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
38 changes: 34 additions & 4 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: 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):
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 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(
Expand Down Expand Up @@ -298,11 +317,22 @@ def main():
action = options.action

if action == "stop" or action == "restart":
for worker in workers:
stop(worker.pidfile, worker.app)
has_stopped = False

if len(workers) > 0:
stopped_worker_count = 0
for worker in workers:
if stop(worker.pidfile, worker.app):
stopped_worker_count += 1
# If all the workers were stopped
if len(workers) == stopped_worker_count:
has_stopped = True
clokep marked this conversation as resolved.
Show resolved Hide resolved

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

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