2020-12-23 19:53:13 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2022-08-15 09:01:53 +02:00
|
|
|
#-------------------------------------------------
|
|
|
|
# config_panel.toml settings:
|
|
|
|
|
2022-08-14 19:30:06 +02:00
|
|
|
if [ -z "$debug_enabled" ]; then
|
|
|
|
debug_enabled="0"
|
2023-08-20 17:18:17 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=debug_enabled --value="$debug_enabled"
|
2022-08-14 19:30:06 +02:00
|
|
|
fi
|
2022-08-14 13:59:26 +02:00
|
|
|
|
2022-08-15 09:01:53 +02:00
|
|
|
if [ -z "$log_level" ]; then
|
|
|
|
log_level="WARNING"
|
2023-08-20 17:18:17 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=log_level --value="$log_level"
|
2022-08-15 09:01:53 +02:00
|
|
|
fi
|
|
|
|
|
2022-08-15 09:17:30 +02:00
|
|
|
if [ -z "$admin_email" ]; then
|
2022-08-15 09:46:03 +02:00
|
|
|
admin_email="${admin}@${domain}"
|
2023-08-20 17:18:17 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=admin_email --value="$admin_email"
|
2022-08-15 09:17:30 +02:00
|
|
|
fi
|
|
|
|
|
2022-08-15 09:46:03 +02:00
|
|
|
if [ -z "$default_from_email" ]; then
|
|
|
|
default_from_email="${app}@${domain}"
|
2023-08-20 17:18:17 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=default_from_email --value="$default_from_email"
|
2022-08-15 09:46:03 +02:00
|
|
|
fi
|
|
|
|
|
2020-12-23 19:53:13 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2022-08-24 08:04:05 +02:00
|
|
|
ynh_script_progression --message="Stopping systemd service '$app'..." --weight=5
|
2020-12-23 19:53:13 +01:00
|
|
|
|
2023-08-20 17:18:17 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="$log_file"
|
2020-12-23 19:53:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2022-08-24 10:16:12 +02:00
|
|
|
ynh_script_progression --message="Configuring systemd service '$app'..." --weight=5
|
2020-12-23 19:53:13 +01:00
|
|
|
|
2023-08-20 17:18:17 +02:00
|
|
|
ynh_add_systemd_config --service=$app --template="systemd.service"
|
2020-12-23 19:53:13 +01:00
|
|
|
|
|
|
|
#=================================================
|
2022-08-14 19:30:06 +02:00
|
|
|
# PYTHON VIRTUALENV
|
2020-12-23 19:53:13 +01:00
|
|
|
#=================================================
|
2023-08-20 17:18:17 +02:00
|
|
|
ynh_script_progression --message="Create and setup Python virtualenv..." --weight=45
|
|
|
|
cp ../conf/requirements.txt "$data_dir/requirements.txt"
|
|
|
|
myynh_setup_python_venv
|
2020-12-23 19:53:13 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# copy config files
|
|
|
|
# ================================================
|
2020-12-29 10:51:43 +01:00
|
|
|
ynh_script_progression --message="Create project configuration files..."
|
2020-12-23 19:53:13 +01:00
|
|
|
|
2023-08-20 17:18:17 +02:00
|
|
|
ynh_add_config --template="gunicorn.conf.py" --destination="$data_dir/gunicorn.conf.py"
|
2020-12-23 19:53:13 +01:00
|
|
|
|
2023-08-20 17:18:17 +02:00
|
|
|
ynh_add_config --template="manage.py" --destination="$data_dir/manage.py"
|
|
|
|
chmod -c +x "$data_dir/manage.py"
|
2020-12-23 19:53:13 +01:00
|
|
|
|
2023-08-20 17:18:17 +02:00
|
|
|
ynh_add_config --template="settings.py" --destination="$data_dir/settings.py"
|
|
|
|
ynh_add_config --template="setup_user.py" --destination="$data_dir/setup_user.py"
|
|
|
|
ynh_add_config --template="urls.py" --destination="$data_dir/urls.py"
|
|
|
|
ynh_add_config --template="wsgi.py" --destination="$data_dir/wsgi.py"
|
2020-12-23 19:53:13 +01:00
|
|
|
|
|
|
|
#=================================================
|
2021-02-28 10:56:42 +01:00
|
|
|
# MIGRATE PYINVENTORY
|
2020-12-23 19:53:13 +01:00
|
|
|
#=================================================
|
2021-02-28 10:56:42 +01:00
|
|
|
ynh_script_progression --message="migrate/collectstatic/createadmin..." --weight=10
|
2020-12-23 19:53:13 +01:00
|
|
|
|
2023-08-20 17:18:17 +02:00
|
|
|
cd "$data_dir" || exit
|
2020-12-23 19:53:13 +01:00
|
|
|
|
2022-08-14 13:59:26 +02:00
|
|
|
# Just for debugging:
|
|
|
|
./manage.py diffsettings
|
2020-12-23 19:53:13 +01:00
|
|
|
|
2022-08-14 13:59:26 +02:00
|
|
|
./manage.py migrate --no-input
|
|
|
|
./manage.py collectstatic --no-input
|
2020-12-29 10:51:43 +01:00
|
|
|
|
2022-08-14 13:59:26 +02:00
|
|
|
# Create/update Django superuser (set unusable password, because auth done via SSOwat):
|
2022-08-15 09:17:30 +02:00
|
|
|
./manage.py create_superuser --username="$admin" --email="$(ynh_user_get_info "$admin" mail)"
|
2022-08-14 13:59:26 +02:00
|
|
|
|
|
|
|
# Check the configuration
|
|
|
|
# This may fail in some cases with errors, etc., but the app works and the user can fix issues later.
|
|
|
|
./manage.py check --deploy || true
|
2020-12-23 19:53:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..."
|
|
|
|
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
2023-08-20 17:18:17 +02:00
|
|
|
ynh_use_logrotate --logfile="$log_file" --specific_user=$app --non-append
|
2020-12-23 19:53:13 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
2023-08-20 17:18:17 +02:00
|
|
|
ynh_script_progression --message="Set file permissions..."
|
|
|
|
myynh_fix_file_permissions
|
2022-01-19 09:11:23 +01:00
|
|
|
|
2020-12-23 19:53:13 +01:00
|
|
|
#=================================================
|
2022-08-15 17:15:24 +02:00
|
|
|
# Start the app server via systemd
|
2020-12-23 19:53:13 +01:00
|
|
|
#=================================================
|
2022-08-24 08:04:05 +02:00
|
|
|
ynh_script_progression --message="Starting systemd service '$app'..." --weight=5
|
2020-12-23 19:53:13 +01:00
|
|
|
|
2023-08-20 17:18:17 +02:00
|
|
|
yunohost service add $app
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="$log_file"
|
2020-12-23 19:53:13 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|