Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add synctl warning when no process is stopped and fix restart #6598

Merged
merged 9 commits into from
May 19, 2020
1 change: 1 addition & 0 deletions changelog.d/6590.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
synctl: On restart don't start if nothing was stopped. Warns that the process might not be started by synctl.
clokep marked this conversation as resolved.
Show resolved Hide resolved
30 changes: 27 additions & 3 deletions synctl
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,38 @@ def start_worker(app: str, configfile: str, worker_configfile: str) -> bool:
return False


def stop(pidfile, app):
def stop(pidfile, app) -> bool:
romainbou marked this conversation as resolved.
Show resolved Hide resolved
"""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 stopped or an error occured
romainbou marked this conversation as resolved.
Show resolved Hide resolved
"""

if os.path.exists(pidfile):
pid = int(open(pidfile).read())
try:
os.kill(pid, signal.SIGTERM)
write("stopped %s" % (app,), colour=GREEN)
return True
except OSError as err:
if err.errno == errno.ESRCH:
write("%s not running" % (app,), colour=YELLOW)
elif err.errno == errno.EPERM:
abort("Cannot stop %s: Operation not permitted" % (app,))
else:
abort("Cannot stop %s: Unknown error" % (app,))
return False
else:
write(
"No running worker found. (from '%s')\nThe process might be managed by another controller (e.g. systemd)"
romainbou marked this conversation as resolved.
Show resolved Hide resolved
% pidfile,
colour=YELLOW,
)
return False


Worker = collections.namedtuple(
Expand Down Expand Up @@ -298,11 +317,16 @@ def main():
action = options.action

if action == "stop" or action == "restart":
hasStopped = False
romainbou marked this conversation as resolved.
Show resolved Hide resolved
for worker in workers:
stop(worker.pidfile, worker.app)
if stop(worker.pidfile, worker.app):
hasStopped = True
romainbou marked this conversation as resolved.
Show resolved Hide resolved

if start_stop_synapse:
stop(pidfile, "synapse.app.homeserver")
if stop(pidfile, "synapse.app.homeserver"):
hasStopped = True
if not hasStopped:
sys.exit(1)

# Wait for synapse to actually shutdown before starting it again
if action == "restart":
Expand Down