def uninstall_mongodb(version_number, edition=None): version_info = make_version_info(version_number, edition=edition) # validate version string if not is_valid_version_info(version_info): raise MongoctlException("Invalid version '%s'. Please provide a" " valid MongoDB version." % version_info) mongo_installation = get_mongo_installation(version_info) if mongo_installation is None: # no-op msg = ("Cannot find a MongoDB installation for version '%s'. Please" " use list-versions to see all possible versions " % version_info) log_info(msg) return log_info("Found MongoDB '%s' in '%s'" % (version_info, mongo_installation)) def rm_mongodb(): # make sure that the mongo installation to be removed does not have # any running processes ensure_mongo_home_not_used(mongo_installation) log_info("Deleting '%s'" % mongo_installation) shutil.rmtree(mongo_installation) log_info("MongoDB '%s' Uninstalled successfully!" % version_info) prompt_execute_task("Proceed uninstall?" , rm_mongodb)
def prompt_add_member_to_replica(replica_cluster, server): prompt = ("Do you want to add server '%s' to replica set cluster '%s'?" % (server.id, replica_cluster.id)) def add_member_func(): replica_cluster.add_member_to_replica(server) prompt_execute_task(prompt, add_member_func)
def prompt_init_replica_cluster(replica_cluster, suggested_primary_server): prompt = ("Do you want to initialize replica set cluster '%s' using " "server '%s'?" % (replica_cluster.id, suggested_primary_server.id)) def init_repl_func(): replica_cluster.initialize_replicaset(suggested_primary_server) prompt_execute_task(prompt, init_repl_func)
def stop_server_signal_handler(): global __mongod_pid__ # otherwise prompt to kill server global __current_server__ if __mongod_pid__: prompt_execute_task("Kill server '%s'?" % __current_server__.id, exit_mongoctl) else: exit_mongoctl()
def prompt_init_replica_cluster(replica_cluster, suggested_primary_server): prompt = ("Do you want to initialize replica set cluster '%s' using server" " '%s'? [type 'n' (NO) unless you are absolutely sure you" " should be initializing this replica set]?" % (replica_cluster.id, suggested_primary_server.id)) def init_repl_func(): replica_cluster.initialize_replicaset(suggested_primary_server) prompt_execute_task(prompt, init_repl_func)
def prompt_or_force_stop_server(server, pid, force=False, try_mongo_force=True): if force: return force_stop_server(server, pid, try_mongo_force=try_mongo_force) def stop_func(): return force_stop_server(server, pid, try_mongo_force=try_mongo_force) if try_mongo_force: result = prompt_execute_task("Issue the shutdown with force command?", stop_func) else: result = prompt_execute_task("Kill the server process?", stop_func) return result[1]
def shall_we_terminate(mongod_pid): def killit(): utils.kill_process(mongod_pid, force=True) log_info("Server process terminated at operator behest.") (condemned, _) = prompt_execute_task("Kill server now?", killit) return condemned
def prompt_step_server_down(server, force): def step_down_func(): step_server_down(server, force) return prompt_execute_task( "Server '%s' is a primary server. " "Step it down before proceeding to shutdown?" % server.id, step_down_func )
def prompt_step_server_down(server, force): def step_down_func(): step_server_down(server, force) return prompt_execute_task( "Server '%s' is a primary server. " "Step it down before proceeding to shutdown?" % server.id, step_down_func)
def uninstall_mongodb(version): # validate version string if not is_valid_version(version): raise MongoctlException("Invalid version '%s'. Please provide a" " valid MongoDB version." % version) mongo_installation = get_mongo_installation(version) if mongo_installation is None: # no-op msg = ("Cannot find a MongoDB installation for version '%s'. Please" " use list-versions to see all possible versions " % version) log_info(msg) return log_info("Found MongoDB '%s' in '%s'" % (version, mongo_installation)) def rm_mongodb(): log_info("Deleting '%s'" % mongo_installation) shutil.rmtree(mongo_installation) log_info("MongoDB '%s' Uninstalled successfully!" % version) prompt_execute_task("Proceed uninstall?" , rm_mongodb)
except Exception, e: log_exception(e) log_verbose("Unable to kill child process '%s': Cause: %s" % (child_process, e)) def exit_mongoctl(): # kill all children then exit map(kill_child, get_child_processes()) exit(0) # if there is no mongod server yet then exit if __mongod_pid__ is None: exit_mongoctl() else: prompt_execute_task("Kill server '%s'?" % __current_server__.id, exit_mongoctl) ############################################################################### # Register the global mongoctl signal handler signal.signal(signal.SIGINT, mongoctl_signal_handler) ############################################################################### SUPPORTED_MONGOD_OPTIONS = [ "verbose", "quiet", "port", "bind_ip", "maxConns", "objcheck", "logpath", "logappend", "pidfilepath", "keyFile", "nounixsocket", "unixSocketPrefix", "auth", "cpu", "dbpath", "diaglog", "directoryperdb", "journal", "journalOptions", "journalCommitInterval", "ipv6", "jsonp", "noauth", "nohttpinterface", "nojournal", "noprealloc", "notablescan", "nssize", "profile", "quota", "quotaFiles", "rest", "repair", "repairpath", "slowms", "smallfiles", "syncdelay", "sysinfo", "upgrade", "fastsync", "oplogSize",
child_process.terminate() except Exception, e: log_exception(e) log_verbose("Unable to kill child process '%s': Cause: %s" % (child_process, e)) def exit_mongoctl(): # kill all children then exit map(kill_child, get_child_processes()) exit(0) # if there is no mongod server yet then exit if __mongod_pid__ is None: exit_mongoctl() else: prompt_execute_task("Kill server '%s'?" % __current_server__.id, exit_mongoctl) ############################################################################### # Register the global mongoctl signal handler signal.signal(signal.SIGINT, mongoctl_signal_handler) ############################################################################### SUPPORTED_MONGOD_OPTIONS = [ "verbose", "quiet", "port", "bind_ip", "maxConns", "objcheck", "logpath", "logappend",