Merge pull request #49 from YunoHost-Apps/test-multi_instance

Test multi instance
This commit is contained in:
Thomas 2023-11-19 12:26:39 +01:00 committed by GitHub
commit 1619e13c9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 88 additions and 62 deletions

View file

@ -1,7 +1,7 @@
[Unit] [Unit]
Description=__APP__ celery beat process Description=__APP__ celery beat process
After=redis.service postgresql.service After=network.target postgresql.service redis.service
PartOf=__APP__.target PartOf=__APP__.target
[Service] [Service]

View file

@ -1,7 +1,7 @@
[Unit] [Unit]
Description=__APP__ application server Description=__APP__ application server
After=redis.service postgresql.service After=network.target postgresql.service redis.service
PartOf=__APP__.target PartOf=__APP__.target
[Service] [Service]

View file

@ -1,7 +1,7 @@
[Unit] [Unit]
Description=__APP__ celery worker Description=__APP__ celery worker
After=redis.service postgresql.service After=network.target postgresql.service redis.service
PartOf=__APP__.target PartOf=__APP__.target
[Service] [Service]
@ -9,7 +9,7 @@ User=__APP__
Group=__APP__ Group=__APP__
WorkingDirectory=__INSTALL_DIR__/ WorkingDirectory=__INSTALL_DIR__/
EnvironmentFile=__INSTALL_DIR__/.env 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 NoNewPrivileges=yes
PrivateTmp=yes PrivateTmp=yes

View file

@ -70,7 +70,7 @@ ram.runtime = "50M"
main.default = 8000 main.default = 8000
[resources.apt] [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] [resources.database]
type = "postgresql" type = "postgresql"

View file

@ -31,9 +31,9 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
# BACKUP SYSTEMD # BACKUP SYSTEMD
#================================================= #=================================================
ynh_backup --src_path="/etc/systemd/system/${app}-beat.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-server.service"
ynh_backup --src_path="/etc/systemd/system/${app}-worker.service" ynh_backup --src_path="/etc/systemd/system/$app-worker.service"
ynh_backup --src_path="/etc/systemd/system/$app.target" ynh_backup --src_path="/etc/systemd/system/$app.target"
#================================================= #=================================================

View file

@ -66,17 +66,29 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=1
# Create a dedicated NGINX config # Create a dedicated NGINX config
ynh_add_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 # SETUP SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=1 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 # Create a dedicated systemd config
ynh_add_systemd_config --service="${app}-server" --template="${app}-server.service" ynh_add_systemd_config --service="$app-server" --template="bookwyrm-server.service"
ynh_add_systemd_config --service="${app}-worker" --template="${app}-worker.service" ynh_add_systemd_config --service="$app-worker" --template="bookwyrm-worker.service"
ynh_add_systemd_config --service="${app}-beat" --template="${app}-beat.service" ynh_add_systemd_config --service="$app-beat" --template="bookwyrm-beat.service"
#================================================= #=================================================
# GENERIC FINALIZATION # 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 ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add "${app}-beat" yunohost service add "$app-beat" --log="/var/log/$app/$app-beat.log"
yunohost service add "${app}-server" yunohost service add "$app-server" --log="/var/log/$app/$app.log"
yunohost service add "${app}-worker" yunohost service add "$app-worker" --log="/var/log/$app/$app-worker.log"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
@ -95,9 +107,9 @@ yunohost service add "${app}-worker"
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service # 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-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-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-worker" --action="start" --log_path="systemd" --line_match="ready"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -9,7 +9,6 @@
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# STANDARD REMOVE # 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`) # 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 then
ynh_script_progression --message="Removing $app service integration..." --weight=1 ynh_script_progression --message="Removing $app-server service integration..."
yunohost service remove $app 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 fi
#================================================= #=================================================
@ -28,25 +39,17 @@ fi
#================================================= #=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 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-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-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-worker" --action="stop" --log_path="systemd" --line_match="Stopped $app"
# Remove the dedicated systemd config # Remove the dedicated systemd config
ynh_remove_systemd_config --service="${app}-beat" ynh_remove_systemd_config --service="$app-beat"
ynh_remove_systemd_config --service="${app}-server" ynh_remove_systemd_config --service="$app-server"
ynh_remove_systemd_config --service="${app}-worker" ynh_remove_systemd_config --service="$app-worker"
ynh_secure_remove --file="/etc/systemd/system/$app.target" 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 # REMOVE NGINX CONFIGURATION
#================================================= #=================================================
@ -55,6 +58,17 @@ ynh_script_progression --message="Removing NGINX web server configuration..." --
# Remove the dedicated NGINX config # Remove the dedicated NGINX config
ynh_remove_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 # END OF SCRIPT
#================================================= #=================================================

View file

@ -44,32 +44,32 @@ chown -R $app:www-data "$install_dir"
#================================================= #=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 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/bookwyrm-beat.service"
ynh_restore_file --origin_path="/etc/systemd/system/${app}-server.service" ynh_restore_file --origin_path="/etc/systemd/system/bookwyrm-server.service"
ynh_restore_file --origin_path="/etc/systemd/system/${app}-worker.service" ynh_restore_file --origin_path="/etc/systemd/system/bookwyrm-worker.service"
ynh_restore_file --origin_path="/etc/systemd/system/$app.target" ynh_restore_file --origin_path="/etc/systemd/system/bookwyrm.target"
systemctl enable "${app}-beat.service" --quiet systemctl enable "bookwyrm-beat.service" --quiet
systemctl enable "${app}-server.service" --quiet systemctl enable "bookwyrm-server.service" --quiet
systemctl enable "${app}-worker.service" --quiet systemctl enable "bookwyrm-worker.service" --quiet
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add "${app}-beat" yunohost service add "$app-beat" --log="/var/log/$app/$app-beat.log"
yunohost service add "${app}-server" yunohost service add "$app-server" --log="/var/log/$app/$app.log"
yunohost service add "${app}-worker" yunohost service add "$app-worker" --log="/var/log/$app/$app-worker.log"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 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-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-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-worker" --action="start" --log_path="systemd" --line_match="ready"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION

View file

@ -32,9 +32,9 @@ upgrade_type=$(ynh_check_app_version_changed)
#================================================= #=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1 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="bookwyrm-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="bookwyrm-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-worker" --log_path="systemd" --line_match="Stopped"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
@ -113,12 +113,12 @@ ynh_add_nginx_config
#================================================= #=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 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 # Create a dedicated systemd config
ynh_add_systemd_config --service="${app}-server" --template="${app}-server.service" ynh_add_systemd_config --service="$app-server" --template="bookwyrm-server.service"
ynh_add_systemd_config --service="${app}-worker" --template="${app}-worker.service" ynh_add_systemd_config --service="$app-worker" --template="bookwyrm-worker.service"
ynh_add_systemd_config --service="${app}-beat" --template="${app}-beat.service" ynh_add_systemd_config --service="$app-beat" --template="bookwyrm-beat.service"
#================================================= #=================================================
# GENERIC FINALIZATION # 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 ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add "${app}-beat" yunohost service add "$app-beat" --log="/var/log/$app/$app-beat.log"
yunohost service add "${app}-server" yunohost service add "$app-server" --log="/var/log/$app/$app.log"
yunohost service add "${app}-worker" yunohost service add "$app-worker" --log="/var/log/$app/$app-worker.log"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 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-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-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-worker" --action="start" --log_path="systemd" --line_match="ready"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT