1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/grafana_ynh.git synced 2024-09-03 20:36:29 +02:00
grafana_ynh/scripts/restore

137 lines
5.5 KiB
Text
Raw Normal View History

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
#=================================================
2023-10-24 20:25:42 +02:00
#REMOVEME? 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
2023-10-24 20:25:42 +02:00
#REMOVEME? ynh_abort_if_errors
2017-12-03 19:24:03 +01:00
#=================================================
# LOAD SETTINGS
#=================================================
2023-10-24 20:25:42 +02:00
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
2017-02-18 16:45:43 +01:00
2023-10-24 20:25:42 +02:00
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
2017-02-18 16:45:43 +01:00
2023-10-24 20:25:42 +02:00
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path)
#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#REMOVEME? 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
#=================================================
2023-10-24 20:25:42 +02:00
#REMOVEME? ynh_script_progression --message="Validating restoration parameters..." --weight=1
2017-02-18 16:45:43 +01:00
2022-09-04 14:19:10 +02:00
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
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
2023-10-24 20:25:42 +02:00
#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." --weight=24
2020-05-17 09:28:22 +02:00
# Define and install dependencies
2023-10-24 20:25:42 +02:00
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
#REMOVEME? ynh_install_extra_app_dependencies --repo="deb https://packages.grafana.com/oss/deb stable main" --package="grafana" --key="https://packages.grafana.com/gpg.key"
2020-05-17 09:28:22 +02:00
#=================================================
2021-08-22 16:17:29 +02:00
# RESTORE THE MYSQL DATABASE
#=================================================
2023-10-24 20:25:42 +02:00
#REMOVEME? ynh_script_progression --message="Restoring the MySQL database..." --weight=2
2021-08-22 16:17:29 +02:00
2023-10-24 20:25:42 +02:00
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
#REMOVEME? ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
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
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
2023-10-24 20:25:42 +02:00
influxd restore -database opentsdb -data_dir /var/lib/influxdb/data ./influxdb_data
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