mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-14 23:43:55 +01:00
synctl warns when no process is stopped and avoids start (#6598)
* If an error occurs when stopping a process synctl now logs a warning. * During a restart, synctl will avoid attempting to start Synapse if an error occurs during stopping Synapse.
This commit is contained in:
parent
ab3e19d814
commit
a57863d2b4
2 changed files with 29 additions and 3 deletions
1
changelog.d/6590.misc
Normal file
1
changelog.d/6590.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
`synctl` now warns if it was unable to stop Synapse and will not attempt to start Synapse if nothing was stopped. Contributed by Romain Bouyé.
|
31
synctl
31
synctl
|
@ -142,12 +142,23 @@ def start_worker(app: str, configfile: str, worker_configfile: str) -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def stop(pidfile, app):
|
def stop(pidfile: str, app: str) -> bool:
|
||||||
|
"""Attempts to kill a synapse worker from the pidfile.
|
||||||
|
Args:
|
||||||
|
pidfile: path to file containing worker's pid
|
||||||
|
app: name of the worker's appservice
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True if the process stopped successfully
|
||||||
|
False if process was already stopped or an error occured
|
||||||
|
"""
|
||||||
|
|
||||||
if os.path.exists(pidfile):
|
if os.path.exists(pidfile):
|
||||||
pid = int(open(pidfile).read())
|
pid = int(open(pidfile).read())
|
||||||
try:
|
try:
|
||||||
os.kill(pid, signal.SIGTERM)
|
os.kill(pid, signal.SIGTERM)
|
||||||
write("stopped %s" % (app,), colour=GREEN)
|
write("stopped %s" % (app,), colour=GREEN)
|
||||||
|
return True
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
if err.errno == errno.ESRCH:
|
if err.errno == errno.ESRCH:
|
||||||
write("%s not running" % (app,), colour=YELLOW)
|
write("%s not running" % (app,), colour=YELLOW)
|
||||||
|
@ -155,6 +166,14 @@ def stop(pidfile, app):
|
||||||
abort("Cannot stop %s: Operation not permitted" % (app,))
|
abort("Cannot stop %s: Operation not permitted" % (app,))
|
||||||
else:
|
else:
|
||||||
abort("Cannot stop %s: Unknown error" % (app,))
|
abort("Cannot stop %s: Unknown error" % (app,))
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
write(
|
||||||
|
"No running worker of %s found (from %s)\nThe process might be managed by another controller (e.g. systemd)"
|
||||||
|
% (app, pidfile),
|
||||||
|
colour=YELLOW,
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
Worker = collections.namedtuple(
|
Worker = collections.namedtuple(
|
||||||
|
@ -300,11 +319,17 @@ def main():
|
||||||
action = options.action
|
action = options.action
|
||||||
|
|
||||||
if action == "stop" or action == "restart":
|
if action == "stop" or action == "restart":
|
||||||
|
has_stopped = True
|
||||||
for worker in workers:
|
for worker in workers:
|
||||||
stop(worker.pidfile, worker.app)
|
if not stop(worker.pidfile, worker.app):
|
||||||
|
# A worker could not be stopped.
|
||||||
|
has_stopped = False
|
||||||
|
|
||||||
if start_stop_synapse:
|
if start_stop_synapse:
|
||||||
stop(pidfile, "synapse.app.homeserver")
|
if not stop(pidfile, "synapse.app.homeserver"):
|
||||||
|
has_stopped = False
|
||||||
|
if not has_stopped:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# Wait for synapse to actually shutdown before starting it again
|
# Wait for synapse to actually shutdown before starting it again
|
||||||
if action == "restart":
|
if action == "restart":
|
||||||
|
|
Loading…
Reference in a new issue