#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= #REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1 #REMOVEME? app=$YNH_APP_INSTANCE_NAME #REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) #REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) #REMOVEME? admin=$(ynh_app_setting_get --app=$app --key=admin) #REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) #REMOVEME? language=$(ynh_app_setting_get --app=$app --key=language) #REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) #REMOVEME? db_user=$db_name #REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) #REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port) #REMOVEME? backend_port=$(ynh_app_setting_get --app=$app --key=backend_port) #REMOVEME? similarity_port=$(ynh_app_setting_get --app=$app --key=similarity_port) #REMOVEME? data_path=$(ynh_app_setting_get --app=$app --key=data_path) #REMOVEME? allow_multimedia_write=$(ynh_app_setting_get --app=$app --key=allow_multimedia_write) #================================================= # CHECK VERSION #================================================= upgrade_type=$(ynh_check_app_version_changed) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= #REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=30 # Backup the current version of the app #REMOVEME? ynh_backup_before_upgrade #REMOVEME? ynh_clean_setup () { # Restore it if the upgrade fails #REMOVEME? ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script #REMOVEME? ynh_abort_if_errors #================================================= # STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= ynh_script_progression --message="Stopping systemd services..." --weight=7 ynh_systemd_action --service_name=$app-backend --action="stop" --log_path="/var/log/$app/gunicorn_django.log" ynh_systemd_action --service_name=$app-frontend --action="stop" --log_path="systemd" ynh_systemd_action --service_name=$app-image-similarity --action="stop" --log_path="/var/log/$app/image_similarity.log" ynh_systemd_action --service_name=$app-worker --action="stop" --log_path="/var/log/$app/$app-worker.log" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # Remove old node version ynh_use_nodejs if [ "$nodejs_version" -eq 10 ]; then ynh_remove_nodejs fi #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= if [ "$upgrade_type" == "UPGRADE_APP" ] then unpack_source fi #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config backend_port #================================================= # UPGRADE DEPENDENCIES #================================================= #REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=1 #REMOVEME? ynh_install_app_dependencies $pkg_dependencies #REMOVEME? ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" #================================================= # CREATE DEDICATED USER #================================================= #REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 # Create a dedicated user (if not existing) #REMOVEME? ynh_system_user_create --username=$app --home_dir=$data_path #================================================= # SPECIFIC UPGRADE #================================================= # SET UP BACKEND #================================================= ynh_script_progression --message="Setting up backend..." --weight=50 set_up_backend #================================================= # SET UP FRONTEND #================================================= ynh_script_progression --message="Setting up frontend..." --weight=5 set_up_frontend #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression --message="Upgrading systemd configurations..." --weight=1 # Create dedicated systemd configs ynh_add_systemd_config --service=$app-backend --template=backend.service ynh_add_systemd_config --service=$app-frontend --template=frontend.service ynh_add_systemd_config --service=$app-image-similarity --template=image-similarity.service ynh_add_systemd_config --service=$app-worker --template=worker.service #================================================= # ADD CONFIGURATIONS #================================================= ynh_script_progression --message="Generating configuration files..." --weight=1 add_configuations #================================================= # FINALIZE DATABASE #================================================= ynh_script_progression --message="Finalizing database..." --weight=1 upgrade_db #================================================= # YUNOHOST MULTIMEDIA INTEGRATION #================================================= ynh_script_progression --message="Adding multimedia directories..." --weight=1 # Build YunoHost multimedia directories ynh_multimedia_build_main_dir if [ $allow_multimedia_write -eq 1 ]; then ynh_multimedia_addaccess $app fi #================================================= # GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= # Set permissions to app files set_permissions #================================================= # SETUP LOGROTATE #================================================= ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 # Use logrotate to manage application logfiles set_up_logrotate #================================================= # INTEGRATE SERVICES IN YUNOHOST #================================================= ynh_script_progression --message="Integrating services in YunoHost..." --weight=1 yunohost service add $app-backend --description="Backend for librephotos" --log="/var/log/$app/gunicorn_django.log" yunohost service add $app-frontend --description="Frontend for librephotos" --log="/var/log/$app/$app-frontend.log" yunohost service add $app-image-similarity --description="Image similarity server for librephotos" --log="/var/log/$app/image_similarity.log" yunohost service add $app-worker --description="Worker for librephotos" --log="/var/log/$app/$app-worker.log" #================================================= # START SYSTEMD SERVICES #================================================= ynh_script_progression --message="Starting systemd services..." --weight=1 # Start systemd services ynh_systemd_action --service_name=$app-backend --action="start" --log_path="/var/log/$app/gunicorn_django.log" --line_match="Listening at: http" ynh_systemd_action --service_name=$app-frontend --action="start" --log_path="systemd" --line_match="INFO: Accepting connections at http:" ynh_systemd_action --service_name=$app-image-similarity --action="start" --log_path="/var/log/$app/image_similarity.log" ynh_systemd_action --service_name=$app-worker --action="start" --log_path="/var/log/$app/$app-worker.log" #================================================= # RELOAD NGINX #================================================= #REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1 #REMOVEME? ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Upgrade of $app completed" --last