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 #=================================================