def _stop(self): (pid_alive, m2ee_alive) = self.m2ee.check_alive() if not pid_alive and not m2ee_alive: logger.info("Nothing to stop, the application is not running.") return True logger.debug("Trying to stop the application.") stopped = False logger.info("Waiting for the application to shutdown...") stopped = self.m2ee.runner.stop(timeout=10) if stopped: logger.info("The application has been stopped successfully.") return True logger.warn("The application did not shutdown by itself yet...") answer = None while not answer in ('y', 'n'): answer = raw_input("Do you want to try to signal the JVM " "process to stop immediately? (y)es, (n)o? ") if answer == 'y': logger.info("Waiting for the JVM process to disappear...") stopped = self.m2ee.runner.terminate(timeout=10) if stopped: logger.info("The JVM process has been stopped.") return True elif answer == 'n': logger.info("Doing nothing, use stop again to check if the " "process finally disappeared...") return False else: print("Unknown option %s" % answer) logger.warn("The application process seems not to respond to any " "command or signal.") answer = None while not answer in ('y', 'n'): answer = raw_input("Do you want to kill the JVM process? (y)es," "(n)o? ") if answer == 'y': logger.info("Waiting for the JVM process to disappear...") stopped = self.m2ee.runner.kill(timeout=10) if stopped: logger.info("The JVM process has been destroyed.") return True elif answer == 'n': logger.info("Doing nothing, use stop again to check if the " "process finally disappeared...") return False else: print("Unknown option %s" % answer) logger.error("Stopping the application process failed thorougly.") return False
def do_who(self, args): if self._report_not_running(): return if args: try: limitint = int(args) self._who(limitint) except ValueError: logger.warn("Could not parse argument to an integer. Use a " "number as argument to limit the amount of logged " "in users shown.") else: self._who()
def do_emptydb(self, args): if not self.m2ee.config.is_using_postgresql(): logger.error("Only PostgreSQL databases are supported right now.") return if not self.m2ee.config.allow_destroy_db(): logger.error("Destructive database operations are turned off.") return (pid_alive, m2ee_alive) = self.m2ee.check_alive() if pid_alive or m2ee_alive: logger.warn("The application process is still running, refusing " "to empty the database right now.") return pgutil.emptydb( self.m2ee.config.get_pg_environment(), self.m2ee.config.get_psql_binary(), )
def do_create_admin_user(self, args=None): (pid_alive, m2ee_alive) = self.m2ee.check_alive() if not m2ee_alive: logger.warn("The application process needs to be running to " "create a user object in the application.") return print("This option will create an administrative user account, using " "the preset username and user role settings.") newpw1 = getpass.getpass("Type new password for this user: "******"Type new password for this user again: ") if newpw1 != newpw2: print("The passwords are not equal!") else: m2eeresponse = self.m2ee.client.create_admin_user( {"password": newpw1}) m2eeresponse.display_error()
def do_log(self, args): if self._cleanup_logging(): return logfile = self.m2ee.config.get_logfile() if not logfile: logger.warn("logfile location is not specified") return print("This command will start printing log information from the " "application right in the middle of all of the other output on " "your screen. This can be confusing, especially when you're " "typing something and everything gets messed up by the logging. " "Issuing the log command again will turn off logging output.") answer = raw_input("Do you want to start log output (y/N): ") if answer == 'y': cmd = ("tail", "-F", logfile) proc = subprocess.Popen(cmd) self.m2ee._logproc = proc self.prompt = "LOG %s" % self._default_prompt
def do_update_admin_user(self, args=None): (pid_alive, m2ee_alive) = self.m2ee.check_alive() if not m2ee_alive: logger.warn("The application process needs to be running to " "change user objects in the application.") return print("Using this function you can reset the password of an " "administrative user account.") username = raw_input("User name: ") newpw1 = getpass.getpass("Type new password for user %s: " % username) newpw2 = getpass.getpass("Type new password for user %s again: " % username) if newpw1 != newpw2: print("The passwords are not equal!") else: m2eeresponse = self.m2ee.client.update_admin_user( {"username": username, "password": newpw1}) m2eeresponse.display_error()
def do_restoredb(self, args): if not self.m2ee.config.is_using_postgresql(): logger.error("Only PostgreSQL databases are supported right now.") return if not self.m2ee.config.allow_destroy_db(): logger.error("Destructive database operations are turned off.") return if not args: logger.error("restoredb needs the name of a dump file in %s as arg" "ument" % self.m2ee.config.get_database_dump_path()) return (pid_alive, m2ee_alive) = self.m2ee.check_alive() if pid_alive or m2ee_alive: logger.warn("The application is still running, refusing to " "restore the database right now.") return pgutil.restoredb( self.m2ee.config.get_pg_environment(), self.m2ee.config.get_pg_restore_binary(), self.m2ee.config.get_database_dump_path(), args, )
def do_get_logged_in_user_names(self, args): logger.warn("get_logged_in_user_names is deprectated in favor of the " "shorter who command") self.do_who(args)