From 907a2af4bb210c6f719940b1c346d630ab69e7dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Sat, 10 Jun 2023 23:09:04 +0200 Subject: [PATCH] Deduplicate code to wait for server to start --- scripts/_common.sh | 9 ++++++++- scripts/change_url | 1 + scripts/install | 7 +------ scripts/restore | 7 +------ scripts/upgrade | 7 +------ 5 files changed, 12 insertions(+), 19 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index b806c2b..341ea2e 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -10,12 +10,19 @@ pip_dependencies=( 'PyMySQL>=0.9,<1.1' ) -### Constants #================================================= # PERSONAL HELPERS #================================================= +wait_gunicorn_start() { + # line_match isn't enough because ihatemoney may stop if database upgrades + for _ in {1..20}; do + test -S /tmp/budget.gunicorn_$app.sock && break + sleep 1 + done +} + __ynh_python_venv_setup() { local -A args_array=( [d]=venv_dir= [p]=packages= ) local venv_dir diff --git a/scripts/change_url b/scripts/change_url index b6f2645..0f44907 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -50,6 +50,7 @@ ynh_script_progression --message="Starting a systemd service..." --weight=5 # Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path=systemd +wait_gunicorn_start #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index 761ec72..c9813aa 100755 --- a/scripts/install +++ b/scripts/install @@ -88,12 +88,7 @@ ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Listening at" - -# line_match isn't enough because ihatemoney may stop if database upgrades -for _ in {1..20}; do - test -S /tmp/budget.gunicorn_$app.sock && break - sleep 1 -done +wait_gunicorn_start #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index aaf2d5e..3f234ac 100755 --- a/scripts/restore +++ b/scripts/restore @@ -58,12 +58,7 @@ yunohost service add $app --description="$app daemon for IHateMoney" --log=syste ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Listening at" - -# line_match isn't enough because ihatemoney may stop if database upgrades -for _ in {1..20}; do - test -S /tmp/budget.gunicorn_$app.sock && break - sleep 1 -done +wait_gunicorn_start #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 76e1235..3d88c4c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -155,12 +155,7 @@ yunohost service add $app --description="$app daemon for IHateMoney" --log=syste ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Listening at" - -# line_match isn't enough because ihatemoney may stop if database upgrades -for _ in {1..20}; do - test -S /tmp/budget.gunicorn_$app.sock && break - sleep 1 -done +wait_gunicorn_start #================================================= # END OF SCRIPT