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
2020-05-17 09:28:22 +02:00
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
2023-12-04 20:38:08 +01:00
#ynh_script_progression --message="Validating restoration parameters..." --weight=1
#
# This old test doesn't seem to make sense in packaging v2 anymore, because at this stage the apt dependencies are already installed, so yes /etc/influxdb exists ...
# it's not clear what was really the intent
#test ! -d "/etc/influxdb" || ynh_die --message="InfluxDB/Grafana are already installed"
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
#=================================================
2021-08-22 16:17:29 +02:00
# RESTORE THE MYSQL DATABASE
#=================================================
2023-10-24 20:36:33 +02:00
ynh_script_progression --message="Restoring the MySQL database..." --weight=2
2021-08-22 16:17:29 +02:00
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
2023-10-24 23:41:41 +02:00
chown -R $app:$app "/var/lib/grafana/plugins"
2022-09-03 19:04:01 +02:00
fi
2022-03-27 10:45:52 +02:00
2020-05-17 09:28:22 +02:00
#=================================================
# RESTORE THE INFLUXDB DATABASE
#=================================================
ynh_script_progression --message="Restoring the InfluxDB database..." --weight=10
2023-10-24 20:36:33 +02:00
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
2023-10-24 20:25:42 +02:00
influxd restore -database opentsdb -data_dir /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