From 50411a0f56dff1f4fafb8ccafb72a778a68e592c Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 7 Jan 2022 20:19:38 +0100 Subject: [PATCH 1/3] ynh_redis on its own script --- scripts/_common.sh | 42 ------------------------------------------ scripts/install | 1 + scripts/remove | 1 + scripts/upgrade | 1 + scripts/ynh_redis | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 42 deletions(-) create mode 100644 scripts/ynh_redis diff --git a/scripts/_common.sh b/scripts/_common.sh index 5ffdb6ac..406fe699 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -17,45 +17,3 @@ pkg_dependencies="postgresql libgd3 jpegoptim optipng pngquant ffmpeg imagemagic #================================================= # EXPERIMENTAL HELPERS #================================================= - -#================================================= -# REDIS HELPERS -#================================================= - -# get the first available redis database -# -# usage: ynh_redis_get_free_db -# | returns: the database number to use -ynh_redis_get_free_db() { - local result max db - result="$(redis-cli INFO keyspace)" - - # get the num - max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+") - - db=0 - # default Debian setting is 15 databases - for i in $(seq 0 "$max") - do - if ! echo "$result" | grep -q "db$i" - then - db=$i - break 1 - fi - db=-1 - done - - test "$db" -eq -1 && ynh_die --message="No available Redis databases..." - - echo "$db" -} - -# Create a master password and set up global settings -# Please always call this script in install and restore scripts -# -# usage: ynh_redis_remove_db database -# | arg: database - the database to erase -ynh_redis_remove_db() { - local db=$1 - redis-cli -n "$db" flushall -} diff --git a/scripts/install b/scripts/install index b2a4a6be..852df63f 100644 --- a/scripts/install +++ b/scripts/install @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_redis source ynh_supervisor source /usr/share/yunohost/helpers diff --git a/scripts/remove b/scripts/remove index 75f33c32..6908d721 100644 --- a/scripts/remove +++ b/scripts/remove @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_redis source ynh_supervisor source /usr/share/yunohost/helpers diff --git a/scripts/upgrade b/scripts/upgrade index 4a782638..1f78978f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_redis source ynh_supervisor source /usr/share/yunohost/helpers diff --git a/scripts/ynh_redis b/scripts/ynh_redis new file mode 100644 index 00000000..af5a55c2 --- /dev/null +++ b/scripts/ynh_redis @@ -0,0 +1,39 @@ +#!/bin/bash + +# get the first available redis database +# +# usage: ynh_redis_get_free_db +# | returns: the database number to use +ynh_redis_get_free_db() { + local result max db + result="$(redis-cli INFO keyspace)" + + # get the num + max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+") + + db=0 + # default Debian setting is 15 databases + for i in $(seq 0 "$max") + do + if ! echo "$result" | grep -q "db$i" + then + db=$i + break 1 + fi + db=-1 + done + + test "$db" -eq -1 && ynh_die --message="No available Redis databases..." + + echo "$db" +} + +# Create a master password and set up global settings +# Please always call this script in install and restore scripts +# +# usage: ynh_redis_remove_db database +# | arg: database - the database to erase +ynh_redis_remove_db() { + local db=$1 + redis-cli -n "$db" flushall +} From 4f6f20b9eb49829fffa442c40266decbf09984b9 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 7 Jan 2022 20:29:28 +0100 Subject: [PATCH 2/3] Apply last example_ynh --- scripts/_common.sh | 4 ++++ scripts/remove | 25 ++++++++++------------- scripts/restore | 49 +++++++++++++++++++++------------------------- scripts/upgrade | 24 +++++++++++------------ 4 files changed, 48 insertions(+), 54 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 406fe699..3e4035a2 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -17,3 +17,7 @@ pkg_dependencies="postgresql libgd3 jpegoptim optipng pngquant ffmpeg imagemagic #================================================= # EXPERIMENTAL HELPERS #================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= diff --git a/scripts/remove b/scripts/remove index 6908d721..06262450 100644 --- a/scripts/remove +++ b/scripts/remove @@ -44,6 +44,14 @@ ynh_script_progression --message="Stopping and removing the supervisor service.. # Remove the dedicated supervisor config ynh_remove_supervisor_config --service="${app}-horizon" +#================================================= +# REMOVE LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Removing logrotate configuration..." + +# Remove the app-specific logrotate config +ynh_remove_logrotate + #================================================= # REMOVE THE POSTGRESQL DATABASE #================================================= @@ -91,29 +99,16 @@ ynh_script_progression --message="Removing dependencies..." # Remove metapackage and its dependencies ynh_remove_app_dependencies -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Removing logrotate configuration..." - -# Remove the app-specific logrotate config -ynh_remove_logrotate - #================================================= # SPECIFIC REMOVE #================================================= -# REMOVE THE CRON FILE +# REMOVE VARIOUS FILES #================================================= -ynh_script_progression --message="Removing the cron file..." +ynh_script_progression --message="Removing various files..." # Remove a cron file ynh_secure_remove --file="/etc/cron.d/$app" -#================================================= -# REMOVE THE LOG FILE -#================================================= -ynh_script_progression --message="Removing the log file..." - # Remove the log files ynh_secure_remove --file="/var/log/$app" diff --git a/scripts/restore b/scripts/restore index a306338b..435ba9fd 100644 --- a/scripts/restore +++ b/scripts/restore @@ -43,7 +43,8 @@ fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage) #================================================= ynh_script_progression --message="Validating restoration parameters..." -test ! -d $final_path || ynh_die --message="There is already a directory: $final_path " +test ! -d $final_path \ + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS @@ -85,25 +86,6 @@ ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint --phpversion=$p #================================================= # SPECIFIC RESTORATION -#================================================= -# RESTORE THE CRON FILE -#================================================= -ynh_script_progression --message="Restoring the cron file..." - -ynh_restore_file --origin_path="/etc/cron.d/$app" - -chown root: "/etc/cron.d/$app" -chmod 644 "/etc/cron.d/$app" - -#================================================= -# CREATE LOG FILE -#================================================= -ynh_script_progression --message="Creating log file..." - -mkdir -p "/var/log/$app/" -touch "/var/log/$app/${app}-horizon.log" -chown -R $app: "/var/log/$app/" - #================================================= # REINSTALL DEPENDENCIES #================================================= @@ -122,6 +104,19 @@ ynh_psql_test_if_first_run ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name +#================================================= +# RESTORE VARIOUS FILES +#================================================= +ynh_script_progression --message="Restoring various files..." + +ynh_restore_file --origin_path="/etc/cron.d/$app" +chown root: "/etc/cron.d/$app" +chmod 644 "/etc/cron.d/$app" + +mkdir -p "/var/log/$app/" +touch "/var/log/$app/${app}-horizon.log" +chown -R $app: "/var/log/$app/" + #================================================= # RESTORE SUPERVISOR CONFIGURATION #================================================= @@ -130,6 +125,13 @@ ynh_script_progression --message="Restoring the supervisor configuration..." ynh_restore_file --origin_path="/etc/supervisor/conf.d/${app}-horizon.conf" supervisorctl reread && supervisorctl update +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the logrotate configuration..." + +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= @@ -144,13 +146,6 @@ ynh_script_progression --message="Starting a supervisor service..." ynh_supervisor_action --service_name="${app}-horizon" --action="reload" --log_path="systemd" --line_match="success: ${app}-horizon" -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the logrotate configuration..." - -ynh_restore_file --origin_path="/etc/logrotate.d/$app" - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 1f78978f..a116a6e5 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -54,9 +54,18 @@ ynh_clean_setup () { ynh_abort_if_errors #================================================= -# ENSURE UPGRADE COMPATIBILITY +# STANDARD UPGRADE STEPS #================================================= -ynh_script_progression --message="Ensuring upgrade compatibility..." +# STOP SUPERVISOR SERVICE +#================================================= +ynh_script_progression --message="Stopping a supervisor service..." + +ynh_supervisor_action --service_name="${app}-horizon" --action="stop" --log_path="systemd" --line_match="stopped: ${app}-horizon" + +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= +ynh_script_progression --message="Ensuring downward compatibility..." # If fpm_footprint doesn't exist, create it if [ -z "$fpm_footprint" ]; then @@ -132,22 +141,13 @@ if ynh_legacy_permissions_exists; then ynh_app_setting_delete --app=$app --key=is_public fi -#================================================= -# STANDARD UPGRADE STEPS -#================================================= -# STOP SUPERVISOR SERVICE -#================================================= -ynh_script_progression --message="Stopping a supervisor service..." - -ynh_supervisor_action --service_name="${app}-horizon" --action="stop" --log_path="systemd" --line_match="stopped: ${app}-horizon" - #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Making sure dedicated system user exists..." # Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir="$final_path" +ynh_system_user_create --username=$app --home_dir=$final_path #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE From 50aa5d724f336acabafadac9ca95791f55f8883f Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 7 Jan 2022 20:34:12 +0100 Subject: [PATCH 3/3] Fix #155 --- conf/cron | 2 +- scripts/install | 3 --- scripts/restore | 2 -- scripts/upgrade | 3 --- 4 files changed, 1 insertion(+), 9 deletions(-) diff --git a/conf/cron b/conf/cron index 659c3411..8100d341 100644 --- a/conf/cron +++ b/conf/cron @@ -1 +1 @@ -* * * * * /usr/bin/php__PHPVERSION__ __FINALPATH__/artisan schedule:run >> /dev/null 2>&1 +* * * * * __APP__ /usr/bin/php__PHPVERSION__ __FINALPATH__/artisan schedule:run >> /dev/null 2>&1 diff --git a/scripts/install b/scripts/install index 852df63f..2ec24270 100644 --- a/scripts/install +++ b/scripts/install @@ -184,9 +184,6 @@ ynh_script_progression --message="Installing the cron file..." ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" -chown root: "/etc/cron.d/$app" -chmod 644 "/etc/cron.d/$app" - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index 435ba9fd..1b93b2e1 100644 --- a/scripts/restore +++ b/scripts/restore @@ -110,8 +110,6 @@ ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name ynh_script_progression --message="Restoring various files..." ynh_restore_file --origin_path="/etc/cron.d/$app" -chown root: "/etc/cron.d/$app" -chmod 644 "/etc/cron.d/$app" mkdir -p "/var/log/$app/" touch "/var/log/$app/${app}-horizon.log" diff --git a/scripts/upgrade b/scripts/upgrade index a116a6e5..59ed3950 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -247,9 +247,6 @@ ynh_script_progression --message="Upgrading cron file..." ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" -chown root: "/etc/cron.d/$app" -chmod 644 "/etc/cron.d/$app" - #================================================= # SETUP SUPERVISOR #=================================================