From aa6387f9c3fbdb0950a81b286a68879e4deeab37 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Fri, 24 May 2019 21:10:58 +0200 Subject: [PATCH] restore usage of systemd-sysconfig --- conf/systemd-sysconfig | 34 ++++++++++++++++++++++++++++++++++ conf/systemd.service | 9 +-------- scripts/backup | 2 ++ scripts/change_url | 13 ++++++++++--- scripts/install | 21 ++++++++++++++++----- scripts/remove | 5 ++++- scripts/restore | 2 ++ scripts/upgrade | 19 ++++++++++++++++--- 8 files changed, 85 insertions(+), 20 deletions(-) create mode 100644 conf/systemd-sysconfig diff --git a/conf/systemd-sysconfig b/conf/systemd-sysconfig new file mode 100644 index 0000000..c4d505b --- /dev/null +++ b/conf/systemd-sysconfig @@ -0,0 +1,34 @@ +# source file https://raw.githubusercontent.com/airsonic/airsonic/master/contrib/airsonic-systemd-env +# install documentation : https://airsonic.github.io/docs/install/war-standalone/ + +# Set the location of the standalone war to use +JAVA_JAR=__FINALPATH__/airsonic.war + +# Set any java opts separated by spaces +#JAVA_OPTS=-Xmx700m + +# Set a different location for airsonic home. +# If this path is /var/libresonic or even contains "libresonic", +# the data from a previous libresonic can be used as is (i.e. without +# renaming libresonic.properties,db/libresonic*,etc +AIRSONIC_HOME=__FINALPATH__ + +# Change the port to listen on +PORT=__PORT__ + +# Change the path that is listened on +CONTEXT_PATH=__PATH__ + +# Add any java args. These are different than JAVA_OPTS in that +# they are passed directly to the program. The default is empty: +#JAVA_ARGS= + +# Note that there are several settings for spring boot, not explicitly listed +# here, but can be used in either JAVA_OPTS or JAVA_ARGS. The full list +# can be found here: +# https://docs.spring.io/spring-boot/docs/1.4.5.RELEASE/reference/htmlsingle/#common-application-properties +# For example to set debug across the board: +#JAVA_ARGS=--debug + +# Or to change the ip address that is listened on: +#JAVA_ARGS=--server.address=127.0.0.1 diff --git a/conf/systemd.service b/conf/systemd.service index af65c90..a2cca3b 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -8,13 +8,9 @@ AssertPathExists=__FINALPATH__ [Service] Type=simple -Environment="JAVA_JAR=__FINALPATH__/airsonic.war" Environment="JAVA_OPTS=-Xmx700m" -Environment="AIRSONIC_HOME=__FINALPATH__" -Environment="PORT=__PORT__" -Environment="CONTEXT_PATH=__PATH__" Environment="JAVA_ARGS=" -EnvironmentFile=-/etc/default/airsonic +EnvironmentFile=-/etc/default/__APP__ ExecStart=/usr/bin/java \ $JAVA_OPTS \ -Dairsonic.home=${AIRSONIC_HOME} \ @@ -24,8 +20,5 @@ ExecStart=/usr/bin/java \ User=__APP__ Group=__APP__ -# Force systemd to wait XX sec for the process to start before killing it -# TimeoutStopSec= 180 - [Install] WantedBy=multi-user.target \ No newline at end of file diff --git a/scripts/backup b/scripts/backup index e9e997f..603cdd5 100644 --- a/scripts/backup +++ b/scripts/backup @@ -29,6 +29,7 @@ app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) domain=$(ynh_app_setting_get --app=$app --key=domain) +service_config=$(ynh_app_setting_get --app=$app --key=service_config) #================================================= # STANDARD BACKUP STEPS @@ -68,6 +69,7 @@ ynh_backup --src_path="/etc/logrotate.d/$app" ynh_script_progression --message="Backing up systemd configuration..." --weight=1 ynh_backup --src_path="/etc/systemd/system/$app.service" +ynh_backup --src_path="$service_config" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/change_url b/scripts/change_url index 6449927..53254ea 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -28,6 +28,7 @@ ynh_script_progression --message="Loading installation settings..." --weight=1 # Needed for helper "ynh_add_nginx_config" final_path=$(ynh_app_setting_get --app=$app --key=final_path) +service_config=$(ynh_app_setting_get --app=$app --key=service_config) port=$(ynh_app_setting_get --app=$app --key=port) #================================================= @@ -91,12 +92,18 @@ fi #================================================= ynh_script_progression --message="Configuring a systemd service..." --weight=3 -ynh_replace_string --match_string="__PORT__" --replace_string=$port --target_file="../conf/systemd.service" -ynh_replace_string --match_string="__PATH__" --replace_string=$path_url --target_file="../conf/systemd.service" - # Create a dedicated systemd config ynh_add_systemd_config +ynh_backup_if_checksum_is_different --file="$service_config" + +# Copy config. template to right location +cp ../conf/systemd-sysconfig $service_config + +ynh_replace_string --match_string="__FINALPATH__" --replace_string=$final_path --target_file="$service_config" +ynh_replace_string --match_string="__PORT__" --replace_string=$port --target_file="$service_config" +ynh_replace_string --match_string="__PATH__" --replace_string=$path_url --target_file="$service_config" + #================================================= # GENERIC FINALISATION #================================================= diff --git a/scripts/install b/scripts/install index 987f107..57dcf03 100644 --- a/scripts/install +++ b/scripts/install @@ -123,24 +123,35 @@ chown $app: $final_path/transcode #================================================= ynh_script_progression --message="Configuring a systemd service..." --weight=3 -ynh_replace_string --match_string="__PORT__" --replace_string=$port --target_file="../conf/systemd.service" -ynh_replace_string --match_string="__PATH__" --replace_string=$path_url --target_file="../conf/systemd.service" - # Create a dedicated systemd config ynh_add_systemd_config #================================================= -# MODIFY A CONFIG FILE +# MODIFY CONFIG FILES #================================================= +# Path of the systemd service configuration +service_config="/etc/default/$app" + +ynh_app_setting_set --app=$app --key=service_config --value=$service_config + +# Copy config. template to right location +cp ../conf/systemd-sysconfig $service_config + +ynh_replace_string --match_string="__FINALPATH__" --replace_string=$final_path --target_file="$service_config" +ynh_replace_string --match_string="__PORT__" --replace_string=$port --target_file="$service_config" +ynh_replace_string --match_string="__PATH__" --replace_string=$path_url --target_file="$service_config" + +# Copy configuration file of airsonic cp ../conf/airsonic.properties $final_path/airsonic.properties #================================================= -# STORE THE CONFIG FILE CHECKSUM +# STORE THE CONFIG FILES CHECKSUM #================================================= # Calculate and store the config file checksum into the app settings ynh_store_file_checksum --file="$final_path/airsonic.properties" +ynh_store_file_checksum --file="$service_config" #================================================= # GENERIC FINALIZATION diff --git a/scripts/remove b/scripts/remove index 9b269db..79a50bc 100644 --- a/scripts/remove +++ b/scripts/remove @@ -19,6 +19,7 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) port=$(ynh_app_setting_get --app=$app --key=port) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +service_config=$(ynh_app_setting_get --app=$app --key=service_config) #================================================= # STANDARD REMOVE @@ -86,12 +87,14 @@ fi #================================================= # SPECIFIC REMOVE #================================================= -# REMOVE THE CRON FILE +# REMOVE FILES #================================================= # Remove the log files ynh_secure_remove --file="/var/log/$app/" +ynh_secure_remove --file="$service_config" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index 16afbfc..d04fbb8 100644 --- a/scripts/restore +++ b/scripts/restore @@ -30,6 +30,7 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +service_config=$(ynh_app_setting_get --app=$app --key=service_config) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -107,6 +108,7 @@ chown $app: $final_path/transcode ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +ynh_restore_file --origin_path="$service_config" systemctl enable $app.service #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 40370a5..8d35c37 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -22,6 +22,7 @@ admin=$(ynh_app_setting_get --app=$app --key=admin) is_public=$(ynh_app_setting_get --app=$app --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path) port=$(ynh_app_setting_get --app=$app --key=port) +service_config=$(ynh_app_setting_get --app=$app --key=service_config) #================================================= # CHECK VERSION @@ -49,6 +50,12 @@ if [ -z "$final_path" ]; then ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi +# If service_config doesn't exist, create it +if [ -z "$service_config" ]; then + final_path="/etc/default/$app" + ynh_app_setting_set --app=$app --key=service_config --value=$service_config +fi + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -155,12 +162,18 @@ ynh_use_logrotate --non-append --logfile="$final_path/airsonic.log" #================================================= ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 -ynh_replace_string --match_string="__PORT__" --replace_string=$port --target_file="../conf/systemd.service" -ynh_replace_string --match_string="__PATH__" --replace_string=$path_url --target_file="../conf/systemd.service" - # Create a dedicated systemd config ynh_add_systemd_config +ynh_backup_if_checksum_is_different --file="$service_config" + +# Copy config. template to right location +cp ../conf/systemd-sysconfig $service_config + +ynh_replace_string --match_string="__FINALPATH__" --replace_string=$final_path --target_file="$service_config" +ynh_replace_string --match_string="__PORT__" --replace_string=$port --target_file="$service_config" +ynh_replace_string --match_string="__PATH__" --replace_string=$path_url --target_file="$service_config" + #================================================= # GENERIC FINALIZATION #=================================================