From 0ab7d76234ff1399a485d87553c8e03b20bb8834 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 27 Dec 2019 23:53:20 +0100 Subject: [PATCH] Apply example_ynh --- README.md | 1 - scripts/backup | 9 ++++++++- scripts/change_url | 21 +++++++++++++++++++-- scripts/install | 18 ++++++++---------- scripts/remove | 4 ++-- scripts/restore | 8 +++----- scripts/upgrade | 14 ++++++-------- 7 files changed, 46 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 51bb7e2..08abbe0 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,6 @@ The app can be used by multiple users * x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/wikijs%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/wikijs/) * ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/wikijs%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/wikijs/) -* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/wikijs%20%28Apps%29.svg)](https://ci-stretch.nohost.me/ci/apps/wikijs/) ## Limitations diff --git a/scripts/backup b/scripts/backup index 1f976ee..39dd013 100644 --- a/scripts/backup +++ b/scripts/backup @@ -38,7 +38,7 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= ynh_print_info --message="Stopping a systemd service..." -ynh_systemd_action --service_name=$app --action="stop" +ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped wikijs service" #================================================= # BACKUP THE APP MAIN DIR @@ -70,6 +70,13 @@ ynh_print_info --message="Backing up systemd configuration..." ynh_backup --src_path="/etc/systemd/system/$app.service" +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_print_info --message="Starting a systemd service..." + +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP Server: [ RUNNING ]" + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/change_url b/scripts/change_url index 4b116d6..5a36f18 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -35,6 +35,23 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) #db_user=$db_name #db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_print_info --message="Backing up the app before changing its url (may take a while)..." + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. + ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" + + # restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + #================================================= # CHECK WHICH PARTS SHOULD BE CHANGED #================================================= @@ -58,7 +75,7 @@ fi #================================================= ynh_print_info --message="Stopping a systemd service..." -ynh_systemd_action --service_name=$app --action="stop" +ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped wikijs service" #================================================= # MODIFY URL IN NGINX CONF @@ -96,7 +113,7 @@ fi #================================================= ynh_print_info --message="Starting a systemd service..." -ynh_systemd_action --service_name=$app --action="start" +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP Server: [ RUNNING ]" #================================================= # RELOAD NGINX diff --git a/scripts/install b/scripts/install index 6f02f56..33c990d 100644 --- a/scripts/install +++ b/scripts/install @@ -108,7 +108,7 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= -ynh_print_info --message="Configuring system user ..." +ynh_print_info --message="Configuring system user..." # Create a system user ynh_system_user_create --username=$app --home_dir="$final_path" @@ -138,16 +138,16 @@ ynh_add_systemd_config config_file="$final_path/config.yml" cp -f ../conf/config.sample.yml $config_file -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file=$config_file -ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file=$config_file -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file=$config_file +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_file" +ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config_file" +ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config_file" #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file=$config_file +ynh_store_file_checksum --file="$config_file" #================================================= # GENERIC FINALIZATION @@ -159,19 +159,17 @@ ynh_store_file_checksum --file=$config_file chown -R "$app":"$app" "$final_path" #================================================= -# ADVERTISE SERVICE IN ADMIN PANEL +# INTEGRATE SERVICE IN YUNOHOST #================================================= # if using yunohost version 3.2 or more in the 'manifest.json', a description can be added -yunohost service add $app --description "$app daemon for Wiki.js" -t systemd +yunohost service add $app --description "$app daemon for Wiki.js" --log_type systemd #================================================= # START SYSTEMD SERVICE #================================================= -ynh_systemd_action --service_name=$app --action=start --line_match="Browse to http://localhost" --log_path=systemd - -sleep 30 +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP Server: [ RUNNING ]" #================================================= # SETUP SSOWAT diff --git a/scripts/remove b/scripts/remove index 5d9c264..86f4b65 100644 --- a/scripts/remove +++ b/scripts/remove @@ -27,10 +27,10 @@ ldap_user=$(ynh_app_setting_get --app=$app --key=ldap_user) #================================================= # STANDARD REMOVE #================================================= -# REMOVE SERVICE FROM ADMIN PANEL +# REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= -# Remove a service from the admin panel, added by `yunohost service add` +# Remove the service from the list of services known by Yunohost (added from `yunohost service add`) if ynh_exec_warn_less yunohost service status $app >/dev/null then ynh_print_info --message="Removing $app service..." diff --git a/scripts/restore b/scripts/restore index dad24bc..3835313 100644 --- a/scripts/restore +++ b/scripts/restore @@ -106,19 +106,17 @@ ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service #================================================= -# ADVERTISE SERVICE IN ADMIN PANEL +# INTEGRATE SERVICE IN YUNOHOST #================================================= -yunohost service add $app --description "$app daemon for Wiki.js" -t systemd +yunohost service add $app --description "$app daemon for Wiki.js" --log_type systemd #================================================= # START SYSTEMD SERVICE #================================================= ynh_print_info --message="Starting a systemd service..." -ynh_systemd_action --service_name=$app --action=start --log_path=systemd - -sleep 30 +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP Server: [ RUNNING ]" #================================================= # CREATE LDAP USER diff --git a/scripts/upgrade b/scripts/upgrade index 2585817..dadfc92 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -101,7 +101,7 @@ ynh_abort_if_errors #================================================= ynh_print_info --message="Stopping a systemd service..." -ynh_systemd_action --service_name=$app --action="stop" +ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped wikijs service" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -150,16 +150,16 @@ config_file="$final_path/config.yml" ynh_backup_if_checksum_is_different --file=$config_file cp -f ../conf/config.sample.yml $config_file -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file=$config_file -ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file=$config_file -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file=$config_file +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_file" +ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config_file" +ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config_file" #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= # Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file=$config_file +ynh_store_file_checksum --file="$config_file" #================================================= # SETUP SYSTEMD @@ -196,9 +196,7 @@ fi #================================================= ynh_print_info --message="Starting a systemd service..." -ynh_systemd_action --service_name=$app --action="start" --log_path=systemd - -sleep 30 +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP Server: [ RUNNING ]" #================================================= # RELOAD NGINX