Prevent server from reconnecting to Portal mid-shutdown

This commit is contained in:
Griatch 2018-01-20 13:19:06 +01:00
parent d6105f6d6c
commit 9422c6314d
3 changed files with 23 additions and 11 deletions

View file

@ -5,7 +5,7 @@ Portal. This module sets up the Client-side communication.
""" """
from evennia.server.portal import amp from evennia.server.portal import amp
from twisted.internet import protocol from twisted.internet import protocol, reactor
from evennia.utils import logger from evennia.utils import logger
@ -84,8 +84,9 @@ class AMPClientFactory(protocol.ReconnectingClientFactory):
reason (str): Eventual text describing why connection failed. reason (str): Eventual text describing why connection failed.
""" """
logger.log_info("Attempting to reconnect to Portal ...") if reactor.running:
protocol.ReconnectingClientFactory.clientConnectionFailed(self, connector, reason) logger.log_info("Attempting to reconnect to Portal ...")
protocol.ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
class AMPServerClientProtocol(amp.AMPMultiConnectionProtocol): class AMPServerClientProtocol(amp.AMPMultiConnectionProtocol):

View file

@ -1363,7 +1363,7 @@ def del_pid(pidfile):
os.remove(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 Send a kill signal to a process based on PID. A customized
success/error message will be returned. If clean=True, the system success/error message will be returned. If clean=True, the system
@ -1372,6 +1372,8 @@ def kill(pidfile, component='Server', killsignal=SIG):
Args: Args:
pidfile (str): The path of the pidfile to get the PID from. pidfile (str): The path of the pidfile to get the PID from.
component (str, optional): Usually one of 'Server' or 'Portal'. 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. 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( "Try removing it manually.".format(
component=component, pid=pid, pidfile=pidfile)) component=component, pid=pid, pidfile=pidfile))
return return
print("Sent kill signal to {component}.".format(component=component)) if callback:
return callback()
print("Could not send kill signal - {component} does " else:
"not appear to be running.".format(component=component)) 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): def show_version_info(about=False):
@ -1715,8 +1723,10 @@ def run_menu():
elif inp == 7: elif inp == 7:
kill(SERVER_PIDFILE, 'Server') kill(SERVER_PIDFILE, 'Server')
elif inp == 8: elif inp == 8:
kill(PORTAL_PIDFILE, 'Portal') global REACTOR_RUN
kill(SERVER_PIDFILE, 'Server') kill(SERVER_PIDFILE, 'Server')
reactor.callLater(5, kill, PORTAL_PIDFILE, 'Portal')
REACTOR_RUN = True
elif inp == 9: elif inp == 9:
if not SERVER_LOGFILE: if not SERVER_LOGFILE:
init_game_directory(CURRENT_DIR, check_db=False) init_game_directory(CURRENT_DIR, check_db=False)
@ -1878,7 +1888,7 @@ def main():
elif option == 'sstop': elif option == 'sstop':
stop_server_only() stop_server_only()
elif option == 'kill': elif option == 'kill':
kill(PORTAL_PIDFILE, 'Portal') kill(SERVER_PIDFILE, 'Server')
kill(SERVER_PIDFILE, 'Server') kill(SERVER_PIDFILE, 'Server')
elif option == 'skill': elif option == 'skill':
kill(SERVER_PIDFILE, 'Server') kill(SERVER_PIDFILE, 'Server')

View file

@ -210,7 +210,8 @@ class Evennia(object):
Optimize some SQLite stuff at startup since we Optimize some SQLite stuff at startup since we
can't save it to the database. 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 (hasattr(settings, 'DATABASES') and
settings.DATABASES.get("default", {}).get('ENGINE', None) == settings.DATABASES.get("default", {}).get('ENGINE', None) ==
'django.db.backends.sqlite3')): 'django.db.backends.sqlite3')):