From b1a0c2a5cdb2591214b8a0920fed43830fdc3de0 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 21 Apr 2020 10:43:14 +0200 Subject: [PATCH] Add CRON --- conf/cron | 1 + scripts/backup | 7 +++++++ scripts/install | 10 +++++++++- scripts/remove | 8 ++++++++ scripts/restore | 9 ++++++++- scripts/upgrade | 8 ++++++++ 6 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 conf/cron diff --git a/conf/cron b/conf/cron new file mode 100644 index 00000000..d7b99655 --- /dev/null +++ b/conf/cron @@ -0,0 +1 @@ +* * * * * cd __FINALPATH__/ && php7.3 artisan schedule:run >> /dev/null 2>&1 diff --git a/scripts/backup b/scripts/backup index 057cb238..7d81e8e5 100644 --- a/scripts/backup +++ b/scripts/backup @@ -86,6 +86,13 @@ ynh_print_info --message="Backing up supervisor configuration..." ynh_backup --src_path="/etc/supervisor/conf.d/${app}-horizon.conf" +#================================================= +# BACKUP A CRON FILE +#================================================= +ynh_print_info --message="Backing up a cron file..." + +ynh_backup --src_path="/etc/cron.d/$app" + #================================================= # START SUPERVISOR SERVICE #================================================= diff --git a/scripts/install b/scripts/install index f34c2c6e..6afa9e81 100644 --- a/scripts/install +++ b/scripts/install @@ -198,6 +198,14 @@ pushd "$final_path" php7.3 artisan horizon:assets popd +#================================================= +# INSTALL THE CRON FILE +#================================================= +ynh_print_info --message="Installing cron file..." + +cp ../conf/cron "/etc/cron.d/$app" +ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="/etc/cron.d/$app" + #================================================= # GENERIC FINALIZATION #================================================= @@ -222,7 +230,7 @@ ynh_use_logrotate --logfile="/var/log/$app/${app}-horizon.log" #================================================= ynh_print_info --message="Integrating service in YunoHost..." -yunohost service add "${app}-horizon" --description "${app}-horizon daemon for $app" --log "/var/log/$app/${app}-horizon.log" +yunohost service add "supervisor" --description "${app}-horizon daemon for $app" --log "/var/log/$app/${app}-horizon.log" #================================================= # START SUPERVISOR SERVICE diff --git a/scripts/remove b/scripts/remove index 7a7fd426..bbe6783e 100644 --- a/scripts/remove +++ b/scripts/remove @@ -99,6 +99,14 @@ ynh_remove_logrotate #================================================= # SPECIFIC REMOVE +#================================================= +# REMOVE THE CRON FILE +#================================================= +ynh_print_info --message="Removing the cron file..." + +# Remove a cron file +ynh_secure_remove --file="/etc/cron.d/$app" + #================================================= # REMOVE THE LOG FILE #================================================= diff --git a/scripts/restore b/scripts/restore index 7882de6a..ac7f329d 100644 --- a/scripts/restore +++ b/scripts/restore @@ -139,7 +139,7 @@ supervisorctl reread && supervisorctl update #================================================= ynh_print_info --message="Integrating service in YunoHost..." -yunohost service add "${app}-horizon" --log "/var/log/$app/${app}-horizon.log" +yunohost service add "supervisor" --log "/var/log/$app/${app}-horizon.log" #================================================= # START SUPERVISOR SERVICE @@ -148,6 +148,13 @@ ynh_print_info --message="Starting a supervisor service..." ynh_supervisor_action --service_name="${app}-horizon" --action="start" --log_path="/var/log/$app/${app}-horizon.log" +#================================================= +# RESTORE THE CRON FILE +#================================================= +ynh_print_info --message="Restoring the cron file..." + +ynh_restore_file --origin_path="/etc/cron.d/$app" + #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index cbe5aed8..551b2724 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -226,6 +226,14 @@ mkdir -p "/var/log/$app/" touch "/var/log/$app/${app}-horizon.log" chown -R root: "/var/log/$app/" +#================================================= +# UPGRADE THE CRON FILE +#================================================= +ynh_print_info --message="Upgrading cron file..." + +cp ../conf/cron "/etc/cron.d/$app" +ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="/etc/cron.d/$app" + #================================================= # SETUP LOGROTATE #=================================================