1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mygpo_ynh.git synced 2024-09-03 19:55:52 +02:00
mygpo_ynh/scripts/upgrade

131 lines
5.2 KiB
Text
Raw Normal View History

2014-10-20 18:55:53 +02:00
#!/bin/bash
2017-06-02 18:44:37 +02:00
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2017-06-05 13:06:35 +02:00
source _common.sh
2017-06-02 18:44:37 +02:00
source /usr/share/yunohost/helpers
2024-03-04 16:37:46 +01:00
#=================================================
# INITIALIZE AND STORE SETTINGS
#=================================================
admin_email=$(ynh_user_get_info --username="$admin" --key="mail")
2019-05-02 20:44:22 +02:00
#=================================================
# STOP SYSTEMD SERVICES
2019-05-02 20:44:22 +02:00
#=================================================
2024-03-04 15:42:05 +01:00
ynh_script_progression --message="Stopping $app's systemd services..." --weight=1
2019-05-02 20:44:22 +02:00
2024-03-04 15:42:05 +01:00
ynh_systemd_action --service_name="$app.socket" --action="stop" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name="$app-beat" --action="stop" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name="$app-celery" --action="stop" --log_path="/var/log/$app/$app.log"
2021-03-15 01:36:28 +01:00
2024-03-04 15:42:05 +01:00
systemctl disable "$app.socket" --quiet
systemctl disable "$app" --quiet
systemctl disable "$app-beat" --quiet
systemctl disable "$app-celery" --quiet
2019-05-02 20:44:22 +02:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2024-03-04 15:47:56 +01:00
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
2024-03-04 15:42:05 +01:00
if [ -n "${data_path:-}" ]; then
ynh_app_setting_delete --app="$app" --key=data_path
ynh_app_setting_delete --app="$app" --key=db_pwd
ynh_app_setting_delete --app="$app" --key=admin_email
fi
2024-03-04 16:37:46 +01:00
if [[ -n "${random_key:-}" ]]; then
secret_key="$random_key"
ynh_app_setting_delete --app="$app" --key=random_key
ynh_app_setting_set --app="$app" --key=secret_key --value="$random_key"
fi
2024-03-04 20:50:00 +01:00
if [ -f "$install_dir/requirements.txt" ]; then
# Move to $install_dir/sources
find "$install_dir" -maxdepth 1 -mindepth 1 -not -name envs -exec rm -rf {} +
fi
2017-06-02 18:44:37 +02:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2024-03-04 15:42:05 +01:00
ynh_script_progression --message="Upgrading source files..." --weight=1
2024-03-04 15:42:05 +01:00
# Download, check integrity, uncompress and patch the source from app.src
2024-03-04 20:50:00 +01:00
ynh_setup_source --dest_dir="$install_dir/sources" --full_replace=1
2017-06-02 18:44:37 +02:00
2024-03-04 15:43:53 +01:00
#=================================================
# APP INITIAL CONFIGURATION
#=================================================
ynh_script_progression --message="Adding $app's configuration files..." --weight=1
2024-03-04 15:49:24 +01:00
mkdir -p "$env_path"
2024-03-04 15:43:53 +01:00
echo "$admin <$admin_email>" > "$env_path/ADMINS"
echo "None" > "$env_path/BROKER_POOL_LIMIT"
echo "redis://localhost:6379" > "$env_path/BROKER_URL"
echo "postgres://$db_user:$db_pwd@localhost:5432/$db_name" > "$env_path/DATABASE_URL"
echo "False" > "$env_path/DEBUG"
echo "$domain" > "$env_path/DEFAULT_BASE_URL"
echo "$app@$domain" > "$env_path/DEFAULT_FROM_EMAIL"
echo "django.core.mail.backends.console.EmailBackend" > "$env_path/EMAIL_BACKEND"
echo "$data_dir" > "$env_path/MEDIA_ROOT"
echo "$secret_key" > "$env_path/SECRET_KEY"
echo "$app@$domain" > "$env_path/SERVER_EMAIL"
set_permissions
2017-06-02 18:44:37 +02:00
2021-03-15 01:36:28 +01:00
#=================================================
# UPDATE VIRTUALENV
2017-06-02 18:44:37 +02:00
#=================================================
2021-03-15 01:36:28 +01:00
ynh_script_progression --message="Upgrading Python virtualenv..." --weight=2
2017-06-02 18:44:37 +02:00
set_up_virtualenv
2017-06-02 18:44:37 +02:00
#=================================================
2021-03-15 01:36:28 +01:00
# PERFORM DATABASE MIGRATIONS
2017-06-02 18:44:37 +02:00
#=================================================
2021-03-15 01:36:28 +01:00
ynh_script_progression --message="Performing database migrations..." --weight=2
upgrade_db
2017-06-02 18:44:37 +02:00
2024-03-04 15:49:24 +01:00
set_permissions
#=================================================
2024-03-04 15:42:05 +01:00
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
2024-03-04 15:42:05 +01:00
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
# Create a dedicated systemd config
ynh_add_systemd_config
2024-03-04 15:43:53 +01:00
yunohost service add "$app" --description="Manage podcast subscriptions, and sync them between apps and devices" --log="/var/log/$app/$app.log"
2021-03-15 01:36:28 +01:00
ynh_add_systemd_config --service="$app-celery" --template systemd-celery.service
ynh_add_systemd_config --service="$app-beat" --template systemd-beat.service
2024-03-04 15:43:53 +01:00
# Some workaround bc ynh_add_system_config doesn't know sockets
ynh_add_systemd_config --service="$app-socket" --template systemd.socket
2021-03-15 01:36:28 +01:00
systemctl disable "$app-socket.service" --quiet
mv "/etc/systemd/system/$app-socket.service" "/etc/systemd/system/$app.socket"
systemctl daemon-reload --quiet
2017-06-02 18:44:37 +02:00
2019-05-02 20:44:22 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2024-03-04 15:42:05 +01:00
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
2017-06-02 18:44:37 +02:00
2024-03-04 15:42:05 +01:00
ynh_systemd_action --service_name="$app.socket" --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name="$app-beat" --action="start" --log_path="/var/log/$app/$app.log"
2019-02-10 15:02:38 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2021-03-15 01:36:28 +01:00
ynh_script_progression --message="Upgrade of $app completed" --last