1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pytition_ynh.git synced 2024-09-03 20:16:08 +02:00

Add upgrade script

This commit is contained in:
Salamandar 2022-04-11 19:15:46 +02:00 committed by Félix Piédallu
parent 6cc0d6361f
commit 87eff9a5c5
2 changed files with 46 additions and 58 deletions

View file

@ -17,7 +17,7 @@
setup_nourl=0
setup_private=1
setup_public=1
;upgrade=1
upgrade=1
;upgrade=1 from_commit=CommitHash
backup_restore=1
multi_instance=1

View file

@ -18,8 +18,6 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
language=$(ynh_app_setting_get --app=$app --key=language)
admin=$(ynh_app_setting_get --app=$app --key=admin)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
@ -81,26 +79,6 @@ ynh_script_progression --message="Ensuring downward compatibility..." --time --w
# ynh_app_setting_set --app=$app --key=final_path --value=$final_path
#fi
### If nobody installed your app before 4.1,
### then you may safely remove these lines
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
if ! ynh_permission_exists --permission="admin"; then
# Create the required permissions
ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin
fi
# Create a permission if needed
if ! ynh_permission_exists --permission="api"; then
ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true"
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
@ -118,7 +96,7 @@ then
ynh_script_progression --message="Upgrading source files..." --time --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
ynh_setup_source --dest_dir="$final_path/pytition"
fi
# FIXME: this should be managed by the core in the future
@ -146,44 +124,54 @@ ynh_script_progression --message="Upgrading dependencies..." --time --weight=1
ynh_install_app_dependencies "${pkg_dependencies[@]}"
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading PHP-FPM configuration..." --time --weight=1
# Create a dedicated PHP-FPM config
ynh_add_fpm_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
# ...
# Upgrade virtualenv content
#=================================================
ynh_script_progression --message="Upgrading python dependencies..." --time --weight=1
python3 -m venv --upgrade ENV_DIR
(
set +o nounset
source "${final_path}/venv/bin/activate"
set -o nounset
python3 -m pip install -r requirements.txt --upgrade
)
#=================================================
# UPDATE A CONFIG FILE
# Update the configuration
#=================================================
ynh_script_progression --message="Updating a configuration file..." --time --weight=1
ynh_script_progression --message="Adding configuration files..." --time --weight=1
secret_key=$(generate_secret_key)
### Same as during install
###
### The file will automatically be backed-up if it's found to be manually modified (because
### ynh_add_config keeps track of the file's checksum)
config_path="$final_path/pytition/pytition/pytition/settings/config.py"
ynh_add_config --template="../conf/config.py" --destination="$config_path"
chmod 400 "$config_path"
chown $app:$app "$config_path"
ynh_add_config --template="some_config_file" --destination="$final_path/some_config_file"
ynh_add_config --template="../conf/uwsgi.yaml" --destination="$final_path/uwsgi.yaml"
chmod 400 "$final_path/uwsgi.yaml"
chown $app:$app "$final_path/uwsgi.yaml"
# FIXME: this should be handled by the core in the future
# You may need to use chmod 600 instead of 400,
# for example if the app is expected to be able to modify its own config
chmod 400 "$final_path/some_config_file"
chown $app:$app "$final_path/some_config_file"
#=================================================
# Run app configuration
#=================================================
ynh_script_progression --message="Running app configuration..." --time --weight=1
### For more complex cases where you want to replace stuff using regexes,
### you shoud rely on ynh_replace_string (which is basically a wrapper for sed)
### When doing so, you also need to manually call ynh_store_file_checksum
###
### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$final_path/some_config_file"
### ynh_store_file_checksum --file="$final_path/some_config_file"
ynh_exec_as $app bash -c "
set +o nounset
source '$final_path/venv/bin/activate'
set -o nounset
cd '$final_path/pytition/pytition'
export DJANGO_SETTINGS_MODULE=pytition.settings.config
python3 manage.py migrate
python3 manage.py collectstatic
python3 manage.py compilemessages
"
chown -R $app:www-data "$final_path/static"
#=================================================
# SETUP SYSTEMD
@ -198,17 +186,17 @@ ynh_add_systemd_config
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1
# ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
# # Use logrotate to manage app-specific logfile(s)
# ynh_use_logrotate --non-append
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --time --weight=1
yunohost service add $app --description="A short description of the app" --log="/var/log/$app/$app.log"
yunohost service add $app --description="Pytition uWSGI app $app" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
@ -220,10 +208,10 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap
#=================================================
# UPGRADE FAIL2BAN
#=================================================
ynh_script_progression --message="Reconfiguring Fail2Ban..." --time --weight=1
# ynh_script_progression --message="Reconfiguring Fail2Ban..." --time --weight=1
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login"
# # Create a dedicated Fail2Ban config
# ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login"
#=================================================
# RELOAD NGINX