Add interactive server-start mode.

This commit is contained in:
Griatch 2018-08-19 21:40:19 +02:00
parent 2a6e914161
commit 42038737ff
2 changed files with 44 additions and 12 deletions

View file

@ -467,9 +467,10 @@ ARG_OPTIONS = \
stop - shutdown server+portal stop - shutdown server+portal
reboot - shutdown server+portal, then start again reboot - shutdown server+portal, then start again
reset - restart server in 'shutdown' mode reset - restart server in 'shutdown' mode
sstart - start only server (requires portal) istart - start server in the foreground (until reload)
sstop - stop only server
kill - send kill signal to portal+server (force) kill - send kill signal to portal+server (force)
skill = send kill signal only to server skill - send kill signal only to server
status - show server and portal run state status - show server and portal run state
info - show server and portal port info info - show server and portal port info
menu - show a menu of options menu - show a menu of options
@ -955,12 +956,37 @@ def reboot_evennia(pprofiler=False, sprofiler=False):
send_instruction(PSTATUS, None, _portal_running, _portal_not_running) send_instruction(PSTATUS, None, _portal_running, _portal_not_running)
def stop_server_only(): def start_server_interactive():
"""
Start the Server under control of the launcher process (foreground)
"""
def _iserver():
_, server_twistd_cmd = _get_twistd_cmdline(False, False)
server_twistd_cmd.append("--nodaemon")
print("Starting Server in interactive mode (stop with Ctrl-C)...")
try:
Popen(server_twistd_cmd, env=getenv(), stderr=STDOUT).wait()
except KeyboardInterrupt:
print("... Stopped Server with Ctrl-C.")
else:
print("... Server stopped (leaving interactive mode).")
stop_server_only(when_stopped=_iserver)
def stop_server_only(when_stopped=None):
""" """
Only stop the Server-component of Evennia (this is not useful except for debug) Only stop the Server-component of Evennia (this is not useful except for debug)
Args:
when_stopped (callable): This will be called with no arguments when Server has stopped (or
if it had already stopped when this is called).
""" """
def _server_stopped(*args): def _server_stopped(*args):
if when_stopped:
when_stopped()
else:
print("... Server stopped.") print("... Server stopped.")
_reactor_stop() _reactor_stop()
@ -970,6 +996,9 @@ def stop_server_only():
print("Server stopping ...") print("Server stopping ...")
wait_for_status_reply(_server_stopped) wait_for_status_reply(_server_stopped)
send_instruction(SSHUTD, {}) send_instruction(SSHUTD, {})
else:
if when_stopped:
when_stopped()
else: else:
print("Server is not running.") print("Server is not running.")
_reactor_stop() _reactor_stop()
@ -1937,7 +1966,7 @@ def main():
# launch menu for operation # launch menu for operation
init_game_directory(CURRENT_DIR, check_db=True) init_game_directory(CURRENT_DIR, check_db=True)
run_menu() run_menu()
elif option in ('status', 'info', 'start', 'reload', 'reboot', elif option in ('status', 'info', 'start', 'istart', 'reload', 'reboot',
'reset', 'stop', 'sstop', 'kill', 'skill'): 'reset', 'stop', 'sstop', 'kill', 'skill'):
# operate the server directly # operate the server directly
if not SERVER_LOGFILE: if not SERVER_LOGFILE:
@ -1948,6 +1977,8 @@ def main():
query_info() query_info()
elif option == "start": elif option == "start":
start_evennia(args.profiler, args.profiler) start_evennia(args.profiler, args.profiler)
elif option == "istart":
start_server_interactive()
elif option == 'reload': elif option == 'reload':
reload_evennia(args.profiler) reload_evennia(args.profiler)
elif option == 'reboot': elif option == 'reboot':

View file

@ -507,10 +507,11 @@ ServerConfig.objects.conf("server_starting_mode", True)
# what to execute from. # what to execute from.
application = service.Application('Evennia') application = service.Application('Evennia')
# custom logging if "--nodaemon" not in sys.argv:
logfile = logger.WeeklyLogFile(os.path.basename(settings.SERVER_LOG_FILE), # custom logging, but only if we are not running in interactive mode
logfile = logger.WeeklyLogFile(os.path.basename(settings.SERVER_LOG_FILE),
os.path.dirname(settings.SERVER_LOG_FILE)) os.path.dirname(settings.SERVER_LOG_FILE))
application.setComponent(ILogObserver, logger.ServerLogObserver(logfile).emit) application.setComponent(ILogObserver, logger.ServerLogObserver(logfile).emit)
# The main evennia server program. This sets up the database # The main evennia server program. This sets up the database
# and is where we store all the other services. # and is where we store all the other services.