2023-11-28 13:20:48 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
2023-12-02 09:50:04 +01:00
|
|
|
# SETUP SYSTEMD
|
2023-11-28 13:20:48 +01:00
|
|
|
#=================================================
|
2023-12-02 09:50:04 +01:00
|
|
|
ynh_script_progression --message="Configuring systemd service '$app'..." --weight=5
|
|
|
|
|
|
|
|
ynh_add_systemd_config --service=$app --template="systemd.service"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# PYTHON VIRTUALENV
|
2023-11-28 13:20:48 +01:00
|
|
|
#=================================================
|
2023-12-02 09:50:04 +01:00
|
|
|
ynh_script_progression --message="Create and setup Python virtualenv..." --weight=45
|
2023-11-28 13:20:48 +01:00
|
|
|
|
2023-12-02 09:50:04 +01:00
|
|
|
ynh_add_config --template="requirements.txt" --destination="$install_dir/requirements.txt"
|
2023-11-28 13:20:48 +01:00
|
|
|
|
2023-12-02 09:50:04 +01:00
|
|
|
myynh_setup_python_venv
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# copy config files
|
|
|
|
# ================================================
|
|
|
|
ynh_script_progression --message="Create $app configuration files..."
|
2023-11-28 13:20:48 +01:00
|
|
|
|
2023-12-02 09:50:04 +01:00
|
|
|
ynh_add_config --template="gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py"
|
2023-11-28 13:20:48 +01:00
|
|
|
|
|
|
|
#=================================================
|
2023-12-02 09:50:04 +01:00
|
|
|
# SETUP LOGROTATE
|
2023-11-28 13:20:48 +01:00
|
|
|
#=================================================
|
2023-12-02 09:50:04 +01:00
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..."
|
2023-11-28 13:20:48 +01:00
|
|
|
|
2023-12-02 09:50:04 +01:00
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate --logfile="$log_file" --specific_user=$app --non-append
|
2023-11-28 13:20:48 +01:00
|
|
|
|
2023-12-02 09:50:04 +01:00
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Set file permissions..."
|
|
|
|
myynh_fix_file_permissions
|
2023-11-28 13:20:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
2023-12-02 09:50:04 +01:00
|
|
|
# REAPPLY SYSTEM CONFIGURATIONS
|
2023-11-28 13:20:48 +01:00
|
|
|
#=================================================
|
2023-12-02 09:50:04 +01:00
|
|
|
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
2023-11-28 13:20:48 +01:00
|
|
|
|
2023-12-02 09:50:04 +01:00
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
ynh_add_systemd_config
|
2023-11-28 13:20:48 +01:00
|
|
|
|
2023-12-04 07:19:43 +01:00
|
|
|
yunohost service add $app --description="Gunicorn running a FastAPI app" --log="/var/log/$app/$app.log"
|
2023-11-28 13:20:48 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|