diff --git a/conf/bookwyrm-beat.service b/conf/bookwyrm-beat.service index 71e574f..3d1538a 100644 --- a/conf/bookwyrm-beat.service +++ b/conf/bookwyrm-beat.service @@ -1,7 +1,7 @@ [Unit] Description=__APP__ celery beat process -After=redis.service postgresql.service +After=network.target postgresql.service redis.service PartOf=__APP__.target [Service] diff --git a/conf/bookwyrm-server.service b/conf/bookwyrm-server.service index 568143c..4e5a449 100644 --- a/conf/bookwyrm-server.service +++ b/conf/bookwyrm-server.service @@ -1,7 +1,7 @@ [Unit] Description=__APP__ application server -After=redis.service postgresql.service +After=network.target postgresql.service redis.service PartOf=__APP__.target [Service] diff --git a/conf/bookwyrm-worker.service b/conf/bookwyrm-worker.service index 410d418..c006133 100644 --- a/conf/bookwyrm-worker.service +++ b/conf/bookwyrm-worker.service @@ -1,7 +1,7 @@ [Unit] Description=__APP__ celery worker -After=redis.service postgresql.service +After=network.target postgresql.service redis.service PartOf=__APP__.target [Service] @@ -9,7 +9,7 @@ User=__APP__ Group=__APP__ WorkingDirectory=__INSTALL_DIR__/ EnvironmentFile=__INSTALL_DIR__/.env -ExecStart=__INSTALL_DIR__/venv/bin/celery -A celerywyrm worker -l info -Q high_priority,medium_priority,low_priority,imports +ExecStart=__INSTALL_DIR__/venv/bin/celery -A celerywyrm worker -l info -Q high_priority,medium_priority,low_priority,streams,images,suggested_users,email,connectors,lists,inbox,imports,import_triggered,broadcast,misc NoNewPrivileges=yes PrivateTmp=yes diff --git a/manifest.toml b/manifest.toml index 0daced5..722864d 100644 --- a/manifest.toml +++ b/manifest.toml @@ -70,7 +70,7 @@ ram.runtime = "50M" main.default = 8000 [resources.apt] - packages = "postgresql, postgresql-contrib, python3-venv, libpq-dev, python3-dev" + packages = "postgresql, postgresql-contrib, python3-venv, libpq-dev, python3-pip, python3-dev, libpq-dev" [resources.database] type = "postgresql" diff --git a/scripts/backup b/scripts/backup index 5d28395..1187a94 100755 --- a/scripts/backup +++ b/scripts/backup @@ -31,9 +31,9 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" # BACKUP SYSTEMD #================================================= -ynh_backup --src_path="/etc/systemd/system/${app}-beat.service" -ynh_backup --src_path="/etc/systemd/system/${app}-server.service" -ynh_backup --src_path="/etc/systemd/system/${app}-worker.service" +ynh_backup --src_path="/etc/systemd/system/$app-beat.service" +ynh_backup --src_path="/etc/systemd/system/$app-server.service" +ynh_backup --src_path="/etc/systemd/system/$app-worker.service" ynh_backup --src_path="/etc/systemd/system/$app.target" #================================================= diff --git a/scripts/install b/scripts/install index d622aed..00134ff 100755 --- a/scripts/install +++ b/scripts/install @@ -66,17 +66,29 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config +#================================================= +# LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Configuring logrotate..." --weight=1 + +# Use logrotate to manage application logfile(s) +ynh_use_logrotate --specific_user=$app +touch /var/log/$app/$app.log +touch /var/log/$app/$app-beat.log +touch /var/log/$app/$app-worker.log +chown -R $app:www-data /var/log/$app/ + #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression --message="Configuring a systemd service..." --weight=1 -ynh_add_config --template="../conf/${app}.target" --destination="/etc/systemd/system/$app.target" +ynh_add_config --template="../conf/bookwyrm.target" --destination="/etc/systemd/system/$app.target" # Create a dedicated systemd config -ynh_add_systemd_config --service="${app}-server" --template="${app}-server.service" -ynh_add_systemd_config --service="${app}-worker" --template="${app}-worker.service" -ynh_add_systemd_config --service="${app}-beat" --template="${app}-beat.service" +ynh_add_systemd_config --service="$app-server" --template="bookwyrm-server.service" +ynh_add_systemd_config --service="$app-worker" --template="bookwyrm-worker.service" +ynh_add_systemd_config --service="$app-beat" --template="bookwyrm-beat.service" #================================================= # GENERIC FINALIZATION @@ -85,9 +97,9 @@ ynh_add_systemd_config --service="${app}-beat" --template="${app}-beat.service #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -yunohost service add "${app}-beat" -yunohost service add "${app}-server" -yunohost service add "${app}-worker" +yunohost service add "$app-beat" --log="/var/log/$app/$app-beat.log" +yunohost service add "$app-server" --log="/var/log/$app/$app.log" +yunohost service add "$app-worker" --log="/var/log/$app/$app-worker.log" #================================================= # START SYSTEMD SERVICE @@ -95,9 +107,9 @@ yunohost service add "${app}-worker" ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name="${app}-beat" --action="start" --log_path="systemd" --line_match="Started" -ynh_systemd_action --service_name="${app}-server" --action="start" --log_path="systemd" --line_match="Booting worker with pid" -ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path="systemd" --line_match="ready" +ynh_systemd_action --service_name="$app-beat" --action="start" --log_path="systemd" --line_match="Started" +ynh_systemd_action --service_name="$app-server" --action="start" --log_path="systemd" --line_match="Booting worker with pid" +ynh_systemd_action --service_name="$app-worker" --action="start" --log_path="systemd" --line_match="ready" #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 804edb6..b95a8ed 100644 --- a/scripts/remove +++ b/scripts/remove @@ -9,7 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers - #================================================= # STANDARD REMOVE #================================================= @@ -17,10 +16,22 @@ source /usr/share/yunohost/helpers #================================================= # 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 +if ynh_exec_warn_less yunohost service status "$app-server" >/dev/null then - ynh_script_progression --message="Removing $app service integration..." --weight=1 - yunohost service remove $app + ynh_script_progression --message="Removing $app-server service integration..." + yunohost service remove "$app-server" +fi + +if ynh_exec_warn_less yunohost service status "$app-worker" >/dev/null +then + ynh_script_progression --message="Removing $app-worker service integration..." + yunohost service remove "$app-worker" +fi + +if ynh_exec_warn_less yunohost service status "$app-beat" >/dev/null +then + ynh_script_progression --message="Removing $app-beat service integration..." + yunohost service remove "$app-beat" fi #================================================= @@ -28,25 +39,17 @@ fi #================================================= ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 -ynh_systemd_action --service_name="${app}-beat" --action="stop" --log_path="systemd" --line_match="Stopped $app" -ynh_systemd_action --service_name="${app}-server" --action="stop" --log_path="systemd" --line_match="Stopped $app" -ynh_systemd_action --service_name="${app}-worker" --action="stop" --log_path="systemd" --line_match="Stopped $app" +ynh_systemd_action --service_name="$app-beat" --action="stop" --log_path="systemd" --line_match="Stopped $app" +ynh_systemd_action --service_name="$app-server" --action="stop" --log_path="systemd" --line_match="Stopped $app" +ynh_systemd_action --service_name="$app-worker" --action="stop" --log_path="systemd" --line_match="Stopped $app" # Remove the dedicated systemd config -ynh_remove_systemd_config --service="${app}-beat" -ynh_remove_systemd_config --service="${app}-server" -ynh_remove_systemd_config --service="${app}-worker" +ynh_remove_systemd_config --service="$app-beat" +ynh_remove_systemd_config --service="$app-server" +ynh_remove_systemd_config --service="$app-worker" ynh_secure_remove --file="/etc/systemd/system/$app.target" -#================================================= -# REMOVE APP MAIN DIR -#================================================= -ynh_script_progression --message="Removing app main directory..." --weight=1 - -# Remove the app directory securely -ynh_secure_remove --file="$install_dir" - #================================================= # REMOVE NGINX CONFIGURATION #================================================= @@ -55,6 +58,17 @@ ynh_script_progression --message="Removing NGINX web server configuration..." -- # Remove the dedicated NGINX config ynh_remove_nginx_config +#================================================= +# REMOVE LOGS +#================================================= +ynh_script_progression --message="Removing logs..." --weight=5 + +ynh_remove_logrotate + +# Remove the log files +ynh_secure_remove --file="/var/log/$app" + + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index 2e544a4..0113f4b 100644 --- a/scripts/restore +++ b/scripts/restore @@ -44,32 +44,32 @@ chown -R $app:www-data "$install_dir" #================================================= ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 -ynh_restore_file --origin_path="/etc/systemd/system/${app}-beat.service" -ynh_restore_file --origin_path="/etc/systemd/system/${app}-server.service" -ynh_restore_file --origin_path="/etc/systemd/system/${app}-worker.service" -ynh_restore_file --origin_path="/etc/systemd/system/$app.target" +ynh_restore_file --origin_path="/etc/systemd/system/bookwyrm-beat.service" +ynh_restore_file --origin_path="/etc/systemd/system/bookwyrm-server.service" +ynh_restore_file --origin_path="/etc/systemd/system/bookwyrm-worker.service" +ynh_restore_file --origin_path="/etc/systemd/system/bookwyrm.target" -systemctl enable "${app}-beat.service" --quiet -systemctl enable "${app}-server.service" --quiet -systemctl enable "${app}-worker.service" --quiet +systemctl enable "bookwyrm-beat.service" --quiet +systemctl enable "bookwyrm-server.service" --quiet +systemctl enable "bookwyrm-worker.service" --quiet #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -yunohost service add "${app}-beat" -yunohost service add "${app}-server" -yunohost service add "${app}-worker" +yunohost service add "$app-beat" --log="/var/log/$app/$app-beat.log" +yunohost service add "$app-server" --log="/var/log/$app/$app.log" +yunohost service add "$app-worker" --log="/var/log/$app/$app-worker.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name="${app}-beat" --action="start" --log_path="systemd" --line_match="Started" -ynh_systemd_action --service_name="${app}-server" --action="start" --log_path="systemd" --line_match="Booting worker with pid" -ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path="systemd" --line_match="ready" +ynh_systemd_action --service_name="$app-beat" --action="start" --log_path="systemd" --line_match="Started" +ynh_systemd_action --service_name="$app-server" --action="start" --log_path="systemd" --line_match="Booting worker with pid" +ynh_systemd_action --service_name="$app-worker" --action="start" --log_path="systemd" --line_match="ready" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index b1617f2..a5be43f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -32,9 +32,9 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= ynh_script_progression --message="Stopping a systemd service..." --weight=1 -ynh_systemd_action --action="stop" --service_name="${app}-beat" --log_path="systemd" --line_match="Stopped" -ynh_systemd_action --action="stop" --service_name="${app}-server" --log_path="systemd" --line_match="Stopped" -ynh_systemd_action --action="stop" --service_name="${app}-worker" --log_path="systemd" --line_match="Stopped" +ynh_systemd_action --action="stop" --service_name="bookwyrm-beat" --log_path="systemd" --line_match="Stopped" +ynh_systemd_action --action="stop" --service_name="bookwyrm-server" --log_path="systemd" --line_match="Stopped" +ynh_systemd_action --action="stop" --service_name="bookwyrm-worker" --log_path="systemd" --line_match="Stopped" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -113,12 +113,12 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 -ynh_add_config --template="../conf/${app}.target" --destination="/etc/systemd/system/$app.target" +ynh_add_config --template="../conf/bookwyrm.target" --destination="/etc/systemd/system/$app.target" # Create a dedicated systemd config -ynh_add_systemd_config --service="${app}-server" --template="${app}-server.service" -ynh_add_systemd_config --service="${app}-worker" --template="${app}-worker.service" -ynh_add_systemd_config --service="${app}-beat" --template="${app}-beat.service" +ynh_add_systemd_config --service="$app-server" --template="bookwyrm-server.service" +ynh_add_systemd_config --service="$app-worker" --template="bookwyrm-worker.service" +ynh_add_systemd_config --service="$app-beat" --template="bookwyrm-beat.service" #================================================= # GENERIC FINALIZATION @@ -127,18 +127,18 @@ ynh_add_systemd_config --service="${app}-beat" --template="${app}-beat.service #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -yunohost service add "${app}-beat" -yunohost service add "${app}-server" -yunohost service add "${app}-worker" +yunohost service add "$app-beat" --log="/var/log/$app/$app-beat.log" +yunohost service add "$app-server" --log="/var/log/$app/$app.log" +yunohost service add "$app-worker" --log="/var/log/$app/$app-worker.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name="${app}-beat" --action="start" --log_path="systemd" --line_match="Started" -ynh_systemd_action --service_name="${app}-server" --action="start" --log_path="systemd" --line_match="Booting worker with pid" -ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path="systemd" --line_match="ready" +ynh_systemd_action --service_name="$app-beat" --action="start" --log_path="systemd" --line_match="Started" +ynh_systemd_action --service_name="$app-server" --action="start" --log_path="systemd" --line_match="Booting worker with pid" +ynh_systemd_action --service_name="$app-worker" --action="start" --log_path="systemd" --line_match="ready" #================================================= # END OF SCRIPT