mirror of
https://github.com/YunoHost-Apps/grafana_ynh.git
synced 2024-09-03 20:36:29 +02:00
Use Debian influxdb package and adapt to new Grafana APT repositories (including official ARMv7 package) (#17)
This commit is contained in:
parent
cf9d6789c0
commit
5a2de2c4d1
8 changed files with 92 additions and 42 deletions
|
@ -16,13 +16,9 @@
|
|||
upgrade=1
|
||||
backup_restore=1
|
||||
multi_instance=0
|
||||
wrong_user=0
|
||||
wrong_path=1
|
||||
incorrect_path=1
|
||||
corrupt_source=0
|
||||
fail_download_source=0
|
||||
port_already_use=1
|
||||
final_path_already_use=0
|
||||
change_url=0
|
||||
;;; Levels
|
||||
Level 1=auto
|
||||
Level 2=auto
|
||||
|
@ -36,3 +32,6 @@
|
|||
Level 8=0
|
||||
Level 9=0
|
||||
Level 10=0
|
||||
;;; Options
|
||||
Email=
|
||||
Notification=none
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"en": "Beautiful metric & analytic dashboards for monitoring",
|
||||
"fr": "Tableaux de bords de supervision"
|
||||
},
|
||||
"version": "1.1.0~ynh1",
|
||||
"version": "1.2.0~ynh1",
|
||||
"license": "Apache-2.0",
|
||||
"url": "http://grafana.org/",
|
||||
"maintainer": {
|
||||
|
@ -15,12 +15,12 @@
|
|||
"url": ""
|
||||
},
|
||||
"requirements": {
|
||||
"yunohost": ">= 2.7.2"
|
||||
"yunohost": ">= 3.0.0"
|
||||
},
|
||||
"multi_instance": false,
|
||||
"services": [
|
||||
"nginx",
|
||||
"php5-fpm"
|
||||
"php7.0-fpm"
|
||||
],
|
||||
"arguments": {
|
||||
"install" : [
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#
|
||||
# Common variables
|
||||
#
|
||||
INFLUXDB_REPOSITORY="/etc/apt/sources.list.d/influxdb.list"
|
||||
GRAFANA_REPOSITORY="/etc/apt/sources.list.d/grafana_stable.list"
|
||||
|
||||
#
|
||||
|
@ -29,30 +28,22 @@ install_dependencies() {
|
|||
ynh_package_install apt-transport-https
|
||||
|
||||
# Test repositories existence, in case of failed installation
|
||||
influxdb_repository_present=""
|
||||
grafana_repository_present=""
|
||||
[[ -f $INFLUXDB_REPOSITORY ]] && influxdb_repository_present="true"
|
||||
[[ -f $GRAFANA_REPOSITORY ]] && grafana_repository_present="true"
|
||||
|
||||
# Install needed apt repository for InfluxDB
|
||||
curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
|
||||
source /etc/os-release
|
||||
test $VERSION_ID = "8" && echo "deb https://repos.influxdata.com/debian jessie stable" | sudo tee $INFLUXDB_REPOSITORY
|
||||
|
||||
# Install needed apt repository for Grafana
|
||||
machine=$(uname -m)
|
||||
# Add the repos depending on processor architecture
|
||||
if [[ "$machine" =~ "x86" ]]; then
|
||||
# x86 processor --> we use the official repository
|
||||
curl -s https://packagecloud.io/install/repositories/grafana/stable/script.deb.sh | sudo bash
|
||||
elif [[ "$machine" =~ "armv6" ]] ; then
|
||||
|
||||
if [[ "$machine" =~ "armv6" ]] ; then
|
||||
# For ARM, use fg2it repository
|
||||
# https://github.com/fg2it/grafana-on-raspberry
|
||||
curl https://bintray.com/user/downloadSubjectPublicKey?username=bintray | sudo apt-key add -
|
||||
echo "deb http://dl.bintray.com/fg2it/deb-rpi-1b jessie main" | sudo tee $GRAFANA_REPOSITORY
|
||||
elif [[ "$machine" =~ "armv7" ]] ; then
|
||||
curl https://bintray.com/user/downloadSubjectPublicKey?username=bintray | sudo apt-key add -
|
||||
echo "deb http://dl.bintray.com/fg2it/deb jessie main" | sudo tee $GRAFANA_REPOSITORY
|
||||
echo "deb http://dl.bintray.com/fg2it/deb-rpi-1b stretch main" | sudo tee $GRAFANA_REPOSITORY
|
||||
else
|
||||
# x86 processor --> we use the official repository
|
||||
curl https://packages.grafana.com/gpg.key | sudo apt-key add -
|
||||
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee $GRAFANA_REPOSITORY
|
||||
fi
|
||||
|
||||
# Install packages
|
||||
|
@ -60,7 +51,6 @@ install_dependencies() {
|
|||
ynh_install_app_dependencies influxdb, grafana \
|
||||
|| {
|
||||
# Remove apt repositories if they were added
|
||||
[[ -n "$influxdb_repository_present" ]] && sudo rm $INFLUXDB_REPOSITORY
|
||||
[[ -n "$grafana_repository_present" ]] && sudo rm $GRAFANA_REPOSITORY
|
||||
ynh_die "Unable to install Debian packages"
|
||||
}
|
||||
|
@ -78,3 +68,64 @@ ynh_delete_file_checksum () {
|
|||
local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_'
|
||||
ynh_app_setting_delete $app $checksum_setting_name
|
||||
}
|
||||
|
||||
# Start or restart a service and follow its booting
|
||||
#
|
||||
# usage: ynh_check_starting "Line to match" [Log file] [Timeout] [Service name]
|
||||
#
|
||||
# | arg: Line to match - The line to find in the log to attest the service have finished to boot.
|
||||
# | arg: Log file - The log file to watch; specify "systemd" to read systemd journal for specified service
|
||||
# /var/log/$app/$app.log will be used if no other log is defined.
|
||||
# | arg: Timeout - The maximum time to wait before ending the watching. Defaut 300 seconds.
|
||||
# | arg: Service name
|
||||
ynh_check_starting () {
|
||||
local line_to_match="$1"
|
||||
local service_name="${4:-$app}"
|
||||
local app_log="${2:-/var/log/$service_name/$service_name.log}"
|
||||
local timeout=${3:-300}
|
||||
|
||||
echo "Starting of $service_name" >&2
|
||||
systemctl stop $service_name
|
||||
local templog="$(mktemp)"
|
||||
# Following the starting of the app in its log
|
||||
if [ "$app_log" == "systemd" ] ; then
|
||||
# Read the systemd journal
|
||||
journalctl -u $service_name -f --since=-45 > "$templog" &
|
||||
else
|
||||
# Read the specified log file
|
||||
tail -F -n0 "$app_log" > "$templog" &
|
||||
fi
|
||||
# Get the PID of the last command
|
||||
local pid_tail=$!
|
||||
systemctl start $service_name
|
||||
|
||||
local i=0
|
||||
for i in `seq 1 $timeout`
|
||||
do
|
||||
# Read the log until the sentence is found, which means the app finished starting. Or run until the timeout.
|
||||
if grep --quiet "$line_to_match" "$templog"
|
||||
then
|
||||
echo "The service $service_name has correctly started." >&2
|
||||
break
|
||||
fi
|
||||
echo -n "." >&2
|
||||
sleep 1
|
||||
done
|
||||
if [ $i -eq $timeout ]
|
||||
then
|
||||
echo "The service $service_name didn't fully start before the timeout." >&2
|
||||
fi
|
||||
|
||||
echo ""
|
||||
ynh_clean_check_starting
|
||||
}
|
||||
# Clean temporary process and file used by ynh_check_starting
|
||||
# (usually used in ynh_clean_setup scripts)
|
||||
#
|
||||
# usage: ynh_clean_check_starting
|
||||
|
||||
ynh_clean_check_starting () {
|
||||
# Stop the execution of tail.
|
||||
kill -s 15 $pid_tail 2>&1
|
||||
ynh_secure_remove "$templog" 2>&1
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ ynh_backup "/var/lib/grafana/plugins" "conf_grafana_plugins"
|
|||
# Backup InfluxDB data
|
||||
# Source: http://stackoverflow.com/questions/39501416/how-to-restore-data-base-using-influxd
|
||||
TMPDIR=$(mktemp -d)
|
||||
influx -database opentsdb -execute "show series" && sudo influxd backup -database opentsdb $TMPDIR
|
||||
influxd backup -database opentsdb $TMPDIR
|
||||
ynh_backup "$TMPDIR" "influxdb_data"
|
||||
|
||||
# Dump the Grafana database
|
||||
|
|
|
@ -100,8 +100,10 @@ sudo cp ../conf/ldap.toml /etc/grafana
|
|||
grafana_conf="/etc/grafana/grafana.ini"
|
||||
# Set final port
|
||||
sudo sed -i "/^\[server\]$/,/^\[/ s@;http_port = .*@http_port = $port@" $grafana_conf
|
||||
# Set domain
|
||||
sudo sed -i "/^\[server\]$/,/^\[/ s@;domain = .*@domain = $domain@" $grafana_conf
|
||||
# Set final URL
|
||||
sudo sed -i "/^\[server\]$/,/^\[/ s@;root_url = .*@root_url = https://$domain$path@" $grafana_conf
|
||||
sudo sed -i "/^\[server\]$/,/^\[/ s@;root_url = .*@root_url = %(protocol)s://%(domain)s$path@" $grafana_conf
|
||||
# Disable check for updates
|
||||
sudo sed -i '/^\[analytics\]$/,/^\[/ s/;check_for_updates = .*/check_for_updates = false/' $grafana_conf
|
||||
# Disable organization creation
|
||||
|
@ -124,13 +126,8 @@ sudo sed -i "/^\[database\]$/,/^\[/ {
|
|||
s/;\?password =.*/password = $dbpass/
|
||||
}" $grafana_conf
|
||||
|
||||
# Restart grafana server
|
||||
sudo systemctl restart grafana-server
|
||||
|
||||
# Wait for Grafana to start and initialize database
|
||||
while [ -z "$(sudo netstat -lnput|grep grafana)" ] ; do
|
||||
sleep 5s
|
||||
done
|
||||
# Start Grafana and wait for it to be fully started
|
||||
ynh_check_starting "HTTP Server Listen" "/var/log/grafana/grafana.log" "240" "grafana-server"
|
||||
|
||||
# Change admin name to the specified one
|
||||
mail=$(ynh_user_get_info "$admin" 'mail')
|
||||
|
@ -168,5 +165,8 @@ if [[ $is_public -eq 1 ]]; then
|
|||
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||
fi
|
||||
|
||||
# Start Grafana and wait for it to be fully started
|
||||
ynh_check_starting "HTTP Server Listen" "/var/log/grafana/grafana.log" "240" "grafana-server"
|
||||
|
||||
# Reload services
|
||||
sudo systemctl reload nginx
|
||||
|
|
|
@ -31,18 +31,15 @@ sudo systemctl stop influxdb
|
|||
|
||||
# Remove app dependencies
|
||||
ynh_remove_app_dependencies || true
|
||||
# We keep this second removal for backward compatibility
|
||||
ynh_package_autoremove "influxdb-grafana-deps" || 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 /etc/apt/sources.list.d/grafana_stable.list
|
||||
sudo rm $GRAFANA_REPOSITORY
|
||||
fi
|
||||
if [[ -n "$(dpkg-query --status influxdb | grep -E "Status|deinstall")" ]] ; then
|
||||
sudo dpkg --purge influxdb
|
||||
sudo rm /etc/apt/sources.list.d/influxdb.list
|
||||
fi
|
||||
|
||||
# Remove services from YunoHost monitoring
|
||||
|
@ -56,7 +53,7 @@ if [[ -f "$netdata_conf" ]] ; then
|
|||
s/enabled = yes/# enabled = no/
|
||||
s/type = opentsdb/# type = graphite/
|
||||
s/destination = localhost:4242/# destination = localhost/
|
||||
s/update every = 60/# update every = 10/
|
||||
s/update every = 60/# update every = 10/
|
||||
}' $netdata_conf
|
||||
fi
|
||||
|
||||
|
@ -73,5 +70,3 @@ ynh_mysql_drop_user "$dbuser" || true
|
|||
|
||||
# Reload nginx service
|
||||
sudo systemctl reload nginx
|
||||
|
||||
|
||||
|
|
|
@ -60,7 +60,9 @@ ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql
|
|||
# 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
|
||||
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
|
||||
|
|
|
@ -51,6 +51,9 @@ sudo systemctl restart grafana-server
|
|||
sudo yunohost service add influxdb
|
||||
sudo yunohost service add grafana-server --log "/var/log/grafana/grafana.log"
|
||||
|
||||
# Upgrade dependencies if needed
|
||||
install_dependencies
|
||||
|
||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||
if [[ "$path" == "/" ]] ; then
|
||||
nginx_conf=$SRCPATH/../conf/nginx_root.conf
|
||||
|
|
Loading…
Reference in a new issue