mirror of
https://github.com/YunoHost-Apps/grafana_ynh.git
synced 2024-09-03 20:36:29 +02:00
Refactoring and cleaning, levels 4 & 5 validation
This commit is contained in:
parent
5a89c5fe6f
commit
cc61abbecc
8 changed files with 101 additions and 88 deletions
|
@ -26,8 +26,10 @@
|
||||||
Level 1=auto
|
Level 1=auto
|
||||||
Level 2=auto
|
Level 2=auto
|
||||||
Level 3=auto
|
Level 3=auto
|
||||||
Level 4=0
|
# https://github.com/YunoHost-Apps/grafana_ynh/issues/4
|
||||||
Level 5=0
|
Level 4=1
|
||||||
|
# https://github.com/YunoHost-Apps/grafana_ynh/issues/5
|
||||||
|
Level 5=1
|
||||||
Level 6=auto
|
Level 6=auto
|
||||||
Level 7=auto
|
Level 7=auto
|
||||||
Level 8=0
|
Level 8=0
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
Section: misc
|
|
||||||
Priority: optional
|
|
||||||
Homepage: http://grafana.org/
|
|
||||||
Standards-Version: 3.9.2
|
|
||||||
|
|
||||||
Package: influxdb-grafana-deps
|
|
||||||
Version: 4.1.1-1
|
|
||||||
Depends: influxdb, grafana
|
|
||||||
Architecture: all
|
|
||||||
Description: meta package for InfluxDB/Grafana dependencies
|
|
||||||
.
|
|
||||||
This meta-package is only responsible of installing dependencies.
|
|
|
@ -6,6 +6,7 @@
|
||||||
"en": "Beautiful metric & analytic dashboards for monitoring",
|
"en": "Beautiful metric & analytic dashboards for monitoring",
|
||||||
"fr": "Tableaux de bords de supervision"
|
"fr": "Tableaux de bords de supervision"
|
||||||
},
|
},
|
||||||
|
"version": "1.0.0",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"url": "http://grafana.org/",
|
"url": "http://grafana.org/",
|
||||||
"maintainer": {
|
"maintainer": {
|
||||||
|
|
|
@ -20,4 +20,86 @@ fix_path() {
|
||||||
path="${path:0:${#path}-1}"
|
path="${path:0:${#path}-1}"
|
||||||
fi
|
fi
|
||||||
echo "$path"
|
echo "$path"
|
||||||
|
}
|
||||||
|
# Install needed repositories and install dependencies
|
||||||
|
# usage: install_dependencies
|
||||||
|
install_dependencies() {
|
||||||
|
# Install needed dependency for HTTPS apt access
|
||||||
|
# (that dependency could be handled upstream in YunoHost)
|
||||||
|
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
|
||||||
|
# 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
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Install packages
|
||||||
|
# We install them as dependencies as they may already be installed and used for other purposes
|
||||||
|
ynh_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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# ======== Future YunoHost helpers ========
|
||||||
|
# Install dependencies with a equivs control file
|
||||||
|
#
|
||||||
|
# usage: ynh_app_dependencies dep [dep [...]]
|
||||||
|
# | arg: dep - the package name to install in dependence
|
||||||
|
ynh_app_dependencies () {
|
||||||
|
dependencies=$@
|
||||||
|
manifest_path="../manifest.json"
|
||||||
|
if [ ! -e "$manifest_path" ]; then
|
||||||
|
manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
|
||||||
|
fi
|
||||||
|
version=$(sudo python3 -c "import sys, json;print(json.load(open(\"$manifest_path\"))['version'])") # Retrieve the version number in the manifest file.
|
||||||
|
dep_app=${app//_/-} # Replace all '_' by '-'
|
||||||
|
cat > ./${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build
|
||||||
|
Section: misc
|
||||||
|
Priority: optional
|
||||||
|
Package: ${dep_app}-ynh-deps
|
||||||
|
Version: ${version}
|
||||||
|
Depends: ${dependencies// /, }
|
||||||
|
Architecture: all
|
||||||
|
Description: Fake package for ${app} (YunoHost app) dependencies
|
||||||
|
This meta-package is only responsible of installing its dependencies.
|
||||||
|
EOF
|
||||||
|
ynh_package_install_from_equivs ./${dep_app}-ynh-deps.control \
|
||||||
|
|| ynh_die "Unable to install dependencies" # Install the fake package and its dependencies
|
||||||
|
}
|
||||||
|
|
||||||
|
# Remove fake package and its dependencies
|
||||||
|
#
|
||||||
|
# Dependencies will removed only if no other package need them.
|
||||||
|
#
|
||||||
|
# usage: ynh_remove_app_dependencies
|
||||||
|
ynh_remove_app_dependencies () {
|
||||||
|
dep_app=${app//_/-} # Replace all '_' by '-'
|
||||||
|
ynh_package_autoremove ${dep_app}-ynh-deps # Remove the fake package and its dependencies if they not still used.
|
||||||
}
|
}
|
|
@ -30,46 +30,9 @@ sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
||||||
ynh_app_setting_set "$app" admin "$admin"
|
ynh_app_setting_set "$app" admin "$admin"
|
||||||
ynh_app_setting_set "$app" is_public "$is_public"
|
ynh_app_setting_set "$app" is_public "$is_public"
|
||||||
|
|
||||||
# Install needed dependency for HTTPS apt access
|
# Install dependencies
|
||||||
# (that dependency could be handled upstream in YunoHost)
|
install_dependencies
|
||||||
ynh_package_install apt-transport-https
|
|
||||||
|
|
||||||
# Test repository 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
|
|
||||||
# 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
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Install packages
|
|
||||||
# We install them as dependencies as they may already be installed and used for other purposes
|
|
||||||
ynh_package_install_from_equivs ../conf/influxdb-grafana-deps.control \
|
|
||||||
|| {
|
|
||||||
# Remove apt repositories if they were added
|
|
||||||
[[ -n "$influxdb_repository_present" ]] && rm $INFLUXDB_REPOSITORY
|
|
||||||
[[ -n "$grafana_repository_present" ]] && rm $GRAFANA_REPOSITORY
|
|
||||||
ynh_die "Unable to install Debian packages"
|
|
||||||
}
|
|
||||||
# If NetData is installed, configure it to feed InfluxDB
|
# If NetData is installed, configure it to feed InfluxDB
|
||||||
netdata_conf="/opt/netdata/etc/netdata/netdata.conf"
|
netdata_conf="/opt/netdata/etc/netdata/netdata.conf"
|
||||||
if [[ -f "$netdata_conf" ]] ; then
|
if [[ -f "$netdata_conf" ]] ; then
|
||||||
|
@ -166,7 +129,6 @@ sudo systemctl enable grafana-server.service
|
||||||
|
|
||||||
# Store useful files for backup/restore scripts
|
# Store useful files for backup/restore scripts
|
||||||
sudo cp _common.sh /etc/grafana
|
sudo cp _common.sh /etc/grafana
|
||||||
sudo cp ../conf/influxdb-grafana-deps.control /etc/grafana
|
|
||||||
|
|
||||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||||
if [[ "$path" == "/" ]] ; then
|
if [[ "$path" == "/" ]] ; then
|
||||||
|
@ -185,4 +147,4 @@ if [[ $is_public -eq 1 ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Reload services
|
# Reload services
|
||||||
sudo service nginx reload
|
sudo systemctl reload nginx
|
||||||
|
|
|
@ -6,6 +6,9 @@ set -u
|
||||||
# See comments in install script
|
# See comments in install script
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
|
# Source local helpers
|
||||||
|
source ./_common.sh
|
||||||
|
|
||||||
# Source YunoHost helpers
|
# Source YunoHost helpers
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
@ -17,7 +20,10 @@ sudo systemctl stop grafana-server
|
||||||
sudo systemctl stop influxdb
|
sudo systemctl stop influxdb
|
||||||
|
|
||||||
# Remove app dependencies
|
# Remove app dependencies
|
||||||
|
ynh_remove_app_dependencies || true
|
||||||
|
# We keep this second removal for backward compatibility
|
||||||
ynh_package_autoremove "influxdb-grafana-deps" || true
|
ynh_package_autoremove "influxdb-grafana-deps" || true
|
||||||
|
|
||||||
# If packages deinstalled (weren't installed priorly to package installation)
|
# If packages deinstalled (weren't installed priorly to package installation)
|
||||||
# purge remaining files
|
# purge remaining files
|
||||||
if [[ -n "$(dpkg-query --status grafana | grep -E "Status|deinstall")" ]] ; then
|
if [[ -n "$(dpkg-query --status grafana | grep -E "Status|deinstall")" ]] ; then
|
||||||
|
@ -52,6 +58,6 @@ ynh_mysql_drop_user "$dbuser" || true
|
||||||
|
|
||||||
|
|
||||||
# Reload nginx service
|
# Reload nginx service
|
||||||
sudo service nginx reload
|
sudo systemctl reload nginx
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ path=$(ynh_app_setting_get "$app" path)
|
||||||
|
|
||||||
# Fix permissions
|
# Fix permissions
|
||||||
sudo chmod a+rx ./conf_grafana/_common.sh
|
sudo chmod a+rx ./conf_grafana/_common.sh
|
||||||
sudo chmod a+r ./conf_grafana/influxdb-grafana-deps.control
|
|
||||||
|
|
||||||
# Source local helpers
|
# Source local helpers
|
||||||
source ./conf_grafana/_common.sh
|
source ./conf_grafana/_common.sh
|
||||||
|
@ -27,35 +26,8 @@ path=$(fix_path $path)
|
||||||
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
||||||
|| ynh_die "Path not available: ${domain}${path}"
|
|| ynh_die "Path not available: ${domain}${path}"
|
||||||
|
|
||||||
# Install needed dependency for HTTPS apt access
|
# Install dependencies
|
||||||
# (that dependency could be handled upstream in YunoHost)
|
install_dependencies
|
||||||
ynh_package_install apt-transport-https
|
|
||||||
|
|
||||||
# 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
|
|
||||||
# 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
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Install packages
|
|
||||||
# We install them as dependencies as they may already be installed and used for other purposes
|
|
||||||
ynh_package_install_from_equivs ./conf_grafana/influxdb-grafana-deps.control \
|
|
||||||
|| ynh_die "Unable to install Debian packages"
|
|
||||||
|
|
||||||
# Create and restore Grafana database
|
# Create and restore Grafana database
|
||||||
dbname=$app
|
dbname=$app
|
||||||
|
@ -88,4 +60,4 @@ sudo systemctl restart netdata || true
|
||||||
sudo cp -a $SRCPATH/nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
sudo cp -a $SRCPATH/nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||||
|
|
||||||
# Restart webserver
|
# Restart webserver
|
||||||
sudo service nginx reload
|
sudo systemctl reload nginx
|
||||||
|
|
|
@ -42,4 +42,4 @@ if [[ $is_public -eq 1 ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Reload nginx service
|
# Reload nginx service
|
||||||
sudo service nginx reload
|
sudo systemctl reload nginx
|
Loading…
Add table
Reference in a new issue