From 46180947feabf12b4b0e39a5cfd49b4207620773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Tue, 24 May 2022 20:33:41 +0200 Subject: [PATCH] Queue worker process (#70) * Add worker * regenerate config file * Set log_path to systemd --- conf/.env.example | 2 +- conf/systemd.service | 11 +++++++++++ scripts/backup | 6 ++++++ scripts/change_url | 18 ++++++++++++++++++ scripts/install | 23 +++++++++++++++++++++++ scripts/remove | 21 +++++++++++++++++++++ scripts/restore | 22 ++++++++++++++++++++++ scripts/upgrade | 32 +++++++++++++++++++++++++++----- 8 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 conf/systemd.service diff --git a/conf/.env.example b/conf/.env.example index eb09182..f4f6791 100644 --- a/conf/.env.example +++ b/conf/.env.example @@ -83,7 +83,7 @@ REDIS_SERVERS=127.0.0.1:6379:__REDIS_DB__ # Queue driver to use # Can be 'sync', 'database' or 'redis' -QUEUE_CONNECTION=redis +QUEUE_CONNECTION=database # Storage system to use # Can be 'local', 'local_secure' or 's3' diff --git a/conf/systemd.service b/conf/systemd.service new file mode 100644 index 0000000..fdb603b --- /dev/null +++ b/conf/systemd.service @@ -0,0 +1,11 @@ +[Unit] +Description=BookStack Queue Worker + +[Service] +User=__APP__ +Group=__APP__ +Restart=always +ExecStart=/usr/bin/php__PHPVERSION__ __FINALPATH__/artisan queue:work --sleep=3 --tries=1 --max-time=3600 + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/scripts/backup b/scripts/backup index ae47347..f1fc3d4 100644 --- a/scripts/backup +++ b/scripts/backup @@ -50,6 +50,12 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" +#================================================= +# BACKUP SYSTEMD +#================================================= + +ynh_backup --src_path="/etc/systemd/system/$app.service" + #================================================= # BACKUP THE MYSQL DATABASE #================================================= diff --git a/scripts/change_url b/scripts/change_url index 6e51285..b3884b5 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -63,6 +63,15 @@ then change_path=1 fi +#================================================= +# STANDARD MODIFICATIONS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" + #================================================= # STANDARD MODIFICATIONS #================================================= @@ -107,6 +116,15 @@ popd sed -i "/APP_URL=/c\APP_URL=https://${new_domain}${new_path}" $final_path/.env +#================================================= +# GENERIC FINALISATION +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" + #================================================= # RELOAD NGINX #================================================= diff --git a/scripts/install b/scripts/install index e056634..fe11fde 100644 --- a/scripts/install +++ b/scripts/install @@ -144,6 +144,29 @@ chmod -R o-rwx $final_path chown -R $app:www-data $final_path chown $app:$app $final_path/.env +#================================================= +# SETUP SYSTEMD +#================================================= +ynh_script_progression --message="Configuring a systemd service..." --weight=1 + +# Create a dedicated systemd config +ynh_add_systemd_config + +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 + +yunohost service add $app --description="BookStack Queue Worker" --log="/var/log/$app/$app.log" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=1 + +# Start a systemd service +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" + #================================================= # SETUP SSOWAT #================================================= diff --git a/scripts/remove b/scripts/remove index 1d03002..98d2f79 100644 --- a/scripts/remove +++ b/scripts/remove @@ -22,6 +22,27 @@ db_user=$db_name final_path=$(ynh_app_setting_get --app=$app --key=final_path) redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) +#================================================= +# STANDARD REMOVE +#================================================= +# REMOVE SERVICE INTEGRATION IN YUNOHOST +#================================================= + +# 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_script_progression --message="Removing $app service integration..." --weight=1 + yunohost service remove $app +fi + +#================================================= +# STOP AND REMOVE SERVICE +#================================================= +ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 + +# Remove the dedicated systemd config +ynh_remove_systemd_config + #================================================= # REMOVE THE MYSQL DATABASE #================================================= diff --git a/scripts/restore b/scripts/restore index b7288a5..9157e26 100644 --- a/scripts/restore +++ b/scripts/restore @@ -96,6 +96,28 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +#================================================= +# RESTORE SYSTEMD +#================================================= +ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 + +ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +systemctl enable $app.service --quiet + +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 + +yunohost service add $app --description="BookStack Queue Worker" --log="/var/log/$app/$app.log" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index d13ef17..6a4d9b7 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -100,7 +100,7 @@ then ynh_script_progression --message="Upgrading source files..." --weight=1 # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" --keep="$final_path/.env $final_path/public/uploads $final_path/storage/uploads" + ynh_setup_source --dest_dir="$final_path" --keep="$final_path/public/uploads $final_path/storage/uploads" fi #================================================= @@ -138,12 +138,12 @@ ynh_install_composer #================================================= # MODIFY A CONFIG FILE #================================================= -# ynh_script_progression --message="Adding a configuration file..." --weight=1 +ynh_script_progression --message="Adding a configuration file..." --weight=1 -# app_url_domain="https://$domain${path_url%/}" +app_url_domain="https://$domain${path_url%/}" -# ynh_add_config --template=../conf/.env.example --destination=$final_path/.env -# chmod 600 $final_path/.env +ynh_add_config --template=../conf/.env.example --destination=$final_path/.env +chmod 600 $final_path/.env #================================================= # FINAL BOOKSTACK INSTALL @@ -163,6 +163,28 @@ chmod -R o-rwx $final_path chown -R $app:www-data $final_path chown $app:$app $final_path/.env +#================================================= +# SETUP SYSTEMD +#================================================= +ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 + +# Create a dedicated systemd config +ynh_add_systemd_config + +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 + +yunohost service add $app --description="BookStack Queue Worker" --log="/var/log/$app/$app.log" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" + #================================================= # RELOAD NGINX #=================================================