#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh 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_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" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= 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" --keep=".env" ynh_setup_source --dest_dir="$install_dir/static/fonts/source_han_sans" --source_id="fonts" fi chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" #================================================= # CONFIGURE THE INSTALL SCRIPT #================================================= ynh_script_progression --message="Upgrading .env file..." --weight=1 ynh_add_config --template="../conf/.env.production" --destination="$install_dir/.env" chmod 600 $install_dir/.env chown $app: "$install_dir/.env" #================================================= # CONFIGURE THEN INSTALL SCRIPT AND DEPENDENCIES #================================================= ynh_script_progression --message="Installing service script..." --weight=1 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" #================================================= # Update DATABASE #================================================= ynh_script_progression --message="Upgrading database..." --weight=1 pushd $install_dir $install_dir/venv/bin/python3 "$install_dir/manage.py" compile_themes $install_dir/venv/bin/python3 "$install_dir/manage.py" collectstatic --no-input $install_dir/venv/bin/python3 "$install_dir/manage.py" makemigrations --merge --no-input $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 # Create a dedicated NGINX config ynh_add_nginx_config #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 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="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 #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 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 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" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Upgrade of $app completed" --last