Merge branch 'improve_startstop' of https://github.com/volundmush/evennia into volundmush-improve_startstop

This commit is contained in:
Griatch 2022-08-02 21:36:09 +02:00
commit 80dd48ec9d
3 changed files with 39 additions and 14 deletions

View file

@ -7,6 +7,7 @@ allows for customizing the server operation as desired.
This module must contain at least these global functions:
at_server_init()
at_server_start()
at_server_stop()
at_server_reload_start()
@ -16,6 +17,11 @@ at_server_cold_stop()
"""
def at_server_init():
"""
This is called first as the server is starting up, regardless of how.
"""
pass
def at_server_start():
"""

View file

@ -46,8 +46,9 @@ _SA = object.__setattr__
# a file with a flag telling the server to restart after shutdown or not.
SERVER_RESTART = os.path.join(settings.GAME_DIR, "server", "server.restart")
# module containing hook methods called during start_stop
SERVER_STARTSTOP_MODULE = mod_import(settings.AT_SERVER_STARTSTOP_MODULE)
# modules containing hook methods called during start_stop
SERVER_STARTSTOP_MODULES = [mod_import(mod) for mod in make_iter(settings.AT_SERVER_STARTSTOP_MODULE)
if isinstance(mod, str)]
# modules containing plugin services
SERVER_SERVICES_PLUGIN_MODULES = make_iter(settings.SERVER_SERVICES_PLUGIN_MODULES)
@ -413,6 +414,8 @@ class Evennia:
for typeclass_db in TypedObject.__subclasses__()
]
self.at_server_init()
# call correct server hook based on start file value
if mode == "reload":
logger.log_msg("Server successfully reloaded.")
@ -525,14 +528,23 @@ class Evennia:
# server start/stop hooks
def at_server_init(self):
"""
This is called first when the server is starting, before any other hooks, regardless of how it's starting.
"""
for mod in SERVER_STARTSTOP_MODULES:
if hasattr(mod, "at_server_init"):
mod.at_server_init()
def at_server_start(self):
"""
This is called every time the server starts up, regardless of
how it was shut down.
"""
if SERVER_STARTSTOP_MODULE:
SERVER_STARTSTOP_MODULE.at_server_start()
for mod in SERVER_STARTSTOP_MODULES:
if hasattr(mod, "at_server_start"):
mod.at_server_start()
def at_server_stop(self):
"""
@ -540,16 +552,18 @@ class Evennia:
of it is fore a reload, reset or shutdown.
"""
if SERVER_STARTSTOP_MODULE:
SERVER_STARTSTOP_MODULE.at_server_stop()
for mod in SERVER_STARTSTOP_MODULES:
if hasattr(mod, "at_server_stop"):
mod.at_server_stop()
def at_server_reload_start(self):
"""
This is called only when server starts back up after a reload.
"""
if SERVER_STARTSTOP_MODULE:
SERVER_STARTSTOP_MODULE.at_server_reload_start()
for mod in SERVER_STARTSTOP_MODULES:
if hasattr(mod, "at_server_reload_start"):
mod.at_server_reload_start()
def at_post_portal_sync(self, mode):
"""
@ -589,8 +603,9 @@ class Evennia:
This is called only time the server stops before a reload.
"""
if SERVER_STARTSTOP_MODULE:
SERVER_STARTSTOP_MODULE.at_server_reload_stop()
for mod in SERVER_STARTSTOP_MODULES:
if hasattr(mod, "at_server_reload_stop"):
mod.at_server_reload_stop()
def at_server_cold_start(self):
"""
@ -618,16 +633,18 @@ class Evennia:
if character:
character.delete()
guest.delete()
if SERVER_STARTSTOP_MODULE:
SERVER_STARTSTOP_MODULE.at_server_cold_start()
for mod in SERVER_STARTSTOP_MODULES:
if hasattr(mod, "at_server_cold_start"):
mod.at_server_cold_start()
def at_server_cold_stop(self):
"""
This is called only when the server goes down due to a shutdown or reset.
"""
if SERVER_STARTSTOP_MODULE:
SERVER_STARTSTOP_MODULE.at_server_cold_stop()
for mod in SERVER_STARTSTOP_MODULES:
if hasattr(mod, "at_server_cold_stop"):
mod.at_server_cold_stop()
# ------------------------------------------------------------

View file

@ -389,6 +389,8 @@ AT_INITIAL_SETUP_HOOK_MODULE = "server.conf.at_initial_setup"
# Module containing your custom at_server_start(), at_server_reload() and
# at_server_stop() methods. These methods will be called every time
# the server starts, reloads and resets/stops respectively.
# Now supports a list of python paths or a single string.
# If it's a list, each module's hooks will be called by list order.
AT_SERVER_STARTSTOP_MODULE = "server.conf.at_server_startstop"
# List of one or more module paths to modules containing a function start_
# plugin_services(application). This module will be called with the main