MCPcopy
hub / github.com/rueckstiess/mtools / shutdown_host

Function shutdown_host

mtools/mlaunch/mlaunch.py:104–132  ·  view source on GitHub ↗

Send the shutdown command to a mongod or mongos on given port. This function can be called as a separate thread.

(port, username=None, password=None, authdb=None)

Source from the content-addressed store, hash-verified

102
103
104def shutdown_host(port, username=None, password=None, authdb=None):
105 """
106 Send the shutdown command to a mongod or mongos on given port.
107
108 This function can be called as a separate thread.
109 """
110 host = 'localhost:%i' % port
111 try:
112 if username and password and authdb:
113 if authdb != "admin":
114 raise RuntimeError("given username/password is not for "
115 "admin database")
116 mc = MongoConnection(host, username=username, password=password,
117 directConnection=True)
118 else:
119 mc = MongoConnection(host, directConnection=True)
120
121 try:
122 mc.admin.command('shutdown', force=True)
123 except AutoReconnect:
124 pass
125 except OperationFailure:
126 print("Error: cannot authenticate to shut down %s." % host)
127 return
128
129 except ConnectionFailure:
130 pass
131 else:
132 mc.close()
133
134
135@functools.lru_cache()

Callers 1

initMethod · 0.85

Calls 2

MongoConnectionClass · 0.85
commandMethod · 0.80

Tested by

no test coverage detected