#!/bin/bash #================================================= # IMPORT GENERIC HELPERS #================================================= if [ ! -e _common.sh ]; then # Fetch helpers file if not in current directory cp ../settings/scripts/_common.sh ./_common.sh chmod a+rx _common.sh fi source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= app=$YNH_APP_INSTANCE_NAME # Source YunoHost helpers source /usr/share/yunohost/helpers # Retrieve old app settings domain=$(ynh_app_setting_get "$app" domain) path=$(ynh_app_setting_get "$app" path) # Fix permissions sudo chmod a+r ./conf_grafana/_common.sh # Source local helpers source ./conf_grafana/_common.sh SRCPATH=$(pwd) # Fix path if needed path=$(fix_path $path) # Check domain/path availability sudo yunohost app checkurl "${domain}${path}" -a "$app" \ || ynh_die "Path not available: ${domain}${path}" # Install dependencies install_dependencies # Create and restore Grafana database dbname=$app dbuser=$app dbpass=$(ynh_app_setting_get "$app" mysqlpwd) ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql # Restore InfluxDB data (only if backup not empty) # That happens when passing automated tests (NetData not present) sudo systemctl stop influxdb if [ "$(ls -A $SRCPATH/influxdb_data)" ] ; then sudo influxd restore -metadir /var/lib/influxdb/meta $SRCPATH/influxdb_data if [ "$(ls -A $SRCPATH/influxdb_data/opentsdb*)" ] ; then sudo influxd restore -database opentsdb -datadir /var/lib/influxdb/data $SRCPATH/influxdb_data fi fi # Restore configuration files sudo cp -a $SRCPATH/conf_influxdb/* /etc/influxdb sudo cp -a $SRCPATH/conf_grafana/* /etc/grafana [ "$(sudo ls -A $SRCPATH/conf_grafana_plugins)" ] && sudo cp -a $SRCPATH/conf_grafana_plugins/* /var/lib/grafana/plugins # Start InfluxDB server sudo systemctl start influxdb # Restart grafana server sudo systemctl restart grafana-server # Restart NetData if present sudo systemctl restart netdata || true # Restore NGINX configuration sudo cp -a $SRCPATH/nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf" # Restart webserver sudo systemctl reload nginx