2022-04-29 12:18:34 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2023-02-19 21:27:20 +01:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
admin_mail=$(ynh_user_get_info --username=$admin --key=username)
|
|
|
|
|
2022-04-29 12:18:34 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2022-12-21 16:57:53 +01:00
|
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
2022-04-29 12:18:34 +02:00
|
|
|
|
2022-12-31 18:14:15 +01:00
|
|
|
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"
|
2022-04-29 12:18:34 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
2022-12-21 16:57:53 +01:00
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=1
|
2022-04-29 12:18:34 +02:00
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2023-02-17 18:52:53 +01:00
|
|
|
ynh_setup_source --dest_dir="$install_dir" --keep=".env"
|
2022-04-29 12:18:34 +02:00
|
|
|
fi
|
|
|
|
|
2023-02-17 18:52:53 +01:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:www-data "$install_dir"
|
2022-04-29 12:18:34 +02:00
|
|
|
|
2023-02-06 11:17:52 +01:00
|
|
|
|
2023-01-01 00:50:33 +01:00
|
|
|
#=================================================
|
|
|
|
# CONFIGURE THEN INSTALL SCRIPT AND DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installing service script..." --weight=1
|
|
|
|
|
2023-02-17 18:52:53 +01:00
|
|
|
ynh_secure_remove --file="$install_dir/venv"
|
|
|
|
mkdir "$install_dir/venv"
|
|
|
|
python3 -m venv "$install_dir/venv"
|
|
|
|
$install_dir/venv/bin/pip3 install -r "$install_dir/requirements.txt"
|
2023-01-01 00:50:33 +01:00
|
|
|
|
2023-02-06 00:05:36 +01:00
|
|
|
#=================================================
|
2023-02-06 01:58:53 +01:00
|
|
|
# Update DATABASE
|
2023-02-06 00:05:36 +01:00
|
|
|
#=================================================
|
2023-02-06 01:58:53 +01:00
|
|
|
ynh_script_progression --message="Upgrading database..." --weight=1
|
2023-02-06 00:05:36 +01:00
|
|
|
|
2023-02-17 18:52:53 +01:00
|
|
|
$install_dir/venv/bin/python3 "$install_dir/manage.py" migrate
|
|
|
|
$install_dir/venv/bin/python3 "$install_dir/manage.py" collectstatic --no-input
|
|
|
|
$install_dir/venv/bin/python3 "$install_dir/manage.py" populate_streams
|
2023-01-28 23:42:59 +01:00
|
|
|
|
2023-01-18 09:27:54 +01:00
|
|
|
#=================================================
|
|
|
|
# SET PERMISSIONS ON BOOKWYRM DIRECTORY
|
|
|
|
#=================================================
|
|
|
|
|
2023-02-17 18:52:53 +01:00
|
|
|
chown -R $app:www-data $install_dir
|
2023-01-18 09:27:54 +01:00
|
|
|
|
2022-04-29 12:18:34 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2022-12-21 16:57:53 +01:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
2022-04-29 12:18:34 +02:00
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2022-12-21 17:12:48 +01:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
2022-04-29 12:18:34 +02:00
|
|
|
|
2022-12-31 18:14:15 +01:00
|
|
|
ynh_add_config --template="../conf/${app}.target" --destination="/etc/systemd/system/$app.target"
|
|
|
|
|
2022-04-29 12:18:34 +02:00
|
|
|
# Create a dedicated systemd config
|
2022-12-31 18:14:15 +01:00
|
|
|
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"
|
2022-04-29 12:18:34 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2022-12-21 16:57:53 +01:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
2022-04-29 12:18:34 +02:00
|
|
|
|
2022-12-31 18:14:15 +01:00
|
|
|
yunohost service add "${app}-beat"
|
|
|
|
yunohost service add "${app}-server"
|
|
|
|
yunohost service add "${app}-worker"
|
2022-04-29 12:18:34 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2022-12-21 16:57:53 +01:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
2022-04-29 12:18:34 +02:00
|
|
|
|
2022-12-31 18:14:15 +01:00
|
|
|
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"
|
2022-04-29 12:18:34 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2022-12-21 16:57:53 +01:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|