2017-02-18 16:45:43 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
2017-12-03 19:24:03 +01:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2021-08-22 16:17:29 +02:00
|
|
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
2020-05-17 09:28:22 +02:00
|
|
|
source ../settings/scripts/_common.sh
|
2017-12-03 19:24:03 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
ynh_clean_setup () {
|
2021-08-22 16:17:29 +02:00
|
|
|
ynh_clean_check_starting
|
2020-05-17 09:28:22 +02:00
|
|
|
}
|
2017-12-03 19:24:03 +01:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2020-06-13 09:34:16 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
2017-02-18 16:45:43 +01:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
|
|
db_user=$db_name
|
2017-02-18 16:45:43 +01:00
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Validating restoration parameters..." --weight=1
|
2017-02-18 16:45:43 +01:00
|
|
|
|
2022-09-04 10:46:18 +02:00
|
|
|
test ! -d $final_path \
|
|
|
|
|| ynh_die --message="There is already a directory: $final_path "
|
2017-02-18 16:45:43 +01:00
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
#=================================================
|
|
|
|
# STANDARD RESTORATION STEPS
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2021-08-22 16:17:29 +02:00
|
|
|
ynh_script_progression --message="Restoring the NGINX web server configuration..."
|
2017-02-18 16:45:43 +01:00
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
2017-02-18 16:45:43 +01:00
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORATION
|
|
|
|
#=================================================
|
|
|
|
# REINSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Reinstalling dependencies..." --weight=24
|
|
|
|
|
|
|
|
# Define and install dependencies
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
ynh_install_extra_app_dependencies --repo="deb https://packages.grafana.com/oss/deb stable main" --package="grafana" --key="https://packages.grafana.com/gpg.key"
|
|
|
|
|
|
|
|
#=================================================
|
2021-08-22 16:17:29 +02:00
|
|
|
# RESTORE THE MYSQL DATABASE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restoring the MySQL database..." --weight=2
|
|
|
|
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
|
|
|
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
|
|
|
|
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE VARIOUS FILES
|
2020-05-17 09:28:22 +02:00
|
|
|
#=================================================
|
2021-08-22 16:17:29 +02:00
|
|
|
ynh_script_progression --message="Restoring various files..." --weight=2
|
2017-02-18 16:45:43 +01:00
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/influxdb"
|
|
|
|
ynh_restore_file --origin_path="/etc/grafana"
|
2022-03-06 19:14:26 +01:00
|
|
|
ynh_restore_file --origin_path="/var/lib/grafana/plugins" --not_mandatory
|
2017-02-18 16:45:43 +01:00
|
|
|
|
2022-03-27 10:45:52 +02:00
|
|
|
# Set permission with the new grafana user (id could have been changed)
|
|
|
|
chown -R root:grafana "/etc/grafana"
|
2022-09-03 19:04:01 +02:00
|
|
|
if [ -d "/var/lib/grafana/plugins" ]; then
|
|
|
|
chown -R grafana:grafana "/var/lib/grafana/plugins"
|
|
|
|
fi
|
2022-03-27 10:45:52 +02:00
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE THE INFLUXDB DATABASE
|
|
|
|
#=================================================
|
2017-02-18 16:45:43 +01:00
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
ynh_script_progression --message="Restoring the InfluxDB database..." --weight=10
|
2017-02-18 16:45:43 +01:00
|
|
|
# Restore InfluxDB data (only if backup not empty)
|
|
|
|
# That happens when passing automated tests (NetData not present)
|
2020-05-17 09:28:22 +02:00
|
|
|
ynh_systemd_action --service_name=influxdb --action="stop"
|
|
|
|
if [ "$(ls -A ./influxdb_data)" ] ; then
|
|
|
|
influxd restore -metadir /var/lib/influxdb/meta ./influxdb_data
|
|
|
|
if [ "$(ls -A ./influxdb_data/opentsdb*)" ] ; then
|
|
|
|
influxd restore -database opentsdb -datadir /var/lib/influxdb/data ./influxdb_data
|
2019-01-13 18:51:59 +01:00
|
|
|
fi
|
2017-02-18 16:45:43 +01:00
|
|
|
fi
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2021-08-22 16:17:29 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
2020-05-17 09:28:22 +02:00
|
|
|
|
2020-12-11 22:33:52 +01:00
|
|
|
yunohost service add influxdb --description="open source time series database" --log="/var/log/grafana/grafana.log"
|
|
|
|
yunohost service add grafana-server --description="open source analytics and monitoring solution" --log="/var/log/grafana/grafana.log"
|
2020-05-17 09:28:22 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
2017-02-18 16:45:43 +01:00
|
|
|
|
2021-12-29 12:04:54 +01:00
|
|
|
# Enable the systemd service so that InfluxDB and Grafana start at boot
|
|
|
|
systemctl enable influxdb.service --quiet
|
|
|
|
systemctl enable grafana-server.service --quiet
|
|
|
|
|
2022-02-06 19:08:44 +01:00
|
|
|
systemctl daemon-reload
|
2020-05-17 09:28:22 +02:00
|
|
|
ynh_systemd_action --service_name=influxdb --action="start"
|
2021-12-29 12:04:54 +01:00
|
|
|
ynh_systemd_action --service_name=grafana-server --action="start" --log_path="/var/log/grafana/grafana.log" --line_match="HTTP Server Listen" --timeout=600
|
2020-05-17 09:28:22 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX AND PHP-FPM
|
|
|
|
#=================================================
|
2021-08-03 08:02:26 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
2017-02-18 16:45:43 +01:00
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2017-02-18 16:45:43 +01:00
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2017-02-18 16:45:43 +01:00
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|