peertube-search-index_ynh/scripts/upgrade

182 lines
6.2 KiB
Text
Raw Normal View History

2020-10-31 14:18:46 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
2021-02-17 20:38:04 +01:00
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
2020-10-31 14:18:46 +01:00
2021-02-17 20:38:04 +01:00
ynh_app_setting_delete --app=$app --key=is_public
2020-10-31 14:18:46 +01:00
fi
#=================================================
2021-04-10 19:17:43 +02:00
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
2020-10-31 14:18:46 +01:00
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
2021-04-09 23:48:21 +02:00
# Restore it if the upgrade fails
2020-10-31 14:18:46 +01:00
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped $app search index daemon"
2021-04-09 23:48:21 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
2020-10-31 14:18:46 +01:00
#=================================================
# 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
2020-10-31 14:33:19 +01:00
pushd "$final_path"
2020-10-31 20:28:37 +01:00
git checkout master
git pull --quiet
git checkout $COMMIT --quiet
2020-10-31 14:33:19 +01:00
popd
2020-10-31 14:18:46 +01:00
fi
2021-04-17 18:31:51 +02:00
chmod 750 "$final_path"
2021-04-09 23:48:21 +02:00
chmod -R o-rwx "$final_path"
2021-04-11 20:47:47 +02:00
chown -R $app:$app "$final_path"
2021-04-09 23:48:21 +02:00
2020-10-31 14:18:46 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2021-04-09 23:48:21 +02:00
ynh_script_progression --message="Upgrading NGINX web server configuration..."
2020-10-31 14:18:46 +01:00
2021-04-09 23:48:21 +02:00
# Create a dedicated NGINX config
2020-10-31 14:18:46 +01:00
ynh_add_nginx_config "port"
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..."
ynh_install_app_dependencies $pkg_dependencies
ynh_install_extra_app_dependencies --repo="deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" --package="$extra_pkg_dependencies" --key="https://artifacts.elastic.co/GPG-KEY-elasticsearch"
systemctl enable elasticsearch.service --quiet
2020-11-01 11:56:46 +01:00
systemctl start elasticsearch.service
2020-10-31 14:18:46 +01:00
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
#=================================================
# SPECIFIC UPGRADE
#=================================================
# BUILDING
#=================================================
ynh_script_progression --message="Building..."
pushd "$final_path"
git submodule update --init --recursive
ynh_use_nodejs
yarn install --pure-lockfile
$ynh_npm run build
popd
#=================================================
2021-04-09 23:48:21 +02:00
# UPDATE A CONFIG FILE
2020-10-31 14:18:46 +01:00
#=================================================
2021-04-09 23:48:21 +02:00
ynh_script_progression --message="Updating a config file..."
2020-10-31 14:18:46 +01:00
2021-02-26 21:40:29 +01:00
ynh_add_config --template="../conf/default.yaml" --destination="$final_path/config/production.yaml"
2020-10-31 14:18:46 +01:00
2021-04-10 01:57:11 +02:00
chmod 400 "$final_path/config/production.yaml"
chown $app:$app "$final_path/config/production.yaml"
2021-04-09 23:48:21 +02:00
2021-04-11 20:47:47 +02:00
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..."
# Create a dedicated systemd config
ynh_add_systemd_config --others_var="ynh_npm"
2020-10-31 14:18:46 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..."
# 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..."
yunohost service add $app --description="$app search index daemon"
2020-10-31 14:18:46 +01:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server listening on port"
#=================================================
# RELOAD NGINX
#=================================================
2021-04-09 23:48:21 +02:00
ynh_script_progression --message="Reloading NGINX web server..."
2020-10-31 14:18:46 +01:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed"