From ffb9befd7f13b5a837589c384222935dfd7513ea Mon Sep 17 00:00:00 2001 From: Griatch Date: Wed, 23 Nov 2016 19:07:54 +0100 Subject: [PATCH] Change how evennia stop works under Windows, as per #1100. This introduces the launching of SIGINT-like signals in Windows which unfortunately means the Windows console will show an annoying question about terminating batch jobs (which cannot be removed, apparently). But it should now work consistently with the Linux version when stopping and restarting from the command line. --- evennia/server/evennia_launcher.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/evennia/server/evennia_launcher.py b/evennia/server/evennia_launcher.py index 173a27ce9b..f0aad39ede 100644 --- a/evennia/server/evennia_launcher.py +++ b/evennia/server/evennia_launcher.py @@ -24,6 +24,7 @@ import django # Signal processing SIG = signal.SIGINT +CTRL_C_EVENT = 0 # Windows SIGINT-like signal # Set up the main python paths to Evennia EVENNIA_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) @@ -712,7 +713,20 @@ def kill(pidfile, signal=SIG, succmsg="", errmsg="", with open(restart_file, 'w') as f: f.write("shutdown") try: - os.kill(int(pid), signal) + if os.name == 'nt': + from win32api import GenerateConsoleCtrlEvent + try: + # Windows can only send a SIGINT-like signal to + # *every* process spawned off the same console, so we must + # avoid killing ourselves here. + GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0) + except KeyboardInterrupt: + pass + else: + # Linux can send the SIGINT signal directly + # to the specified PID. + os.kill(int(pid), signal) + except OSError: print("Process %(pid)s cannot be stopped. "\ "The PID file 'server/%(pidfile)s' seems stale. "\ @@ -1141,7 +1155,8 @@ def server_operation(mode, service, interactive, profiler, logserver=False): if os.name == 'nt': print( "Restarting from command line is not supported under Windows. " - "Log into the game to restart.") + "Use the in-game command (@reload by default) " + "or use 'evennia stop && evennia start' for a cold reboot.") return if service == 'server': kill(SERVER_PIDFILE, SIG, "Server reloaded.", @@ -1164,6 +1179,10 @@ def server_operation(mode, service, interactive, profiler, logserver=False): errmsg % 'Server', SERVER_RESTART, restart=True) elif mode == 'stop': + if os.name == "nt": + print ( + "(Obs: You can use a single Ctrl-C to skip " + "Windows' annoying 'Terminate batch job (Y/N)?' prompts.)") # stop processes, avoiding reload if service == 'server': kill(SERVER_PIDFILE, SIG,