mirror of
https://github.com/YunoHost-Apps/django_example_ynh.git
synced 2024-09-03 18:26:21 +02:00
115 lines
3.7 KiB
Bash
Executable file
115 lines
3.7 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#-------------------------------------------------
|
|
# config_panel.toml settings:
|
|
|
|
if [ -z "$debug_enabled" ]; then
|
|
debug_enabled="0"
|
|
ynh_app_setting_set --key=debug_enabled --value="$debug_enabled"
|
|
fi
|
|
|
|
if [ -z "$log_level" ]; then
|
|
log_level="WARNING"
|
|
ynh_app_setting_set --key=log_level --value="$log_level"
|
|
fi
|
|
|
|
if [ -z "$admin_email" ]; then
|
|
admin_email="${admin}@${domain}"
|
|
ynh_app_setting_set --key=admin_email --value="$admin_email"
|
|
fi
|
|
|
|
if [ -z "$default_from_email" ]; then
|
|
default_from_email="${app}@${domain}"
|
|
ynh_app_setting_set --key=default_from_email --value="$default_from_email"
|
|
fi
|
|
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression "Stopping systemd service '$app'..."
|
|
|
|
ynh_systemctl --service=$app --action="stop" --log_path="$log_file"
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression "Configuring systemd service '$app'..."
|
|
|
|
ynh_config_add_systemd
|
|
|
|
#=================================================
|
|
# PYTHON VIRTUALENV
|
|
#=================================================
|
|
ynh_script_progression "Create and setup Python virtualenv..."
|
|
cp ../conf/requirements.txt "$data_dir/requirements.txt"
|
|
myynh_setup_python_venv
|
|
|
|
#=================================================
|
|
# copy config files
|
|
# ================================================
|
|
ynh_script_progression "Create project configuration files..."
|
|
|
|
ynh_config_add --template="gunicorn.conf.py" --destination="$data_dir/gunicorn.conf.py"
|
|
|
|
ynh_config_add --template="manage.py" --destination="$data_dir/manage.py"
|
|
chmod -c +x "$data_dir/manage.py"
|
|
|
|
ynh_config_add --template="settings.py" --destination="$data_dir/settings.py"
|
|
ynh_config_add --template="setup_user.py" --destination="$data_dir/setup_user.py"
|
|
ynh_config_add --template="urls.py" --destination="$data_dir/urls.py"
|
|
ynh_config_add --template="wsgi.py" --destination="$data_dir/wsgi.py"
|
|
|
|
#=================================================
|
|
# MIGRATE PYINVENTORY
|
|
#=================================================
|
|
ynh_script_progression "migrate/collectstatic/createadmin..."
|
|
|
|
cd "$data_dir" || exit
|
|
|
|
# Just for debugging:
|
|
./manage.py diffsettings
|
|
|
|
./manage.py migrate --no-input
|
|
./manage.py collectstatic --no-input
|
|
|
|
# Create/update Django superuser (set unusable password, because auth done via SSOwat):
|
|
./manage.py create_superuser --username="$admin" --email="$(ynh_user_get_info "$admin" mail)"
|
|
|
|
# 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
|
|
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
ynh_script_progression "Upgrading logrotate configuration..."
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
ynh_config_add_logrotate "$log_file"
|
|
|
|
#=================================================
|
|
# SECURE FILES AND DIRECTORIES
|
|
#=================================================
|
|
ynh_script_progression "Set file permissions..."
|
|
myynh_fix_file_permissions
|
|
|
|
#=================================================
|
|
# Start the app server via systemd
|
|
#=================================================
|
|
ynh_script_progression "Starting systemd service '$app'..."
|
|
|
|
yunohost service add $app
|
|
ynh_systemctl --service=$app --action="start" --log_path="$log_file"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression "Upgrade of $app completed"
|