This commit is contained in:
YunoHost Bot 2024-09-01 16:15:25 +00:00 committed by GitHub
commit 79399819bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 101 additions and 190 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
*~
*.sw[op]
.DS_Store

View file

@ -18,7 +18,8 @@ code = "https://github.com/bookwyrm-social/bookwyrm"
cpe = "cpe:2.3:a:joinbookwyrm:bookwyrm"
[integration]
yunohost = ">= 11.2"
yunohost = ">= 11.2.18"
helpers_version = "2.1"
architectures = "all"
multi_instance = false
ldap = false
@ -61,6 +62,7 @@ ram.runtime = "50M"
allow_email = true
[resources.install_dir]
group = "www-data:r-x"
[resources.data_dir]

View file

@ -1,17 +1,5 @@
#!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
#=================================================
# PERSONAL HELPERS
#=================================================
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================

View file

@ -1,50 +1,41 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
ynh_print_info "Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="$install_dir"
ynh_backup "$install_dir"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup "/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.target"
ynh_backup "/etc/systemd/system/$app-beat.service"
ynh_backup "/etc/systemd/system/$app-server.service"
ynh_backup "/etc/systemd/system/$app-worker.service"
ynh_backup "/etc/systemd/system/$app.target"
#=================================================
# BACKUP THE POSTGRESQL DATABASE
#=================================================
ynh_print_info --message="Backing up the PostgreSQL database..."
ynh_print_info "Backing up the PostgreSQL database..."
ynh_psql_dump_db --database="$db_name" > db.sql
ynh_psql_dump_db > db.sql
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -1,38 +1,26 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
key=$(ynh_string_random --length=32)
ynh_app_setting_set --app=$app --key=key --value=$key
ynh_app_setting_set --key=key --value=$key
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
ynh_script_progression "Setting up source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir" --source_id="main"
ynh_setup_source --dest_dir="$install_dir/static/fonts/source_han_sans" --source_id="fonts"
# Set permissions to app files
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# CONFIGURE THEN INSTALL SCRIPT AND DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing service script..." --weight=1
ynh_script_progression "Installing service script..."
ynh_add_config --template="../conf/.env.production" --destination="$install_dir/.env"
chmod 600 $install_dir/.env
chown $app:www-data "$install_dir/.env"
ynh_config_add --template=".env.production" --destination="$install_dir/.env"
mkdir "$install_dir/venv"
python3 -m venv "$install_dir/venv"
@ -41,7 +29,7 @@ $install_dir/venv/bin/pip3 install -r "$install_dir/requirements.txt"
#=================================================
# INITIALIZE DATABASE
#=================================================
ynh_script_progression --message="Initializing database..." --weight=1
ynh_script_progression "Initializing database..."
pushd $install_dir
$install_dir/venv/bin/python3 "$install_dir/manage.py" migrate
@ -53,41 +41,40 @@ popd
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
ynh_script_progression "Configuring NGINX web server..."
# Create a dedicated NGINX config
ynh_add_nginx_config
ynh_config_add_nginx
#=================================================
# LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring logrotate..." --weight=1
ynh_script_progression "Configuring logrotate..."
# Use logrotate to manage application logfile(s)
ynh_use_logrotate --specific_user=$app
ynh_config_add_logrotate
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/
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data /var/log/$app/
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=1
ynh_script_progression "Configuring $app's systemd service..."
ynh_add_config --template="../conf/bookwyrm.target" --destination="/etc/systemd/system/$app.target"
ynh_config_add --template="bookwyrm.target" --destination="/etc/systemd/system/$app.target"
# Create a dedicated systemd config
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"
ynh_config_add_systemd --service="$app-server" --template="bookwyrm-server.service"
ynh_config_add_systemd --service="$app-worker" --template="bookwyrm-worker.service"
ynh_config_add_systemd --service="$app-beat" --template="bookwyrm-beat.service"
#=================================================
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
ynh_script_progression "Integrating service in YunoHost..."
yunohost service add "$app-beat" --log="/var/log/$app/$app-beat.log"
yunohost service add "$app-server" --log="/var/log/$app/$app.log"
@ -96,15 +83,15 @@ 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_script_progression "Starting $app's systemd service..."
# Start a systemd service
ynh_systemd_action --service_name="$app-beat" --action="start" --log_path="systemd" --line_match="Started bookwyrm celery beat process"
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_systemctl --service="$app-beat" --action="start" --log_path="systemd" --wait_until="Started bookwyrm celery beat process"
ynh_systemctl --service="$app-server" --action="start" --log_path="systemd" --wait_until="Booting worker with pid"
ynh_systemctl --service="$app-worker" --action="start" --log_path="systemd" --wait_until="ready"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last
ynh_script_progression "Installation of $app completed"

View file

@ -1,11 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
@ -16,57 +10,57 @@ 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-server" >/dev/null
if ynh_hide_warnings yunohost service status "$app-server" >/dev/null
then
ynh_script_progression --message="Removing $app-server service integration..."
ynh_script_progression "Removing $app-server service integration..."
yunohost service remove "$app-server"
fi
if ynh_exec_warn_less yunohost service status "$app-worker" >/dev/null
if ynh_hide_warnings yunohost service status "$app-worker" >/dev/null
then
ynh_script_progression --message="Removing $app-worker service integration..."
ynh_script_progression "Removing $app-worker service integration..."
yunohost service remove "$app-worker"
fi
if ynh_exec_warn_less yunohost service status "$app-beat" >/dev/null
if ynh_hide_warnings yunohost service status "$app-beat" >/dev/null
then
ynh_script_progression --message="Removing $app-beat service integration..."
ynh_script_progression "Removing $app-beat service integration..."
yunohost service remove "$app-beat"
fi
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
ynh_script_progression "Stopping and removing the systemd service..."
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_systemctl --service="$app-beat" --action="stop" --log_path="systemd" --wait_until="Stopped $app"
ynh_systemctl --service="$app-server" --action="stop" --log_path="systemd" --wait_until="Stopped $app"
ynh_systemctl --service="$app-worker" --action="stop" --log_path="systemd" --wait_until="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_config_remove_systemd"$app-beat"
ynh_config_remove_systemd"$app-server"
ynh_config_remove_systemd"$app-worker"
ynh_secure_remove --file="/etc/systemd/system/$app.target"
ynh_safe_rm "/etc/systemd/system/$app.target"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
ynh_script_progression "Removing NGINX web server configuration..."
# Remove the dedicated NGINX config
ynh_remove_nginx_config
ynh_config_remove_nginx
#=================================================
# REMOVE LOGS
#=================================================
ynh_script_progression --message="Removing logs..." --weight=5
ynh_script_progression "Removing logs..."
ynh_remove_logrotate
ynh_config_remove_logrotate
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last
ynh_script_progression "Removal of $app completed"

View file

@ -1,53 +1,43 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_name=$(ynh_app_setting_get --key=db_name)
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
ynh_script_progression "Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1
ynh_script_progression "Restoring the PostgreSQL database..."
ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name
ynh_psql_db_shell < "./db.sql"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_script_progression "Restoring the app main directory..."
ynh_restore_file --origin_path="$install_dir"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
ynh_restore "$install_dir"
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_script_progression "Restoring $app's systemd service..."
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"
ynh_restore "/etc/systemd/system/bookwyrm-beat.service"
ynh_restore "/etc/systemd/system/bookwyrm-server.service"
ynh_restore "/etc/systemd/system/bookwyrm-worker.service"
ynh_restore "/etc/systemd/system/bookwyrm.target"
systemctl enable "bookwyrm-beat.service" --quiet
systemctl enable "bookwyrm-server.service" --quiet
@ -56,7 +46,7 @@ systemctl enable "bookwyrm-worker.service" --quiet
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
ynh_script_progression "Integrating service in YunoHost..."
yunohost service add "$app-beat" --log="/var/log/$app/$app-beat.log"
yunohost service add "$app-server" --log="/var/log/$app/$app.log"
@ -65,23 +55,21 @@ 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_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name="$app-beat" --action="start" --log_path="systemd" --line_match="Started bookwyrm celery beat process"
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_systemctl --service="$app-beat" --action="start" --log_path="systemd" --wait_until="Started bookwyrm celery beat process"
ynh_systemctl --service="$app-server" --action="start" --log_path="systemd" --wait_until="Booting worker with pid"
ynh_systemctl --service="$app-worker" --action="start" --log_path="systemd" --wait_until="ready"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_script_progression "Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
ynh_systemctl --service=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last
ynh_script_progression "Restoration completed for $app"

View file

@ -1,11 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
@ -13,61 +7,39 @@ source /usr/share/yunohost/helpers
# LOAD SETTINGS
#=================================================
# uncomment me after some updates whenever the key variable is set in install for some times
#key=$(ynh_app_setting_get --app=$app --key=key --value=$key)
#remove me when key setting is uncommented (see above)
key=$(ynh_string_random --length=32)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_script_progression "Stopping $app's systemd service..."
ynh_systemd_action --action="stop" --service_name="bookwyrm-beat" --log_path="systemd"
ynh_systemd_action --action="stop" --service_name="bookwyrm-server" --log_path="systemd"
ynh_systemd_action --action="stop" --service_name="bookwyrm-worker" --log_path="systemd"
ynh_systemctl --action="stop" --service="bookwyrm-beat" --log_path="systemd"
ynh_systemctl --action="stop" --service="bookwyrm-server" --log_path="systemd"
ynh_systemctl --action="stop" --service="bookwyrm-worker" --log_path="systemd"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression "Upgrading source files..."
if [ "$upgrade_type" == "UPGRADE_APP" ]
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="$install_dir" --source_id="main" --full_replace=1 --keep=".env"
ynh_setup_source --dest_dir="$install_dir/static/fonts/source_han_sans" --source_id="fonts" --full_replace=1
fi
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
ynh_setup_source --dest_dir="$install_dir" --source_id="main" --full_replace --keep=".env"
ynh_setup_source --dest_dir="$install_dir/static/fonts/source_han_sans" --source_id="fonts" --full_replace
#=================================================
# CONFIGURE THE INSTALL SCRIPT
#=================================================
ynh_script_progression --message="Upgrading .env file..." --weight=1
ynh_script_progression "Upgrading .env file..."
ynh_add_config --template="../conf/.env.production" --destination="$install_dir/.env"
chmod 600 $install_dir/.env
chown $app: "$install_dir/.env"
ynh_config_add --template=".env.production" --destination="$install_dir/.env"
#=================================================
# CONFIGURE THEN INSTALL SCRIPT AND DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing service script..." --weight=1
ynh_script_progression "Installing service script..."
ynh_secure_remove --file="$install_dir/venv"
ynh_safe_rm "$install_dir/venv"
mkdir "$install_dir/venv"
python3 -m venv "$install_dir/venv"
$install_dir/venv/bin/pip3 install -r "$install_dir/requirements.txt"
@ -75,7 +47,7 @@ $install_dir/venv/bin/pip3 install -r "$install_dir/requirements.txt"
#=================================================
# Update DATABASE
#=================================================
ynh_script_progression --message="Upgrading database..." --weight=1
ynh_script_progression "Upgrading database..."
pushd $install_dir
$install_dir/venv/bin/python3 "$install_dir/manage.py" compile_themes
@ -84,38 +56,30 @@ $install_dir/venv/bin/python3 "$install_dir/manage.py" makemigrations --merge --
$install_dir/venv/bin/python3 "$install_dir/manage.py" migrate
popd
#=================================================
# SET PERMISSIONS ON BOOKWYRM DIRECTORY
#=================================================
chown -R $app:www-data $install_dir
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
ynh_script_progression "Upgrading NGINX web server configuration..."
# Create a dedicated NGINX config
ynh_add_nginx_config
ynh_config_add_nginx
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
ynh_script_progression "Upgrading systemd configuration..."
ynh_add_config --template="../conf/bookwyrm.target" --destination="/etc/systemd/system/$app.target"
ynh_config_add --template="bookwyrm.target" --destination="/etc/systemd/system/$app.target"
# Create a dedicated systemd config
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"
ynh_config_add_systemd --service="$app-server" --template="bookwyrm-server.service"
ynh_config_add_systemd --service="$app-worker" --template="bookwyrm-worker.service"
ynh_config_add_systemd --service="$app-beat" --template="bookwyrm-beat.service"
#=================================================
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
ynh_script_progression "Integrating service in YunoHost..."
yunohost service add "$app-beat" --log="/var/log/$app/$app-beat.log"
yunohost service add "$app-server" --log="/var/log/$app/$app.log"
@ -124,14 +88,14 @@ 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_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name="$app-beat" --action="start" --log_path="systemd" --line_match="Started bookwyrm celery beat process"
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_systemctl --service="$app-beat" --action="start" --log_path="systemd" --wait_until="Started bookwyrm celery beat process"
ynh_systemctl --service="$app-server" --action="start" --log_path="systemd" --wait_until="Booting worker with pid"
ynh_systemctl --service="$app-worker" --action="start" --log_path="systemd" --wait_until="ready"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last
ynh_script_progression "Upgrade of $app completed"

View file

@ -1,2 +0,0 @@
*~
*.sw[op]

View file

@ -1,2 +0,0 @@
*~
*.sw[op]