[autopatch] Automatic patch attempt for helpers 2.1

This commit is contained in:
Yunohost-Bot 2024-08-30 22:49:21 +02:00 committed by Alexandre Aubin
parent 1fe0a4e15b
commit 1ad6ff5cf1
9 changed files with 111 additions and 148 deletions

3
.gitignore vendored
View file

@ -15,3 +15,6 @@ __pycache__
secret.txt secret.txt
/local_test/ /local_test/
*~
*.sw[op]
.DS_Store

View file

@ -24,6 +24,7 @@ code = "https://github.com/YunoHost-Apps/django_example_ynh"
[integration] [integration]
# https://yunohost.org/en/packaging_manifest#integration-section # https://yunohost.org/en/packaging_manifest#integration-section
yunohost = ">=11.2.12" yunohost = ">=11.2.12"
helpers_version = "2.1"
architectures = "all" architectures = "all"
multi_instance = true multi_instance = true
ldap = true ldap = true
@ -86,6 +87,7 @@ ram.runtime = "50M" # **estimate** minimum ram requirement. e.g. 50M, 400M, 1G,
# This will provision/deprovision a unix system user # This will provision/deprovision a unix system user
[resources.install_dir] [resources.install_dir]
group = "www-data:r-x"
# https://yunohost.org/en/packaging_apps_resources#install-dir # https://yunohost.org/en/packaging_apps_resources#install-dir
# This will create/remove the install dir as /var/www/$app/ # This will create/remove the install dir as /var/www/$app/
# and store the corresponding setting $install_dir and template variable __INSTALL_DIR__ # and store the corresponding setting $install_dir and template variable __INSTALL_DIR__

View file

@ -40,12 +40,12 @@ log_file="${log_path}/${app}.log"
myynh_setup_python_venv() { myynh_setup_python_venv() {
# Always recreate everything fresh with current python version # Always recreate everything fresh with current python version
ynh_secure_remove "$data_dir/venv" ynh_safe_rm "$data_dir/venv"
chown -c -R "$app:" "$data_dir" chown -c -R "$app:" "$data_dir"
# Skip pip because of: https://github.com/YunoHost/issues/issues/1960 # Skip pip because of: https://github.com/YunoHost/issues/issues/1960
ynh_exec_as $app python3 -m venv --without-pip "$data_dir/venv" ynh_exec_as_app python3 -m venv --without-pip "$data_dir/venv"
# run source in a 'sub shell' # run source in a 'sub shell'
( (
@ -54,9 +54,9 @@ myynh_setup_python_venv() {
set -o nounset set -o nounset
set -x set -x
cd "$data_dir" cd "$data_dir"
ynh_exec_as $app $data_dir/venv/bin/python3 -m ensurepip ynh_exec_as_app $data_dir/venv/bin/python3 -m ensurepip
ynh_exec_as $app $data_dir/venv/bin/pip3 install --upgrade wheel pip setuptools ynh_exec_as_app $data_dir/venv/bin/pip3 install --upgrade wheel pip setuptools
ynh_exec_as $app $data_dir/venv/bin/pip3 install --no-deps -r "$data_dir/requirements.txt" ynh_exec_as_app $data_dir/venv/bin/pip3 install --no-deps -r "$data_dir/requirements.txt"
) )
} }
@ -77,9 +77,8 @@ myynh_fix_file_permissions() {
set -x set -x
# /var/www/$app/ # /var/www/$app/
chown -c -R "$app:www-data" "$install_dir" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -c -R "$app:www-data" "$install_dir"
chmod -c o-rwx "$install_dir" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -c o-rwx "$install_dir"
# /home/yunohost.app/$app/ # /home/yunohost.app/$app/
chown -c -R "$app:" "$data_dir" chown -c -R "$app:" "$data_dir"
chmod -c o-rwx "$data_dir" chmod -c o-rwx "$data_dir"

View file

@ -1,40 +1,31 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= ynh_print_info "Declaring files to be backed up..."
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
# /var/www/$app/ # /var/www/$app/
ynh_backup --src_path="$install_dir" ynh_backup "$install_dir"
# /home/yunohost.app/$app/ # /home/yunohost.app/$app/
ynh_backup --src_path="$data_dir" ynh_backup "$data_dir"
#================================================= #=================================================
# BACKUP THE NGINX CONFIGURATION # BACKUP THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# BACKUP THE PostgreSQL DATABASE # BACKUP THE PostgreSQL DATABASE
#================================================= #=================================================
ynh_psql_dump_db --database="$db_name" > db.sql ynh_psql_dump_db > db.sql
#================================================= #=================================================
# SPECIFIC BACKUP # SPECIFIC BACKUP
@ -42,16 +33,16 @@ ynh_psql_dump_db --database="$db_name" > db.sql
# BACKUP LOGROTATE # BACKUP LOGROTATE
#================================================= #=================================================
ynh_backup --src_path="/etc/logrotate.d/$app" ynh_backup "/etc/logrotate.d/$app"
#================================================= #=================================================
# BACKUP SYSTEMD # BACKUP SYSTEMD
#================================================= #=================================================
ynh_backup --src_path="/etc/systemd/system/$app.service" ynh_backup "/etc/systemd/system/$app.service"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -1,49 +1,41 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# STANDARD MODIFICATIONS
#================================================= #=================================================
# STOP SYSTEMD SERVICE # STOP SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping systemd service '$app'..." ynh_script_progression "Stopping systemd service '$app'..."
ynh_systemd_action --service_name=$app --action="stop" --log_path="$log_file" ynh_systemctl --service=$app --action="stop" --log_path="$log_file"
#================================================= #=================================================
# MODIFY URL IN NGINX CONF # MODIFY URL IN NGINX CONF
#================================================= #=================================================
ynh_script_progression --message="Updating nginx web server configuration..." ynh_script_progression "Updating nginx web server configuration..."
ynh_change_url_nginx_config ynh_config_change_url_nginx
#================================================= #=================================================
# UPDATE DJANGO SETTINGS # UPDATE DJANGO SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Update $app settings file..." --weight=1 ynh_script_progression "Update $app settings file..."
path=$new_path path=$new_path
domain=$new_domain domain=$new_domain
ynh_add_config --template="settings.py" --destination="$data_dir/settings.py" ynh_config_add --template="settings.py" --destination="$data_dir/settings.py"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting systemd service '$app'..." --weight=5 ynh_script_progression "Starting systemd service '$app'..."
ynh_systemd_action --service_name=$app --action="start" --log_path="$log_file" ynh_systemctl --service=$app --action="start" --log_path="$log_file"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Change of URL completed for $app" --last ynh_script_progression "Change of URL completed for $app"

View file

@ -31,67 +31,67 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# SETTINGS # SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Storing installation settings..." ynh_script_progression "Storing installation settings..."
# Logging: # Logging:
log_file="/var/log/$app/$app.log" log_file="/var/log/$app/$app.log"
ynh_app_setting_set --app=$app --key=log_file --value="$log_file" ynh_app_setting_set --key=log_file --value="$log_file"
# Redis: # Redis:
redis_db=$(ynh_redis_get_free_db) redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db" ynh_app_setting_set --key=redis_db --value="$redis_db"
# App settings: # App settings:
ynh_app_setting_set --app=$app --key=default_from_email --value="$default_from_email" ynh_app_setting_set --key=default_from_email --value="$default_from_email"
ynh_app_setting_set --app=$app --key=admin_email --value="$admin_email" ynh_app_setting_set --key=admin_email --value="$admin_email"
ynh_app_setting_set --app=$app --key=debug_enabled --value="$debug_enabled" ynh_app_setting_set --key=debug_enabled --value="$debug_enabled"
ynh_app_setting_set --app=$app --key=log_level --value="$log_level" ynh_app_setting_set --key=log_level --value="$log_level"
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#================================================= #=================================================
ynh_script_progression --message="Validating installation parameters..." ynh_script_progression "Validating installation parameters..."
mkdir -p "$install_dir/media" "$install_dir/static" mkdir -p "$install_dir/media" "$install_dir/static"
#================================================= #=================================================
# SETUP LOG FILE # SETUP LOG FILE
#================================================= #=================================================
ynh_script_progression --message="Setup logging..." ynh_script_progression "Setup logging..."
myynh_setup_log_file myynh_setup_log_file
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
ynh_use_logrotate --logfile="$log_file" --specific_user=$app ynh_config_add_logrotate "$log_file"
#================================================= #=================================================
# PYTHON VIRTUALENV # PYTHON VIRTUALENV
#================================================= #=================================================
ynh_script_progression --message="Create and setup Python virtualenv..." --weight=45 ynh_script_progression "Create and setup Python virtualenv..."
cp ../conf/requirements.txt "$data_dir/requirements.txt" cp ../conf/requirements.txt "$data_dir/requirements.txt"
myynh_setup_python_venv myynh_setup_python_venv
#================================================= #=================================================
# copy config files # copy config files
# ================================================ # ================================================
ynh_script_progression --message="Create $app configuration files..." ynh_script_progression "Create $app configuration files..."
ynh_add_config --template="gunicorn.conf.py" --destination="$data_dir/gunicorn.conf.py" ynh_config_add --template="gunicorn.conf.py" --destination="$data_dir/gunicorn.conf.py"
ynh_add_config --template="manage.py" --destination="$data_dir/manage.py" ynh_config_add --template="manage.py" --destination="$data_dir/manage.py"
chmod -c +x "$data_dir/manage.py" chmod -c +x "$data_dir/manage.py"
ynh_add_config --template="settings.py" --destination="$data_dir/settings.py" ynh_config_add --template="settings.py" --destination="$data_dir/settings.py"
ynh_add_config --template="setup_user.py" --destination="$data_dir/setup_user.py" ynh_config_add --template="setup_user.py" --destination="$data_dir/setup_user.py"
ynh_add_config --template="urls.py" --destination="$data_dir/urls.py" ynh_config_add --template="urls.py" --destination="$data_dir/urls.py"
ynh_add_config --template="wsgi.py" --destination="$data_dir/wsgi.py" ynh_config_add --template="wsgi.py" --destination="$data_dir/wsgi.py"
touch "$data_dir/local_settings.py" touch "$data_dir/local_settings.py"
#================================================= #=================================================
# MIGRATE / COLLECTSTATIC / CREATEADMIN # MIGRATE / COLLECTSTATIC / CREATEADMIN
#================================================= #=================================================
ynh_script_progression --message="migrate/collectstatic/createadmin..." --weight=10 ynh_script_progression "migrate/collectstatic/createadmin..."
cd "$data_dir" || exit cd "$data_dir" || exit
@ -111,46 +111,44 @@ cd "$data_dir" || exit
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." ynh_script_progression "Integrating service in YunoHost..."
yunohost service add $app yunohost service add $app
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# SECURE FILES AND DIRECTORIES # SECURE FILES AND DIRECTORIES
#================================================= #=================================================
ynh_script_progression --message="Set file permissions..." ynh_script_progression "Set file permissions..."
myynh_fix_file_permissions myynh_fix_file_permissions
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Configuring systemd service '$app'..." --weight=5 ynh_script_progression "Configuring systemd service '$app'..."
# https://yunohost.org/en/packaging_apps_helpers#ynh-add-systemd-config # https://yunohost.org/en/packaging_apps_helpers#ynh-add-systemd-config
# https://github.com/YunoHost/yunohost/blob/dev/helpers/systemd # https://github.com/YunoHost/yunohost/blob/dev/helpers/systemd
ynh_add_systemd_config --service=$app --template="systemd.service" ynh_config_add_systemd
#================================================= #=================================================
# Start the app server via systemd # Start the app server via systemd
#================================================= #=================================================
ynh_script_progression --message="Starting systemd service '$app'..." --weight=5 ynh_script_progression "Starting systemd service '$app'..."
ynh_systemd_action --service_name=$app --action="start" --log_path="$log_file" ynh_systemctl --service=$app --action="start" --log_path="$log_file"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Configuring nginx web server..." ynh_script_progression "Configuring nginx web server..."
# Create a dedicated nginx config # Create a dedicated nginx config
# https://yunohost.org/en/contribute/packaging_apps/helpers # https://yunohost.org/en/contribute/packaging_apps/helpers
# https://github.com/YunoHost/yunohost/blob/dev/helpers/nginx # https://github.com/YunoHost/yunohost/blob/dev/helpers/nginx
ynh_add_nginx_config "public_path" "port" ynh_config_add_nginx "public_path" "port"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Installation of $app completed" --last ynh_script_progression "Installation of $app completed"

View file

@ -1,11 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -18,16 +12,16 @@ source /usr/share/yunohost/helpers
# Remove a service from the admin panel, added by `yunohost service add` # Remove a service from the admin panel, added by `yunohost service add`
if yunohost service status $app >/dev/null 2>&1 if yunohost service status $app >/dev/null 2>&1
then then
ynh_script_progression --message="Removing $app service integration..." ynh_script_progression "Removing $app service integration..."
yunohost service remove $app yunohost service remove $app
fi fi
#================================================= #=================================================
# STOP PYINVENTORY'S SERVICES # STOP PYINVENTORY'S SERVICES
#================================================= #=================================================
ynh_script_progression --message="Stopping and removing systemd service '$app'..." --weight=5 ynh_script_progression "Stopping and removing systemd service '$app'..."
ynh_remove_systemd_config --service=$app ynh_config_remove_systemd
##================================================= ##=================================================
## REMOVE REDIS DB ## REMOVE REDIS DB
@ -38,31 +32,31 @@ ynh_redis_remove_db
#================================================= #=================================================
# REMOVE APP MAIN DIR # REMOVE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Removing app main directory..." ynh_script_progression "Removing app main directory..."
# /var/www/$app/ # /var/www/$app/
ynh_secure_remove --file="$install_dir" ynh_safe_rm "$install_dir"
# /home/yunohost.app/$app/ # /home/yunohost.app/$app/
ynh_secure_remove --file="$data_dir" ynh_safe_rm "$data_dir"
#================================================= #=================================================
# REMOVE NGINX CONFIGURATION # REMOVE NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Removing nginx web server configuration..." ynh_script_progression "Removing nginx web server configuration..."
# Remove the dedicated nginx config # Remove the dedicated nginx config
ynh_remove_nginx_config ynh_config_remove_nginx
#================================================= #=================================================
# REMOVE LOGROTATE CONFIGURATION # REMOVE LOGROTATE CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Removing logrotate configuration..." ynh_script_progression "Removing logrotate configuration..."
# Remove the app-specific logrotate config # Remove the app-specific logrotate config
ynh_remove_logrotate ynh_config_remove_logrotate
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Removal of $app completed" --last ynh_script_progression "Removal of $app completed"

View file

@ -1,11 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -14,84 +8,80 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# RESTORE THE NGINX CONFIGURATION # RESTORE THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1 ynh_script_progression "Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Restoring $app main directory..." ynh_script_progression "Restoring $app main directory..."
ynh_restore_file --origin_path="$install_dir" ynh_restore "$install_dir"
ynh_restore_file --origin_path="$data_dir" ynh_restore "$data_dir"
ynh_script_progression --message="Set file permissions..." ynh_script_progression "Set file permissions..."
myynh_fix_file_permissions myynh_fix_file_permissions
#================================================= #=================================================
# PYTHON VIRTUALENV # PYTHON VIRTUALENV
# Maybe the backup contains a other Python version # Maybe the backup contains a other Python version
#================================================= #=================================================
ynh_script_progression --message="Create and setup Python virtualenv..." --weight=45 ynh_script_progression "Create and setup Python virtualenv..."
myynh_setup_python_venv myynh_setup_python_venv
#================================================= #=================================================
# RESTORE THE PostgreSQL DATABASE # RESTORE THE PostgreSQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=5 ynh_script_progression "Restoring the PostgreSQL database..."
ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql ynh_psql_db_shell < ./db.sql
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Restoring the systemd $app configuration..." ynh_script_progression "Restoring the systemd $app configuration..."
ynh_restore_file --origin_path="/etc/systemd/system/$app.service" ynh_restore "/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet systemctl enable $app.service --quiet
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." ynh_script_progression "Integrating service in YunoHost..."
yunohost service add $app yunohost service add $app
#================================================= #=================================================
# RESTORE THE LOGROTATE CONFIGURATION # RESTORE THE LOGROTATE CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Setup logging..." ynh_script_progression "Setup logging..."
myynh_setup_log_file myynh_setup_log_file
ynh_restore_file --origin_path="/etc/logrotate.d/$app" ynh_restore "/etc/logrotate.d/$app"
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# SECURE FILES AND DIRECTORIES # SECURE FILES AND DIRECTORIES
#================================================= #=================================================
ynh_script_progression --message="Set file permissions..." ynh_script_progression "Set file permissions..."
myynh_fix_file_permissions myynh_fix_file_permissions
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# START PYINVENTORY # START PYINVENTORY
#================================================= #=================================================
ynh_script_progression --message="Starting systemd service '$app'..." --weight=5 ynh_script_progression "Starting systemd service '$app'..."
ynh_systemd_action --service_name=$app --action="start" --log_path="$log_file" ynh_systemctl --service=$app --action="start" --log_path="$log_file"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading nginx web server..." ynh_script_progression "Reloading nginx web server..."
ynh_systemd_action --service_name="nginx" --action="reload" ynh_systemctl --service="nginx" --action="reload"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Restoration completed for $app" --last ynh_script_progression "Restoration completed for $app"

View file

@ -12,67 +12,64 @@ source /usr/share/yunohost/helpers
if [ -z "$debug_enabled" ]; then if [ -z "$debug_enabled" ]; then
debug_enabled="0" debug_enabled="0"
ynh_app_setting_set --app=$app --key=debug_enabled --value="$debug_enabled" ynh_app_setting_set --key=debug_enabled --value="$debug_enabled"
fi fi
if [ -z "$log_level" ]; then if [ -z "$log_level" ]; then
log_level="WARNING" log_level="WARNING"
ynh_app_setting_set --app=$app --key=log_level --value="$log_level" ynh_app_setting_set --key=log_level --value="$log_level"
fi fi
if [ -z "$admin_email" ]; then if [ -z "$admin_email" ]; then
admin_email="${admin}@${domain}" admin_email="${admin}@${domain}"
ynh_app_setting_set --app=$app --key=admin_email --value="$admin_email" ynh_app_setting_set --key=admin_email --value="$admin_email"
fi fi
if [ -z "$default_from_email" ]; then if [ -z "$default_from_email" ]; then
default_from_email="${app}@${domain}" default_from_email="${app}@${domain}"
ynh_app_setting_set --app=$app --key=default_from_email --value="$default_from_email" ynh_app_setting_set --key=default_from_email --value="$default_from_email"
fi fi
#=================================================
# STANDARD UPGRADE STEPS
#================================================= #=================================================
# STOP SYSTEMD SERVICE # STOP SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping systemd service '$app'..." --weight=5 ynh_script_progression "Stopping systemd service '$app'..."
ynh_systemd_action --service_name=$app --action="stop" --log_path="$log_file"
ynh_systemctl --service=$app --action="stop" --log_path="$log_file"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Configuring systemd service '$app'..." --weight=5 ynh_script_progression "Configuring systemd service '$app'..."
ynh_add_systemd_config --service=$app --template="systemd.service" ynh_config_add_systemd
#================================================= #=================================================
# PYTHON VIRTUALENV # PYTHON VIRTUALENV
#================================================= #=================================================
ynh_script_progression --message="Create and setup Python virtualenv..." --weight=45 ynh_script_progression "Create and setup Python virtualenv..."
cp ../conf/requirements.txt "$data_dir/requirements.txt" cp ../conf/requirements.txt "$data_dir/requirements.txt"
myynh_setup_python_venv myynh_setup_python_venv
#================================================= #=================================================
# copy config files # copy config files
# ================================================ # ================================================
ynh_script_progression --message="Create project configuration files..." ynh_script_progression "Create project configuration files..."
ynh_add_config --template="gunicorn.conf.py" --destination="$data_dir/gunicorn.conf.py" ynh_config_add --template="gunicorn.conf.py" --destination="$data_dir/gunicorn.conf.py"
ynh_add_config --template="manage.py" --destination="$data_dir/manage.py" ynh_config_add --template="manage.py" --destination="$data_dir/manage.py"
chmod -c +x "$data_dir/manage.py" chmod -c +x "$data_dir/manage.py"
ynh_add_config --template="settings.py" --destination="$data_dir/settings.py" ynh_config_add --template="settings.py" --destination="$data_dir/settings.py"
ynh_add_config --template="setup_user.py" --destination="$data_dir/setup_user.py" ynh_config_add --template="setup_user.py" --destination="$data_dir/setup_user.py"
ynh_add_config --template="urls.py" --destination="$data_dir/urls.py" ynh_config_add --template="urls.py" --destination="$data_dir/urls.py"
ynh_add_config --template="wsgi.py" --destination="$data_dir/wsgi.py" ynh_config_add --template="wsgi.py" --destination="$data_dir/wsgi.py"
#================================================= #=================================================
# MIGRATE PYINVENTORY # MIGRATE PYINVENTORY
#================================================= #=================================================
ynh_script_progression --message="migrate/collectstatic/createadmin..." --weight=10 ynh_script_progression "migrate/collectstatic/createadmin..."
cd "$data_dir" || exit cd "$data_dir" || exit
@ -89,33 +86,30 @@ cd "$data_dir" || exit
# This may fail in some cases with errors, etc., but the app works and the user can fix issues later. # 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 ./manage.py check --deploy || true
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." ynh_script_progression "Upgrading logrotate configuration..."
# Use logrotate to manage app-specific logfile(s) # Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --logfile="$log_file" --specific_user=$app --non-append ynh_config_add_logrotate "$log_file"
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# SECURE FILES AND DIRECTORIES # SECURE FILES AND DIRECTORIES
#================================================= #=================================================
ynh_script_progression --message="Set file permissions..." ynh_script_progression "Set file permissions..."
myynh_fix_file_permissions myynh_fix_file_permissions
#================================================= #=================================================
# Start the app server via systemd # Start the app server via systemd
#================================================= #=================================================
ynh_script_progression --message="Starting systemd service '$app'..." --weight=5 ynh_script_progression "Starting systemd service '$app'..."
yunohost service add $app yunohost service add $app
ynh_systemd_action --service_name=$app --action="start" --log_path="$log_file" ynh_systemctl --service=$app --action="start" --log_path="$log_file"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Upgrade of $app completed" --last ynh_script_progression "Upgrade of $app completed"