1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/acropolis_ynh.git synced 2024-09-03 18:06:22 +02:00
acropolis_ynh/scripts/upgrade

222 lines
8.5 KiB
Text
Raw Normal View History

2021-11-10 19:58:54 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
2023-10-04 12:18:39 +02:00
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
2021-11-10 19:58:54 +01:00
2023-10-04 12:18:39 +02:00
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
2021-11-10 19:58:54 +01:00
2023-10-04 12:18:39 +02:00
#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=$(ynh_app_setting_get --app=$app --key=db_user)
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#REMOVEME? port_web=$(ynh_app_setting_get --app=$app --key=port_web)
2021-11-10 19:58:54 +01:00
#=================================================
# CHECK VERSION
#=================================================
2022-07-15 05:14:36 +02:00
ynh_script_progression --message="Checking version..."
2021-11-10 19:58:54 +01:00
upgrade_type=$(ynh_check_app_version_changed)
2022-07-15 05:14:36 +02:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2023-10-04 12:18:39 +02:00
#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
2022-07-15 05:14:36 +02:00
# Backup the current version of the app
2023-10-04 12:18:39 +02:00
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? ynh_clean_setup () {
2022-07-15 05:14:36 +02:00
ynh_clean_check_starting
# Restore it if the upgrade fails
2023-10-04 12:18:39 +02:00
#REMOVEME? ynh_restore_upgradebackup
2022-07-15 05:14:36 +02:00
}
# Exit if an error occurs during the execution of the script
2023-10-04 12:18:39 +02:00
#REMOVEME? ynh_abort_if_errors
2022-07-15 05:14:36 +02:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=${app}-web --action="stop" --log_path=systemd --line_match="Stopped"
ynh_systemd_action --service_name=${app}-sidekiq --action="stop" --log_path=systemd --line_match="Stopped"
2021-11-15 20:16:45 +01:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
# Cleaning legacy permissions
2023-10-04 12:18:39 +02:00
#REMOVEME? if ynh_legacy_permissions_exists; then
#REMOVEME? ynh_legacy_permissions_delete_all
2021-11-15 20:16:45 +01:00
ynh_app_setting_delete --app=$app --key=is_public
fi
# If port_web doesn't exist, create it, needed for old install
if [[ -z "$port_web" ]]; then
port_web=3000
2023-10-04 12:18:39 +02:00
#REMOVEME? ynh_app_setting_set --app=$app --key=port_web --value=$port_web
2021-11-15 20:16:45 +01:00
fi
# If db_pwd doesn't exist, create it, needed for old install
if [[ -z "$db_pwd" ]]; then
db_pwd=$(ynh_string_random)
2023-10-04 12:18:39 +02:00
#REMOVEME? ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd
#REMOVEME? ynh_psql_test_if_first_run
2021-11-15 20:16:45 +01:00
sudo --login --user=postgres psql -c"ALTER user $app WITH PASSWORD '$db_pwd'" postgres
ynh_replace_string --match_string="DB_PASS=" --replace_string="DB_PASS=${db_pwd}" --target_file="$config"
fi
ynh_remove_extra_repo
2022-07-15 15:35:26 +02:00
ynh_app_setting_delete --app=$app --key=redis_namespace
2022-07-15 15:37:06 +02:00
ynh_app_setting_delete --app=$app --key=secret_key_base
2021-11-10 19:58:54 +01:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2023-10-04 12:18:39 +02:00
#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
2021-11-10 19:58:54 +01:00
# Create a dedicated user (if not existing)
2023-10-04 12:18:39 +02:00
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
2021-11-10 19:58:54 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --weight=1
2021-11-10 19:58:54 +01:00
# Download, check integrity, uncompress and patch the source from app.src
2023-10-04 12:18:39 +02:00
ynh_setup_source --dest_dir="$install_dir"
2021-11-10 19:58:54 +01:00
fi
2023-10-04 12:18:39 +02:00
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
2021-11-10 19:58:54 +01:00
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2023-10-04 12:18:39 +02:00
#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=1
2021-11-10 19:58:54 +01:00
2023-10-04 12:18:39 +02:00
#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
2022-07-15 05:14:36 +02:00
ynh_exec_warn_less ynh_install_ruby --ruby_version=$RUBY_VERSION
2021-11-10 19:58:54 +01:00
#=================================================
2022-07-15 05:14:36 +02:00
# NGINX CONFIGURATION
2021-11-10 19:58:54 +01:00
#=================================================
2022-07-15 05:14:36 +02:00
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
2021-11-15 20:16:45 +01:00
2022-07-15 05:14:36 +02:00
#=================================================
# SPECIFIC UPGRADE
2021-11-10 19:58:54 +01:00
#=================================================
2021-11-15 20:16:45 +01:00
# INSTALLING RUBY AND BUNDLER
#=================================================
ynh_script_progression --message="Installing Ruby..."
2023-10-04 12:18:39 +02:00
pushd "$install_dir"
2021-11-15 20:16:45 +01:00
ynh_use_ruby
ynh_gem install bundler:1.17.3 --no-document
2023-10-04 12:18:39 +02:00
ynh_exec_as $app echo "gem: --no-ri --no-rdoc" >> "$install_dir/.gemrc"
2021-11-15 20:16:45 +01:00
popd
2021-11-10 19:58:54 +01:00
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1
2021-11-10 19:58:54 +01:00
2023-10-04 12:18:39 +02:00
database_yml="$install_dir/config/database.yml"
diaspora_toml="$install_dir/config/diaspora.toml"
2021-11-15 20:16:45 +01:00
2022-07-15 17:22:00 +02:00
ynh_add_config --template="../conf/database.yml.example" --destination="$database_yml"
ynh_add_config --template="../conf/diaspora.toml.example" --destination="$diaspora_toml"
2021-11-15 20:16:45 +01:00
chmod 400 "$database_yml"
chown $app:$app "$database_yml"
chmod 400 "$diaspora_toml"
chown $app:$app "$diaspora_toml"
2021-11-10 19:58:54 +01:00
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
2021-11-10 19:58:54 +01:00
# Create a dedicated systemd config
ynh_add_systemd_config --service="$app-web" --template="acropolis-web.service"
ynh_add_systemd_config --service="$app-sidekiq" --template="acropolis-sidekiq.service"
2021-11-15 20:16:45 +01:00
2022-07-15 05:14:36 +02:00
#=================================================
# UPGRADE ACROPOLIS
#=================================================
2021-11-15 20:16:45 +01:00
ynh_script_progression --message="Upgrading acropolis..."
2023-10-04 12:18:39 +02:00
pushd "$install_dir"
2022-07-15 15:44:56 +02:00
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle config deployment 'true'
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle config without 'development test'
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle install -j$(getconf _NPROCESSORS_ONLN)
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake assets:clean
2022-07-16 01:08:24 +02:00
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake assets:precompile
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake db:migrate
2021-11-15 20:16:45 +01:00
popd
2021-11-10 19:58:54 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
2021-11-10 19:58:54 +01:00
# 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..." --weight=1
2021-11-10 19:58:54 +01:00
2021-11-15 20:16:45 +01:00
yunohost service add "$app-web" --description="$app web service"
yunohost service add "$app-sidekiq" --description="$app sidekiq service"
2021-11-10 19:58:54 +01:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
2021-11-10 19:58:54 +01:00
2022-07-16 16:16:54 +02:00
ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="listening on"
ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Booted Rails"
2021-11-10 19:58:54 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2023-10-04 12:18:39 +02:00
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1
2021-11-10 19:58:54 +01:00
2023-10-04 12:18:39 +02:00
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
2021-11-10 19:58:54 +01:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last