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/remove

72 lines
1.9 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
# See comments in install script
app=$YNH_APP_INSTANCE_NAME
# Source local helpers
source ./_common.sh
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
# Stop services
sudo systemctl stop grafana-server
sudo systemctl stop influxdb
# Remove app dependencies
ynh_remove_app_dependencies || true
# If packages deinstalled (weren't installed priorly to package installation)
# purge remaining files
if [[ -n "$(dpkg-query --status grafana | grep -E "Status|deinstall")" ]] ; then
sudo dpkg --purge grafana
sudo rm $GRAFANA_REPOSITORY
fi
if [[ -n "$(dpkg-query --status influxdb | grep -E "Status|deinstall")" ]] ; then
sudo dpkg --purge influxdb
fi
# Remove services from YunoHost monitoring
sudo yunohost service remove influxdb
sudo yunohost service remove grafana-server
# If NetData is installed, configure it not to feed InfluxDB any more
netdata_conf="/opt/netdata/etc/netdata/netdata.conf"
if [[ -f "$netdata_conf" ]] ; then
sudo sed -i '/^\[backend\]$/,/^\[/ {
s/enabled = yes/# enabled = no/
s/type = opentsdb/# type = graphite/
s/destination = localhost:4242/# destination = localhost/
s/update every = 60/# update every = 10/
}' $netdata_conf
fi
# Remove nginx configuration file
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
sudo rm -rf /home/yunohost.app/$app
# Drop MySQL database and user
dbname=$app
dbuser=$app
ynh_mysql_drop_db "$dbname" || true
ynh_mysql_drop_user "$dbuser" || true
# Reload nginx service
sudo systemctl reload nginx