From 9d704e47d3cd436743885b880d1e051a54de0d51 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 10 Apr 2021 21:01:25 +0200 Subject: [PATCH] Apply example_ynh --- check_process | 2 +- scripts/install | 54 +++++++++++++++++++++++++------------------------ scripts/restore | 30 ++++++++++++++------------- scripts/upgrade | 8 +++++--- 4 files changed, 50 insertions(+), 44 deletions(-) diff --git a/check_process b/check_process index f2bb656..ea05a96 100644 --- a/check_process +++ b/check_process @@ -24,7 +24,7 @@ multi_instance=1 incorrect_path=0 port_already_use=0 - change_url=1 + change_url=0 ;;; Options Email=cda@rootkey.co.uk Notification=all diff --git a/scripts/install b/scripts/install index 4a919f0..3791d90 100644 --- a/scripts/install +++ b/scripts/install @@ -134,6 +134,34 @@ ynh_add_nginx_config "datadir" #================================================= # SPECIFIC SETUP +#================================================= +# ADD A CONFIGURATION +#================================================= +ynh_script_progression --message="Adding a config file..." + +key=$(ynh_string_random --length=45 | base64) +redis_db=$(ynh_redis_get_free_db) + +ynh_app_setting_set --app=$app --key=key --value=$key +ynh_app_setting_set --app=$app --key=redis_db --value=$redis_db + +ynh_add_config --template="../conf/env.prod" --destination="$final_path/config/.env" + +chmod 400 "$final_path/config/.env" +chown $app:$app "$final_path/config/.env" + +#================================================= +# SETUP SYSTEMD +#================================================= +ynh_script_progression --message="Configuring a systemd service..." + +ynh_add_config --template="../conf/funkwhale.target" --destination="/etc/systemd/system/$app.target" + +# Create a dedicated systemd config +ynh_add_systemd_config --service="${app}-server" --template="funkwhale-server.service" --others_var="datadir" +ynh_add_systemd_config --service="${app}-worker" --template="funkwhale-worker.service" --others_var="datadir" +ynh_add_systemd_config --service="${app}-beat" --template="funkwhale-beat.service" --others_var="datadir" + #================================================= # INSTALL PYTHON DEPENDENCIES #================================================= @@ -148,20 +176,6 @@ pushd $final_path pip install -r api/requirements.txt popd -#================================================= -# MODIFY THE CONFIG FILE -#================================================= -ynh_script_progression --message="Modifying a config file..." - -key=$(ynh_string_random --length=45 | base64) -redis_db=$(ynh_redis_get_free_db) - -ynh_app_setting_set --app=$app --key=key --value=$key -ynh_app_setting_set --app=$app --key=redis_db --value=$redis_db - -ynh_add_config --template="../conf/env.prod" --destination="$final_path/config/.env" -chmod 600 $final_path/config/.env - #================================================= # BUILDING FUNKWHALE #================================================= @@ -179,18 +193,6 @@ pushd $final_path echo "yes" | python api/manage.py collectstatic popd -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Configuring a systemd service..." - -ynh_add_config --template="../conf/funkwhale.target" --destination="/etc/systemd/system/$app.target" - -# Create a dedicated systemd config -ynh_add_systemd_config --service="${app}-server" --template="funkwhale-server.service" --others_var="datadir" -ynh_add_systemd_config --service="${app}-worker" --template="funkwhale-worker.service" --others_var="datadir" -ynh_add_systemd_config --service="${app}-beat" --template="funkwhale-beat.service" --others_var="datadir" - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index 1eaff2d..b36dcf7 100644 --- a/scripts/restore +++ b/scripts/restore @@ -75,6 +75,22 @@ chown -R root:$app "$final_path" #================================================= # SPECIFIC RESTORATION +#================================================= +# RESTORE VARIOUS FILES +#================================================= +ynh_script_progression --message="Restoring various files..." + +ynh_restore_file --origin_path="$datadir" --not_mandatory + +mkdir -p $datadir +pushd $datadir + mkdir -p static media music +popd + +chmod 750 "$datadir" +chmod -R o-rwx "$datadir" +chown -R root:$app "$datadir" + #================================================= # REINSTALL DEPENDENCIES #================================================= @@ -124,20 +140,6 @@ ynh_systemd_action --service_name="${app}-beat" --action="start" --log_path="sys ynh_systemd_action --service_name="${app}-server" --action="start" --log_path="systemd" --line_match="Application startup complete" ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path="systemd" --line_match="Running with the following plugins enabled" -#================================================= -# RESTORE VARIOUS FILES -#================================================= -ynh_script_progression --message="Restoring various files..." - -ynh_restore_file --origin_path="$datadir" --not_mandatory - -mkdir -p $datadir -pushd $datadir - mkdir -p static media music -popd - -chown -R $app: $datadir - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index f48c800..634b913 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -183,12 +183,14 @@ pushd $final_path popd #================================================= -# MODIFY THE CONFIG FILE +# UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Modifying a config file..." +ynh_script_progression --message="Updating a config file..." ynh_add_config --template="../conf/env.prod" --destination="$final_path/config/.env" -chmod 600 $final_path/config/.env + +chmod 400 "$final_path/config/.env" +chown $app:$app "$final_path/config/.env" #================================================= # UPGRADE FUNKWHALE