1
0

Compare commits

...

10 Commits

Author SHA1 Message Date
Jorik Schellekens 074e7b185f comments 2019-09-12 15:58:32 +01:00
Jorik Schellekens 52135531cc How did I flip that again?? 2019-09-12 15:56:01 +01:00
Jorik Schellekens 83864cec6a Fix error code indentations and handling 2019-09-11 13:38:16 +01:00
Jorik Schellekens d910c4418e Return boolean s instead of throwing an exception 2019-09-10 13:37:33 +01:00
Jorik Schellekens f73a196ff2 typo
Co-Authored-By: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
2019-09-10 13:19:16 +01:00
Jorik Schellekens 06bae97015 newsfile 2019-09-06 11:45:51 +01:00
Jorik Schellekens 75483b6bf9 Exit 1 if all fail, else 4 2019-09-06 11:39:57 +01:00
Jorik Schellekens 9ee798e327 Return different error code if subset fails. 2019-09-06 11:33:07 +01:00
Jorik Schellekens 458040a081 Check in one place rather than two 2019-09-06 11:25:53 +01:00
Jorik Schellekens 38c2c5a215 Fix exit codes 2019-09-06 11:15:16 +01:00
2 changed files with 40 additions and 4 deletions
+1
View File
@@ -0,0 +1 @@
Give appropriate exit codes when synctl fails.
+39 -4
View File
@@ -71,7 +71,20 @@ def abort(message, colour=RED, stream=sys.stderr):
sys.exit(1) sys.exit(1)
def start(configfile, daemonize=True): def start(configfile: str, daemonize: bool = True) -> bool:
"""Attempts to start synapse.
Args:
configfile: path to a yaml synapse config file
daemonize: whether to daemonize synapse or keep it attached to the current
session
Returns:
True if the process started successfully
False if there was an error starting the process
If deamonize is False it will only return once synapse exits.
"""
write("Starting ...") write("Starting ...")
args = SYNAPSE args = SYNAPSE
@@ -83,25 +96,40 @@ def start(configfile, daemonize=True):
try: try:
subprocess.check_call(args) subprocess.check_call(args)
write("started synapse.app.homeserver(%r)" % (configfile,), colour=GREEN) write("started synapse.app.homeserver(%r)" % (configfile,), colour=GREEN)
return True
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
write( write(
"error starting (exit code: %d); see above for logs" % e.returncode, "error starting (exit code: %d); see above for logs" % e.returncode,
colour=RED, colour=RED,
) )
return False
def start_worker(app, configfile, worker_configfile): def start_worker(app: str, configfile: str, worker_configfile: str) -> bool:
"""Attempts to start a synapse worker.
Args:
app: name of the worker's appservice
configfile: path to a yaml synapse config file
worker_configfile: path to worker specific yaml synapse file
Returns:
True if the process started successfully
False if there was an error starting the process
"""
args = [sys.executable, "-B", "-m", app, "-c", configfile, "-c", worker_configfile] args = [sys.executable, "-B", "-m", app, "-c", configfile, "-c", worker_configfile]
try: try:
subprocess.check_call(args) subprocess.check_call(args)
write("started %s(%r)" % (app, worker_configfile), colour=GREEN) write("started %s(%r)" % (app, worker_configfile), colour=GREEN)
return True
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
write( write(
"error starting %s(%r) (exit code: %d); see above for logs" "error starting %s(%r) (exit code: %d); see above for logs"
% (app, worker_configfile, e.returncode), % (app, worker_configfile, e.returncode),
colour=RED, colour=RED,
) )
return False
def stop(pidfile, app): def stop(pidfile, app):
@@ -292,11 +320,14 @@ def main():
write("All processes exited; now restarting...") write("All processes exited; now restarting...")
if action == "start" or action == "restart": if action == "start" or action == "restart":
error = False
if start_stop_synapse: if start_stop_synapse:
# Check if synapse is already running # Check if synapse is already running
if os.path.exists(pidfile) and pid_running(int(open(pidfile).read())): if os.path.exists(pidfile) and pid_running(int(open(pidfile).read())):
abort("synapse.app.homeserver already running") abort("synapse.app.homeserver already running")
start(configfile, bool(options.daemonize))
if not start(configfile, bool(options.daemonize)):
error = True
for worker in workers: for worker in workers:
env = os.environ.copy() env = os.environ.copy()
@@ -307,12 +338,16 @@ def main():
for cache_name, factor in iteritems(worker.cache_factors): for cache_name, factor in iteritems(worker.cache_factors):
os.environ["SYNAPSE_CACHE_FACTOR_" + cache_name.upper()] = str(factor) os.environ["SYNAPSE_CACHE_FACTOR_" + cache_name.upper()] = str(factor)
start_worker(worker.app, configfile, worker.configfile) if not start_worker(worker.app, configfile, worker.configfile):
error = True
# Reset env back to the original # Reset env back to the original
os.environ.clear() os.environ.clear()
os.environ.update(env) os.environ.update(env)
if error:
exit(1)
if __name__ == "__main__": if __name__ == "__main__":
main() main()