2017-01-05 23:37:07 +01:00
#!/bin/bash
2023-12-09 00:35:51 +01:00
source _common.sh
2017-07-21 22:11:45 +02:00
source /usr/share/yunohost/helpers
2024-04-04 00:28:32 +02:00
load_vars
2017-07-21 22:11:45 +02:00
2024-04-04 00:28:32 +02:00
#=================================================
# MIGRATION 5 : Manage old settings
#=================================================
ensure_vars_set
2023-12-09 00:35:51 +01:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2024-08-31 01:07:34 +02:00
ynh_script_progression "Ensuring downward compatibility..."
2023-12-09 00:35:51 +01:00
# Fix issue on package deployement
test -e /etc/monitorix/conf.d/00-debian.conf || touch /etc/monitorix/conf.d/00-debian.conf
# Remove old hook if exist
2024-08-31 01:07:34 +02:00
ynh_safe_rm /usr/share/yunohost/hooks/post_iptable_rules/50-"$app"
2017-07-21 22:11:45 +02:00
2023-12-09 00:35:51 +01:00
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
2024-08-31 01:07:34 +02:00
ynh_script_progression "Stopping $app's systemd service..."
2019-06-07 23:09:30 +02:00
2024-08-31 01:07:34 +02:00
ynh_systemctl --service="$app" --action=stop
2017-01-05 23:37:07 +01:00
2023-12-09 00:35:51 +01:00
#=================================================
# "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2017-11-11 00:04:32 +01:00
2024-08-31 01:07:34 +02:00
# FIXME: this is still supported but the recommendation is now to *always* re-setup the app sources wether or not the upstream sources changed
if ynh_app_upstream_version_changed
2022-11-02 23:07:44 +01:00
then
2024-08-31 01:07:34 +02:00
ynh_script_progression "Upgrading source files..."
2023-12-09 00:35:51 +01:00
2024-04-04 00:28:32 +02:00
# Download, check integrity, uncompress and patch the source from manifest.toml
install_monitorix_package
2022-11-02 23:07:44 +01:00
fi
2023-12-09 00:35:51 +01:00
2024-08-31 01:07:34 +02:00
ynh_systemctl --service="$app" --action=stop --log_path=systemd --timeout=15
2024-04-04 00:28:32 +02:00
#=================================================
# MIGRATION 2
#=================================================
# Migrate log files
if [ ! -d /var/log/"${app}" ]; then
mkdir -p /var/log/new_"${app}"
mv -t /var/log/new_"${app}" /var/log/monitorix*
mv /var/log/new_"${app}" /var/log/"${app}"
fi
# Migrate data directory
if [ -e /var/lib/monitorix/system.rrd ] && [ ! -e "$data_dir"/system.rrd ] ; then
2024-04-04 08:28:16 +02:00
mv -f -t "$data_dir/" /var/lib/monitorix/*
2024-04-04 00:28:32 +02:00
fi
2018-01-13 21:31:48 +01:00
2018-01-31 16:07:43 +01:00
#=================================================
2023-12-09 00:35:51 +01:00
# REAPPLY SYSTEM CONFIGURATIONS
2018-01-31 16:07:43 +01:00
#=================================================
2024-08-31 01:07:34 +02:00
ynh_script_progression "Upgrading configurations related to $app..."
2018-01-31 16:07:43 +01:00
2024-08-31 01:07:34 +02:00
ynh_config_add --jinja --template=monitorix.conf --destination=/etc/monitorix/monitorix.conf
ynh_config_add --jinja --template=nginx_status.conf --destination="$nginx_status_conf"
2024-04-04 00:28:32 +02:00
if "$phpfpm_installed"; then
config_php_fpm
fi
2024-08-31 01:07:34 +02:00
ynh_config_add_nginx
ynh_config_add_systemd
2023-01-22 03:09:34 +01:00
2024-04-04 00:28:32 +02:00
yunohost service add "$app" --description=Monitorix --log=systemd
2017-01-05 23:37:07 +01:00
2024-08-31 01:07:34 +02:00
ynh_script_progression "Configuring databases access..."
2024-04-04 00:28:32 +02:00
configure_db
2024-08-31 01:07:34 +02:00
ynh_script_progression "Configuring php fpm access if needed..."
2024-04-04 00:28:32 +02:00
if "$phpfpm_installed"; then
config_php_fpm
fi
2017-01-05 23:37:07 +01:00
2024-04-04 00:28:32 +02:00
configure_hooks
configure_alerts_email
2018-04-30 21:41:07 +02:00
2018-01-31 16:07:43 +01:00
#=================================================
2024-08-31 01:07:34 +02:00
ynh_script_progression "Protecting directory..."
2023-12-09 00:35:51 +01:00
2018-01-29 18:57:10 +01:00
set_permission
2024-08-31 01:07:34 +02:00
ynh_config_add_logrotate "/var/log/$app"
2024-04-04 00:28:32 +02:00
2023-12-09 00:35:51 +01:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2024-08-31 01:07:34 +02:00
ynh_script_progression "Starting $app's systemd service..."
2023-12-09 00:35:51 +01:00
2024-08-31 01:07:34 +02:00
ynh_systemctl --service="$app" --action=restart --log_path=systemd --wait_until=' - Ok, ready.'
2024-04-04 22:42:20 +02:00
# when we change the value of 'listen [::1]:xxx;' nginx don't reload correctly the config, so force to restart to ensure that the new config are loaded
2024-08-31 01:07:34 +02:00
ynh_systemctl --service=nginx.service --action=restart
2024-04-04 00:28:32 +02:00
save_vars_current_value
2023-12-09 00:35:51 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2019-06-07 23:09:30 +02:00
2024-08-31 01:07:34 +02:00
ynh_script_progression "Upgrade of $app completed"