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)
| 102 | |
| 103 | |
| 104 | def 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() |
no test coverage detected