diff --git a/evennia/server/amp_client.py b/evennia/server/amp_client.py index 294250b9e7..24fc7a91f5 100644 --- a/evennia/server/amp_client.py +++ b/evennia/server/amp_client.py @@ -5,7 +5,7 @@ Portal. This module sets up the Client-side communication. """ from evennia.server.portal import amp -from twisted.internet import protocol +from twisted.internet import protocol, reactor from evennia.utils import logger @@ -84,8 +84,9 @@ class AMPClientFactory(protocol.ReconnectingClientFactory): reason (str): Eventual text describing why connection failed. """ - logger.log_info("Attempting to reconnect to Portal ...") - protocol.ReconnectingClientFactory.clientConnectionFailed(self, connector, reason) + if reactor.running: + logger.log_info("Attempting to reconnect to Portal ...") + protocol.ReconnectingClientFactory.clientConnectionFailed(self, connector, reason) class AMPServerClientProtocol(amp.AMPMultiConnectionProtocol): diff --git a/evennia/server/evennia_launcher.py b/evennia/server/evennia_launcher.py index 296cf61b12..db14037ae3 100644 --- a/evennia/server/evennia_launcher.py +++ b/evennia/server/evennia_launcher.py @@ -1363,7 +1363,7 @@ def del_pid(pidfile): os.remove(pidfile) -def kill(pidfile, component='Server', killsignal=SIG): +def kill(pidfile, component='Server', callback=None, errback=None, killsignal=SIG): """ Send a kill signal to a process based on PID. A customized success/error message will be returned. If clean=True, the system @@ -1372,6 +1372,8 @@ def kill(pidfile, component='Server', killsignal=SIG): Args: pidfile (str): The path of the pidfile to get the PID from. component (str, optional): Usually one of 'Server' or 'Portal'. + errback (callable, optional): Called if signal failed to send. + callback (callable, optional): Called if kill signal was sent successfully. killsignal (int, optional): Signal identifier for signal to send. """ @@ -1402,10 +1404,16 @@ def kill(pidfile, component='Server', killsignal=SIG): "Try removing it manually.".format( component=component, pid=pid, pidfile=pidfile)) return - print("Sent kill signal to {component}.".format(component=component)) - return - print("Could not send kill signal - {component} does " - "not appear to be running.".format(component=component)) + if callback: + callback() + else: + print("Sent kill signal to {component}.".format(component=component)) + return + if errback: + errback() + else: + print("Could not send kill signal - {component} does " + "not appear to be running.".format(component=component)) def show_version_info(about=False): @@ -1715,8 +1723,10 @@ def run_menu(): elif inp == 7: kill(SERVER_PIDFILE, 'Server') elif inp == 8: - kill(PORTAL_PIDFILE, 'Portal') + global REACTOR_RUN kill(SERVER_PIDFILE, 'Server') + reactor.callLater(5, kill, PORTAL_PIDFILE, 'Portal') + REACTOR_RUN = True elif inp == 9: if not SERVER_LOGFILE: init_game_directory(CURRENT_DIR, check_db=False) @@ -1878,7 +1888,7 @@ def main(): elif option == 'sstop': stop_server_only() elif option == 'kill': - kill(PORTAL_PIDFILE, 'Portal') + kill(SERVER_PIDFILE, 'Server') kill(SERVER_PIDFILE, 'Server') elif option == 'skill': kill(SERVER_PIDFILE, 'Server') diff --git a/evennia/server/server.py b/evennia/server/server.py index 6ba5f32ef8..2cabb58f37 100644 --- a/evennia/server/server.py +++ b/evennia/server/server.py @@ -210,7 +210,8 @@ class Evennia(object): Optimize some SQLite stuff at startup since we can't save it to the database. """ - if ((".".join(str(i) for i in django.VERSION) < "1.2" and settings.DATABASES.get('default', {}).get('ENGINE') == "sqlite3") or + if ((".".join(str(i) for i in django.VERSION) < "1.2" and + settings.DATABASES.get('default', {}).get('ENGINE') == "sqlite3") or (hasattr(settings, 'DATABASES') and settings.DATABASES.get("default", {}).get('ENGINE', None) == 'django.db.backends.sqlite3')):