From 25a8daa31ff6de0eb0338dcc9607aa680f7677af Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 6 Apr 2023 19:44:52 +0300 Subject: [PATCH] restart must work even if the app is stopped when called. At the end, the app should be running. --- piku.py | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/piku.py b/piku.py index 519ed5b..05879db 100755 --- a/piku.py +++ b/piku.py @@ -1155,19 +1155,22 @@ def spawn_worker(app, kind, command, env, ordinal=1): copyfile(available, enabled) - -def do_restart(app): - """Restarts a deployed app""" - +def do_stop(app): config = glob(join(UWSGI_ENABLED, '{}*.ini'.format(app))) if len(config) > 0: - echo("Restarting app '{}'...".format(app), fg='yellow') + echo("Stopping app '{}'...".format(app), fg='yellow') for c in config: remove(c) - spawn_app(app) else: - echo("Error: app '{}' not deployed!".format(app), fg='red') + echo("Error: app '{}' not deployed!".format(app), fg='red') # TODO app could be already stopped. Need to able to tell the difference. + +# This must work even if the app is stopped when called. At the end, the app should be running. +def do_restart(app): + """Restarts a deployed app""" + echo("restarting app '{}'...".format(app), fg='yellow') + do_stop(app) + spawn_app(app) def multi_tail(app, filenames, catch_up=20): @@ -1543,16 +1546,8 @@ def cmd_setup_ssh(public_key_file): @argument('app') def cmd_stop(app): """Stop an app, e.g: piku stop """ - app = exit_if_invalid(app) - config = glob(join(UWSGI_ENABLED, '{}*.ini'.format(app))) - - if len(config) > 0: - echo("Stopping app '{}'...".format(app), fg='yellow') - for c in config: - remove(c) - else: - echo("Error: app '{}' not deployed!".format(app), fg='red') + do_stop(app) # --- Internal commands ---