From 0907459b4e77014857813e66d469ce98da6df2bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Wed, 21 Feb 2024 16:26:17 +0100 Subject: [PATCH 1/3] Use less generic messages for progression --- scripts/change_url | 4 ++-- scripts/install | 4 ++-- scripts/upgrade | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/change_url b/scripts/change_url index b2c6c33..d8befd1 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -18,7 +18,7 @@ source /usr/share/yunohost/helpers #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression --message="Stopping $app's systemd service..." --weight=1 ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" @@ -43,7 +43,7 @@ ynh_change_url_nginx_config #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression --message="Starting $app's systemd service..." --weight=1 ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" diff --git a/scripts/install b/scripts/install index 923f4d6..024edf6 100755 --- a/scripts/install +++ b/scripts/install @@ -137,7 +137,7 @@ ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failreg #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding a configuration file..." --weight=1 +ynh_script_progression --message="Adding $app's configuration files..." --weight=1 ### You can add specific configuration files. ### @@ -184,7 +184,7 @@ ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression --message="Starting $app's systemd service..." --weight=1 ### `ynh_systemd_action` is used to start a systemd service for an app. ### Only needed if you have configure a systemd service diff --git a/scripts/upgrade b/scripts/upgrade index 72469be..6732b74 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -55,7 +55,7 @@ source /usr/share/yunohost/helpers #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression --message="Stopping $app's systemd service..." --weight=1 ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" @@ -98,7 +98,7 @@ ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failreg #================================================= # UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating a configuration file..." --weight=1 +ynh_script_progression --message="Updating $app's configuration files..." --weight=1 ### Same as during install ### @@ -123,7 +123,7 @@ chown "$app:$app" "$install_dir/some_config_file" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression --message="Starting $app's systemd service..." --weight=1 ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" From 48b7d28c356559f0b6ab3cd13ead6fc6fbddc8fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Wed, 21 Feb 2024 16:33:41 +0100 Subject: [PATCH 2/3] Remove double header comments, since packagingv2 there are less and less 'specific steps' and 'generic steps'. I feel like they don't make much sense anymore. --- scripts/backup | 2 -- scripts/change_url | 8 -------- scripts/config | 2 -- scripts/install | 8 -------- scripts/remove | 2 -- scripts/restore | 4 ---- scripts/upgrade | 9 +-------- 7 files changed, 1 insertion(+), 34 deletions(-) diff --git a/scripts/backup b/scripts/backup index a675fe7..87926d7 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= diff --git a/scripts/change_url b/scripts/change_url index d8befd1..f009a85 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -4,8 +4,6 @@ ## new location is available via $domain and $path (or $new_domain and $new_path variables if you want to be explicit) ## old values are available via, you guessed it, $old_domain and $old_path -#================================================= -# GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -13,8 +11,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# STANDARD MODIFICATIONS #================================================= # STOP SYSTEMD SERVICE #================================================= @@ -33,13 +29,9 @@ ynh_change_url_nginx_config #================================================= # SPECIFIC MODIFICATIONS #================================================= -# ... -#================================================= ## do any changes to files that reference specific installation domain/path, i.e. regenerate configs etc -#================================================= -# GENERIC FINALISATION #================================================= # START SYSTEMD SERVICE #================================================= diff --git a/scripts/config b/scripts/config index 29f78f8..48be2ff 100644 --- a/scripts/config +++ b/scripts/config @@ -8,8 +8,6 @@ # (validation of several interdependent fields, specific getter/setter for a value, # display dynamic informations or choices, pre-loading of config type .cube... ). -#================================================= -# GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= diff --git a/scripts/install b/scripts/install index 024edf6..36697a6 100755 --- a/scripts/install +++ b/scripts/install @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -37,8 +35,6 @@ source /usr/share/yunohost/helpers foo="bar" ynh_app_setting_set --app=$app --key=foo --value=$foo -#================================================= -# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -135,8 +131,6 @@ ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failreg #================================================= # APP INITIAL CONFIGURATION #================================================= -# ADD A CONFIGURATION -#================================================= ynh_script_progression --message="Adding $app's configuration files..." --weight=1 ### You can add specific configuration files. @@ -179,8 +173,6 @@ chown "$app:$app" "$install_dir/some_config_file" ynh_script_progression --message="Finalizing installation..." --weight=1 ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3" -#================================================= -# GENERIC FINALIZATION #================================================= # START SYSTEMD SERVICE #================================================= diff --git a/scripts/remove b/scripts/remove index 9369d1b..828d42f 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= diff --git a/scripts/restore b/scripts/restore index 29e7bca..c4c090a 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -77,8 +75,6 @@ ynh_restore_file --origin_path="/etc/$app/" ### For other apps, the simple way is better: ynh_restore_file --origin_path="/var/log/$app/" -#================================================= -# GENERIC FINALIZATION #================================================= # RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 6732b74..67fcb3e 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,7 +1,6 @@ #!/bin/bash -#================================================= -# GENERIC START + #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -29,8 +28,6 @@ source /usr/share/yunohost/helpers ### check out the $YNH_APP_UPGRADE_TYPE variable that can contain DOWNGRADE and UPGRADE_SAME too. # upgrade_type=$(ynh_check_app_version_changed) -#================================================= -# STANDARD UPGRADE STEPS #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -59,8 +56,6 @@ ynh_script_progression --message="Stopping $app's systemd service..." --weight=1 ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" -#================================================= -# "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -93,8 +88,6 @@ ynh_use_logrotate --non-append ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" -#================================================= -# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...) #================================================= # UPDATE A CONFIG FILE #================================================= From bd4d08752e7a681201a9704868df01c99a642df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Wed, 21 Feb 2024 16:34:51 +0100 Subject: [PATCH 3/3] Reorganize a bit the scripts: * Add configuration files before system configuration in install and upgrade scripts * In upgrade scripts, stop systemd service before 'ensure downward compatibility' because most apps need a stopped service before moving files around --- scripts/install | 64 ++++++++++++++++++++++++------------------------- scripts/upgrade | 52 ++++++++++++++++++++-------------------- 2 files changed, 58 insertions(+), 58 deletions(-) diff --git a/scripts/install b/scripts/install index 36697a6..5e20de5 100755 --- a/scripts/install +++ b/scripts/install @@ -52,6 +52,38 @@ ynh_setup_source --dest_dir="$install_dir" ### ownership to all files such as after the ynh_setup_source step chown -R "$app:www-data" "$install_dir" +#================================================= +# APP INITIAL CONFIGURATION +#================================================= +ynh_script_progression --message="Adding $app's configuration files..." --weight=1 + +### You can add specific configuration files. +### +### Typically, put your template conf file in ../conf/your_config_file +### The template may contain strings such as __FOO__ or __FOO_BAR__, +### which will automatically be replaced by the values of $foo and $foo_bar +### +### ynh_add_config will also keep track of the config file's checksum, +### which later during upgrade may allow to automatically backup the config file +### if it's found that the file was manually modified +### +### Check the documentation of `ynh_add_config` for more info. + +ynh_add_config --template="some_config_file" --destination="$install_dir/some_config_file" + +# FIXME: this should be handled by the core in the future +### You may need to use chmod 600 instead of 400, +### for example if the app is expected to be able to modify its own config +chmod 400 "$install_dir/some_config_file" +chown "$app:$app" "$install_dir/some_config_file" + +### For more complex cases where you want to replace stuff using regexes, +### you shoud rely on ynh_replace_string (which is basically a wrapper for sed) +### When doing so, you also need to manually call ynh_store_file_checksum +### +### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$install_dir/some_config_file" +### ynh_store_file_checksum --file="$install_dir/some_config_file" + #================================================= # SYSTEM CONFIGURATION #================================================= @@ -128,38 +160,6 @@ ynh_use_logrotate # Create a dedicated Fail2Ban config ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" -#================================================= -# APP INITIAL CONFIGURATION -#================================================= -ynh_script_progression --message="Adding $app's configuration files..." --weight=1 - -### You can add specific configuration files. -### -### Typically, put your template conf file in ../conf/your_config_file -### The template may contain strings such as __FOO__ or __FOO_BAR__, -### which will automatically be replaced by the values of $foo and $foo_bar -### -### ynh_add_config will also keep track of the config file's checksum, -### which later during upgrade may allow to automatically backup the config file -### if it's found that the file was manually modified -### -### Check the documentation of `ynh_add_config` for more info. - -ynh_add_config --template="some_config_file" --destination="$install_dir/some_config_file" - -# FIXME: this should be handled by the core in the future -### You may need to use chmod 600 instead of 400, -### for example if the app is expected to be able to modify its own config -chmod 400 "$install_dir/some_config_file" -chown "$app:$app" "$install_dir/some_config_file" - -### For more complex cases where you want to replace stuff using regexes, -### you shoud rely on ynh_replace_string (which is basically a wrapper for sed) -### When doing so, you also need to manually call ynh_store_file_checksum -### -### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$install_dir/some_config_file" -### ynh_store_file_checksum --file="$install_dir/some_config_file" - #================================================= # SETUP APPLICATION WITH CURL #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 67fcb3e..fab8a9a 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -28,6 +28,13 @@ source /usr/share/yunohost/helpers ### check out the $YNH_APP_UPGRADE_TYPE variable that can contain DOWNGRADE and UPGRADE_SAME too. # upgrade_type=$(ynh_check_app_version_changed) +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping $app's systemd service..." --weight=1 + +ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -49,13 +56,6 @@ source /usr/share/yunohost/helpers # ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir # fi -#================================================= -# STOP SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Stopping $app's systemd service..." --weight=1 - -ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -69,25 +69,6 @@ ynh_setup_source --dest_dir="$install_dir" ### ownership to all files such as after the ynh_setup_source step chown -R "$app:www-data" "$install_dir" -#================================================= -# REAPPLY SYSTEM CONFIGURATIONS -#================================================= -ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 - -### This should be a literal copypaste of what happened in the install's "System configuration" section - -ynh_add_fpm_config - -ynh_add_nginx_config - -ynh_add_systemd_config - -yunohost service add "$app" --description="A short description of the app" --log="/var/log/$app/$app.log" - -ynh_use_logrotate --non-append - -ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" - #================================================= # UPDATE A CONFIG FILE #================================================= @@ -113,6 +94,25 @@ chown "$app:$app" "$install_dir/some_config_file" ### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$install_dir/some_config_file" ### ynh_store_file_checksum --file="$install_dir/some_config_file" +#================================================= +# REAPPLY SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 + +### This should be a literal copypaste of what happened in the install's "System configuration" section + +ynh_add_fpm_config + +ynh_add_nginx_config + +ynh_add_systemd_config + +yunohost service add "$app" --description="A short description of the app" --log="/var/log/$app/$app.log" + +ynh_use_logrotate --non-append + +ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" + #================================================= # START SYSTEMD SERVICE #=================================================