1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pagure_ynh.git synced 2024-09-03 19:56:19 +02:00

Update upgrade

This commit is contained in:
Salamandar 2024-03-15 23:40:31 +01:00
parent d9f13f2f02
commit 19d085ad43
3 changed files with 53 additions and 296 deletions

View file

@ -1,7 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -11,87 +9,14 @@ source ynh_redis
source ynh_uwsgi_service__2
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
#REMOVEME? old_domain=$YNH_APP_OLD_DOMAIN
#REMOVEME? old_path=$YNH_APP_OLD_PATH
#REMOVEME? new_domain=$YNH_APP_NEW_DOMAIN
#REMOVEME? new_path=$YNH_APP_NEW_PATH
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#=================================================
# LOAD SETTINGS
#=================================================
#REMOVEME? ynh_script_progression --message="Loading installation settings..."
#REMOVEME? # Needed for helper "ynh_add_nginx_config"
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
# Add settings here as needed by your application
#REMOVEME? admin=$(ynh_app_setting_get --app=$app --key=admin)
#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#REMOVEME? db_user=$db_name
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#REMOVEME? redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
#REMOVEME? secret_key=$(ynh_app_setting_get --app=$app --key=secret_key)
#REMOVEME? salt_email=$(ynh_app_setting_get --app=$app --key=salt_email)
#REMOVEME? data_dir=$(ynh_app_setting_get --app=$app --key=data_dir)
#=================================================
# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
#=================================================
#REMOVEME? ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..."
# Backup the current version of the app
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? ynh_clean_setup () {
#REMOVEME? ynh_clean_check_starting
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
#REMOVEME? ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# Restore it if the upgrade fails
#REMOVEME? ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
#REMOVEME? ynh_abort_if_errors
#=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED
#=================================================
#REMOVEME? change_domain=0
#REMOVEME? if [ "$old_domain" != "$new_domain" ]
then
#REMOVEME? change_domain=1
fi
#REMOVEME? change_path=0
#REMOVEME? if [ "$old_path" != "$new_path" ]
then
#REMOVEME? change_path=1
fi
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name=${app}_authorized_keys_worker --action="stop" --log_path="systemd"
ynh_systemd_action --service_name=${app}_ci --action="stop" --log_path="systemd"
#ynh_systemd_action --service_name=${app}_ev_server --action="stop" --log_path="systemd"
ynh_systemd_action --service_name=${app}_gitolite_worker --action="stop" --log_path="systemd"
ynh_systemd_action --service_name=${app}_loadjson --action="stop" --log_path="systemd"
ynh_systemd_action --service_name=${app}_logcom --action="stop" --log_path="systemd"
#ynh_systemd_action --service_name=${app}_milters --action="stop" --log_path="systemd"
ynh_systemd_action --service_name=${app}_mirror --action="stop" --log_path="systemd"
ynh_systemd_action --service_name=${app}_webhook --action="stop" --log_path="systemd"
ynh_systemd_action --service_name=${app}_worker --action="stop" --log_path="systemd"
for service in "${services[@]}"; do
ynh_systemd_action --service_name="${app}_${service}" --action="stop" --log_path="systemd"
done
ynh_systemd_action --service_name="uwsgi-app@$app.service" --action="stop" --log_path="systemd"
#=================================================
@ -101,75 +26,30 @@ ynh_script_progression --message="Updating NGINX web server configuration..."
ynh_change_url_nginx_config
#REMOVEME? nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the path in the NGINX config file
if [ $change_path -eq 1 ]
then
# Make a backup of the original NGINX config file if modified
#REMOVEME? ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for NGINX helper
#REMOVEME? domain="$old_domain"
#REMOVEME? path="$new_path"
# Create a dedicated NGINX config
#REMOVEME? ynh_add_nginx_config
fi
# Change the domain for NGINX
if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
#REMOVEME? ynh_delete_file_checksum --file="$nginx_conf_path"
#REMOVEME? mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
#REMOVEME? ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..."
#REMOVEME?
domain=$new_domain
path=$new_path
ynh_add_config --template="../conf/pagure.cfg.sample" --destination="$install_dir/pagure.cfg"
ynh_add_config --template="pagure.cfg.sample" --destination="$install_dir/pagure.cfg"
chmod 400 "$install_dir/pagure.cfg"
chown $app:$app "$install_dir/pagure.cfg"
chown "$app:$app" "$install_dir/pagure.cfg"
ynh_add_config --template="../conf/pagure.wsgi" --destination="$install_dir/pagure.wsgi"
ynh_add_config --template="pagure.wsgi" --destination="$install_dir/pagure.wsgi"
ynh_add_uwsgi_service --service="$app" --template="uwsgi.ini"
#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
# Start a systemd service
ynh_systemd_action --service_name=${app}_authorized_keys_worker --action="start" --log_path="systemd" --line_match="ready"
ynh_systemd_action --service_name=${app}_ci --action="start" --log_path="systemd" --line_match="ready"
#ynh_systemd_action --service_name=${app}_ev_server --action="start" --log_path="systemd" --line_match="ready"
ynh_systemd_action --service_name=${app}_gitolite_worker --action="start" --log_path="systemd" --line_match="ready"
ynh_systemd_action --service_name=${app}_loadjson --action="start" --log_path="systemd" --line_match="ready"
ynh_systemd_action --service_name=${app}_logcom --action="start" --log_path="systemd" --line_match="ready"
#ynh_systemd_action --service_name=${app}_milters --action="start" --log_path="systemd" --line_match="ready"
ynh_systemd_action --service_name=${app}_mirror --action="start" --log_path="systemd" --line_match="ready"
ynh_systemd_action --service_name=${app}_webhook --action="start" --log_path="systemd" --line_match="ready"
ynh_systemd_action --service_name=${app}_worker --action="start" --log_path="systemd" --line_match="ready"
for service in "${services[@]}"; do
ynh_systemd_action --service_name="${app}_${service}" --action="start" --log_path="systemd" --line_match="ready"
done
ynh_systemd_action --service_name="uwsgi-app@$app.service" --action="start" --log_path="systemd" --line_match="Started"
#=================================================
# RELOAD NGINX
#=================================================
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..."
#REMOVEME? #REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================

View file

@ -91,7 +91,7 @@ yunohost service add "uwsgi-app@$app"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_script_progression --message="Starting $app's systemd services..."
# Start a systemd service
for service in "${services[@]}"; do

View file

@ -1,7 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -11,148 +9,41 @@ source ynh_redis
source ynh_uwsgi_service__2
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
#REMOVEME? ynh_script_progression --message="Loading installation settings..."
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path)
#REMOVEME? admin=$(ynh_app_setting_get --app=$app --key=admin)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#REMOVEME? db_user=$db_name
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#REMOVEME? data_dir=$(ynh_app_setting_get --app=$app --key=data_dir)
#REMOVEME? redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
#REMOVEME? secret_key=$(ynh_app_setting_get --app=$app --key=secret_key)
#REMOVEME? salt_email=$(ynh_app_setting_get --app=$app --key=salt_email)
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
# Backup the current version of the app
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? ynh_clean_setup () {
ynh_clean_check_starting
# Restore it if the upgrade fails
#REMOVEME? ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
#REMOVEME? ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name=${app}_authorized_keys_worker --action="stop" --log_path="systemd"
ynh_systemd_action --service_name=${app}_ci --action="stop" --log_path="systemd"
#ynh_systemd_action --service_name=${app}_ev_server --action="stop" --log_path="systemd"
ynh_systemd_action --service_name=${app}_gitolite_worker --action="stop" --log_path="systemd"
ynh_systemd_action --service_name=${app}_loadjson --action="stop" --log_path="systemd"
ynh_systemd_action --service_name=${app}_logcom --action="stop" --log_path="systemd"
#ynh_systemd_action --service_name=${app}_milters --action="stop" --log_path="systemd"
ynh_systemd_action --service_name=${app}_mirror --action="stop" --log_path="systemd"
ynh_systemd_action --service_name=${app}_webhook --action="stop" --log_path="systemd"
ynh_systemd_action --service_name=${app}_worker --action="stop" --log_path="systemd"
for service in "${services[@]}"; do
ynh_systemd_action --service_name="${app}_${service}" --action="stop" --log_path="systemd"
done
ynh_systemd_action --service_name="uwsgi-app@$app.service" --action="stop" --log_path="systemd"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
# Cleaning legacy permissions
#REMOVEME? if ynh_legacy_permissions_exists; then
#REMOVEME? ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
# ynh_script_progression --message="Ensuring downward compatibility..."
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
fi
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
chown -R "$app:www-data" "$install_dir"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..."
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
#REMOVEME? ynh_script_progression --message="Upgrading dependencies..."
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
#=================================================
# SPECIFIC UPGRADE
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..."
ynh_add_config --template="../conf/pagure.cfg.sample" --destination="$install_dir/pagure.cfg"
ynh_add_config --template="pagure.cfg.sample" --destination="$install_dir/pagure.cfg"
chmod 400 "$install_dir/pagure.cfg"
chown $app:$app "$install_dir/pagure.cfg"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..."
# Create a dedicated systemd config
ynh_add_systemd_config --service="${app}_authorized_keys_worker" --template="pagure_authorized_keys_worker.service"
ynh_add_systemd_config --service="${app}_ci" --template="pagure_ci.service"
#ynh_add_systemd_config --service="${app}_ev_server" --template="pagure_ev_server.service"
ynh_add_systemd_config --service="${app}_gitolite_worker" --template="pagure_gitolite_worker.service"
ynh_add_systemd_config --service="${app}_loadjson" --template="pagure_loadjson.service"
ynh_add_systemd_config --service="${app}_logcom" --template="pagure_logcom.service"
#ynh_add_systemd_config --service="${app}_milters" --template="pagure_milters.service"
ynh_add_systemd_config --service="${app}_mirror" --template="pagure_mirror.service"
ynh_add_systemd_config --service="${app}_webhook" --template="pagure_webhook.service"
ynh_add_systemd_config --service="${app}_worker" --template="pagure_worker.service"
ynh_add_config --template="../conf/pagure.wsgi" --destination="$install_dir/pagure.wsgi"
ynh_add_uwsgi_service --service="$app" --template="uwsgi.ini"
chown "$app:$app" "$install_dir/pagure.cfg"
#=================================================
# BUILD APP
@ -161,68 +52,54 @@ ynh_script_progression --message="Building app..."
pushd "$install_dir"
ynh_secure_remove --file="${install_dir}/venv"
python3 -m venv venv
source ./venv/bin/activate
pip install --upgrade pip
pip install wheel
pip install cffi
pip install psycopg2
pip install pyyaml
pip install pygit2
pip install "jinja2<3.1.0"
pip install -r requirements.txt
ynh_add_config --template="../conf/alembic.ini" --destination="$install_dir/alembic.ini"
PAGURE_CONFIG=${install_dir}/pagure.cfg alembic upgrade head 2>&1
ynh_exec_as "$app" python3 -m venv venv
ynh_exec_as "$app" "$install_dir/venv/bin/python3" -m pip install --upgrade pip
ynh_exec_as "$app" "$install_dir/venv/bin/python3" -m pip install wheel
ynh_exec_as "$app" "$install_dir/venv/bin/python3" -m pip install cffi
ynh_exec_as "$app" "$install_dir/venv/bin/python3" -m pip install psycopg2
ynh_exec_as "$app" "$install_dir/venv/bin/python3" -m pip install pyyaml
ynh_exec_as "$app" "$install_dir/venv/bin/python3" -m pip install pygit2
ynh_exec_as "$app" "$install_dir/venv/bin/python3" -m pip install "jinja2<3.1.0"
ynh_exec_as "$app" "$install_dir/venv/bin/python3" -m pip install -r requirements.txt
ynh_add_config --template="alembic.ini" --destination="$install_dir/alembic.ini"
ynh_exec_as "$app" PAGURE_CONFIG="${install_dir}/pagure.cfg" "$install_dir/venv/bin/python3" alembic upgrade head 2>&1
popd
ynh_replace_string --match_string="validators.Required" --replace_string="validators.DataRequired" --target_file="$install_dir/pagure/forms.py"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
chown -R "$app:www-data" "$install_dir"
#=================================================
# GENERIC FINALIZATION
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
yunohost service add ${app}_authorized_keys_worker
yunohost service add ${app}_ci
#yunohost service add ${app}_ev_server
yunohost service add ${app}_gitolite_worker
yunohost service add ${app}_loadjson
yunohost service add ${app}_logcom
#yunohost service add ${app}_milters
yunohost service add ${app}_mirror
yunohost service add ${app}_webhook
yunohost service add ${app}_worker
# Create a dedicated NGINX config
ynh_add_nginx_config
# Create a dedicated systemd config
for service in "${services[@]}"; do
ynh_add_systemd_config --service="${app}_${service}" --template="pagure_${service}.service"
yunohost service add "${app}_${service}"
done
ynh_add_config --template="pagure.wsgi" --destination="$install_dir/pagure.wsgi"
ynh_add_uwsgi_service --service="$app" --template="uwsgi.ini"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_script_progression --message="Starting $app's systemd services..."
# Start a systemd service
for service in "${services[@]}"; do
ynh_systemd_action --service_name="${app}_${service}" --action="start" --log_path="systemd" --line_match="ready"
done
ynh_systemd_action --service_name=${app}_authorized_keys_worker --action="start" --log_path="systemd" --line_match="ready"
ynh_systemd_action --service_name=${app}_ci --action="start" --log_path="systemd" --line_match="ready"
#ynh_systemd_action --service_name=${app}_ev_server --action="start" --log_path="systemd" --line_match="ready"
ynh_systemd_action --service_name=${app}_gitolite_worker --action="start" --log_path="systemd" --line_match="ready"
ynh_systemd_action --service_name=${app}_loadjson --action="start" --log_path="systemd" --line_match="ready"
ynh_systemd_action --service_name=${app}_logcom --action="start" --log_path="systemd" --line_match="ready"
#ynh_systemd_action --service_name=${app}_milters --action="start" --log_path="systemd" --line_match="ready"
ynh_systemd_action --service_name=${app}_mirror --action="start" --log_path="systemd" --line_match="ready"
ynh_systemd_action --service_name=${app}_webhook --action="start" --log_path="systemd" --line_match="ready"
ynh_systemd_action --service_name=${app}_worker --action="start" --log_path="systemd" --line_match="ready"
ynh_systemd_action --service_name="uwsgi-app@$app.service" --action="start" --log_path="systemd" --line_match="Started"
#=================================================
# RELOAD NGINX
#=================================================
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..."
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================