2017-02-18 16:45:43 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
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+rx ./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}"
|
|
|
|
|
2017-03-12 12:40:26 +01:00
|
|
|
# Install dependencies
|
|
|
|
install_dependencies
|
2017-02-18 16:45:43 +01:00
|
|
|
|
|
|
|
# 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)
|
|
|
|
if [ "$(ls -A $SRCPATH/influxdb_data)" ] ; then
|
|
|
|
sudo influxd restore -metadir /var/lib/influxdb/meta $SRCPATH/influxdb_data
|
|
|
|
sudo influxd restore -database opentsdb -datadir /var/lib/influxdb/data $SRCPATH/influxdb_data
|
|
|
|
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
|
2017-03-12 12:40:26 +01:00
|
|
|
sudo systemctl reload nginx
|