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

Give appropriate exit codes when synctl fails #5992

Merged
merged 10 commits into from
Sep 18, 2019
1 change: 1 addition & 0 deletions changelog.d/5992.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Give appropriate exit codes when syctl fails.
22 changes: 20 additions & 2 deletions synctl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def start(configfile, daemonize=True):
"error starting (exit code: %d); see above for logs" % e.returncode,
colour=RED,
)
raise


def start_worker(app, configfile, worker_configfile):
Expand All @@ -102,6 +103,7 @@ def start_worker(app, configfile, worker_configfile):
% (app, worker_configfile, e.returncode),
colour=RED,
)
raise


def stop(pidfile, app):
Expand Down Expand Up @@ -292,11 +294,15 @@ def main():
write("All processes exited; now restarting...")

if action == "start" or action == "restart":
errors = 0
if start_stop_synapse:
# Check if synapse is already running
if os.path.exists(pidfile) and pid_running(int(open(pidfile).read())):
abort("synapse.app.homeserver already running")
start(configfile, bool(options.daemonize))
try:
start(configfile, bool(options.daemonize))
except subprocess.CalledProcessError:
errors += 1

for worker in workers:
env = os.environ.copy()
Expand All @@ -307,12 +313,24 @@ def main():
for cache_name, factor in iteritems(worker.cache_factors):
os.environ["SYNAPSE_CACHE_FACTOR_" + cache_name.upper()] = str(factor)

start_worker(worker.app, configfile, worker.configfile)
try:
start_worker(worker.app, configfile, worker.configfile)
except subprocess.CalledProcessError:
errors += 1

# Reset env back to the original
os.environ.clear()
os.environ.update(env)

process_count = len(workers) + int(start_stop_synapse)

# If every process failed to start we exit with exit code 1. If a subset
# fails we exit with 4
if errors == process_count:
exit(1)
elif errors:
exit(4)


if __name__ == "__main__":
main()