From 329248cf19aea31dcac9248c00e056a16574ce65 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Fri, 7 Jun 2019 21:48:14 +0200 Subject: [PATCH] [fix] upgrade and separating service and launcher --- conf/__APP__.sh | 3 +++ conf/systemd.service | 2 +- scripts/install | 14 +++++++++++--- scripts/upgrade | 18 ++++++++++-------- 4 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 conf/__APP__.sh diff --git a/conf/__APP__.sh b/conf/__APP__.sh new file mode 100644 index 0000000..339962b --- /dev/null +++ b/conf/__APP__.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +__FINALPATH__/cowyo --port __PORT__ --host localhost diff --git a/conf/systemd.service b/conf/systemd.service index ee8d466..9152cd1 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -7,7 +7,7 @@ Type=simple User=__APP__ Group=__APP__ WorkingDirectory=__FINALPATH__/ -ExecStart=__FINALPATH__/cowyo --port __PORT__ --host localhost >> /var/log/__APP__.log 2>&1 +ExecStart=__FINALPATH__/__APP__.sh >> /var/log/__APP__.log 2>&1 [Install] WantedBy=multi-user.target diff --git a/scripts/install b/scripts/install index 27f18d5..6ade36b 100644 --- a/scripts/install +++ b/scripts/install @@ -101,9 +101,17 @@ ynh_add_systemd_config # MODIFY A CONFIG FILE #================================================= -# Set the systemd service settings -ynh_replace_string "__PORT__" "$port" "/etc/systemd/system/$app.service" -systemctl daemon-reload +cp ../conf/__APP__.sh "$final_path/${app}.sh" +ynh_replace_string "__PORT__" "$port" "$final_path/${app}.sh" +ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/${app}.sh" +chmod +x "$final_path/${app}.sh" + +#================================================= +# STORE THE CONFIG FILE CHECKSUM +#================================================= + +# Calculate and store the config file checksum into the app settings +ynh_store_file_checksum "$final_path/${app}.sh" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index f1a5a23..99a076d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -117,6 +117,16 @@ ynh_script_progression --message="Making sure dedicated system user exists..." - # Create a dedicated user (if not existing) ynh_system_user_create --username=$app +#================================================= +# STORE THE CONFIG FILE CHECKSUM +#================================================= + +### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. +### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. +ynh_backup_if_checksum_is_different --file="$final_path/${app}.sh" +# Recalculate and store the checksum of the file for the next upgrade. +ynh_store_file_checksum --file="$final_path/${app}.sh" + #================================================= # SETUP LOGROTATE #================================================= @@ -133,14 +143,6 @@ ynh_script_progression --message="Upgrading systemd configuration..." --time --w # Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# MODIFY A CONFIG FILE -#================================================= - -# Set the systemd service settings -ynh_replace_string "__PORT__" "$port" "/etc/systemd/system/$app.service" -systemctl daemon-reload - #================================================= # GENERIC FINALIZATION #=================================================