mirror of
https://github.com/YunoHost-Apps/netdata_ynh.git
synced 2024-09-03 19:46:33 +02:00
Refactor, use latest YunoHost 2.7.2 standards
This commit is contained in:
parent
3f12eab1dd
commit
0478e79ea8
13 changed files with 419 additions and 299 deletions
75
README.md
75
README.md
|
@ -1,6 +1,9 @@
|
|||
NetData for YunoHost
|
||||
---------------------
|
||||
|
||||
[](https://install-app.yunohost.org/?app=piwigo)
|
||||
[](https://ci-apps.yunohost.org/jenkins/job/piwigo%20%28Community%29/lastBuild/consoleFull)
|
||||
|
||||
|
||||
[NetData](http://my-netdata.io/) is a system for **distributed real-time performance and health monitoring**.
|
||||
It provides **unparalleled insights, in real-time**, of everything happening on the
|
||||
|
@ -37,47 +40,52 @@ It has been tested on x86_64 and ARM.
|
|||
|
||||
- **Stunning interactive bootstrap dashboards**<br/>
|
||||
mouse and touch friendly, in 2 themes: dark, light
|
||||
|
||||
|
||||
- **Amazingly fast**<br/>
|
||||
responds to all queries in less than 0.5 ms per metric,
|
||||
even on low-end hardware
|
||||
|
||||
|
||||
- **Highly efficient**<br/>
|
||||
collects thousands of metrics per server per second,
|
||||
with just 1% CPU utilization of a single core, a few MB of RAM and no disk I/O at all
|
||||
|
||||
|
||||
- **Sophisticated alarming**<br/>
|
||||
hundreds of alarms, **out of the box**!<br/>
|
||||
supports dynamic thresholds, hysteresis, alarm templates,
|
||||
multiple role-based notification methods (such as email, slack.com,
|
||||
pushover.net, pushbullet.com telegram.org, twilio.com, messagebird.com)
|
||||
|
||||
pushover.net, pushbullet.com, telegram.org, twilio.com, messagebird.com)
|
||||
|
||||
- **Extensible**<br/>
|
||||
you can monitor anything you can get a metric for,
|
||||
using its Plugin API (anything can be a netdata plugin,
|
||||
BASH, python, perl, node.js, java, Go, ruby, etc)
|
||||
|
||||
|
||||
- **Embeddable**<br/>
|
||||
it can run anywhere a Linux kernel runs (even IoT)
|
||||
and its charts can be embedded on your web pages too
|
||||
|
||||
|
||||
- **Customizable**<br/>
|
||||
custom dashboards can be built using simple HTML (no javascript necessary)
|
||||
|
||||
|
||||
- **Zero configuration**<br/>
|
||||
auto-detects everything, it can collect up to 5000 metrics
|
||||
per server out of the box
|
||||
|
||||
|
||||
- **Zero dependencies**<br/>
|
||||
it is even its own web server, for its static web files and its web API
|
||||
|
||||
|
||||
- **Zero maintenance**<br/>
|
||||
you just run it, it does the rest
|
||||
|
||||
|
||||
- **scales to infinity**<br/>
|
||||
requiring minimal central resources
|
||||
|
||||
- **back-ends supported**<br/>
|
||||
can archive its metrics on `graphite` or `opentsdb`, in the same or lower detail
|
||||
|
||||
- **several operating modes**<br/>
|
||||
autonomous host monitoring, headless data collector, forwarding proxy, store and forward proxy, central multi-host monitoring, in all possible configurations.
|
||||
Each node may have different metrics retention policy and run with or without health monitoring.
|
||||
|
||||
- **time-series back-ends supported**<br/>
|
||||
can archive its metrics on `graphite`, `opentsdb`, `prometheus`, json document DBs, in the same or lower detail
|
||||
(lower: to prevent it from congesting these servers due to the amount of data collected)
|
||||
|
||||

|
||||
|
@ -86,7 +94,7 @@ It has been tested on x86_64 and ARM.
|
|||
|
||||
## What does it monitor?
|
||||
|
||||
netdata monitors several thousands of metrics per device.
|
||||
netdata collects several thousands of metrics per device.
|
||||
All these metrics are collected and visualized in real-time.
|
||||
|
||||
> _Almost all metrics are auto-detected, without any configuration._
|
||||
|
@ -94,13 +102,13 @@ All these metrics are collected and visualized in real-time.
|
|||
This is a list of what it currently monitors:
|
||||
|
||||
- **CPU**<br/>
|
||||
usage, interrupts, softirqs, frequency, total and per core
|
||||
usage, interrupts, softirqs, frequency, total and per core, CPU states
|
||||
|
||||
- **Memory**<br/>
|
||||
RAM, swap and kernel memory usage, KSM (Kernel Samepage Merging), NUMA
|
||||
|
||||
- **Disks**<br/>
|
||||
per disk: I/O, operations, backlog, utilization, space
|
||||
per disk: I/O, operations, backlog, utilization, space, software RAID (md)
|
||||
|
||||

|
||||
|
||||
|
@ -176,6 +184,9 @@ This is a list of what it currently monitors:
|
|||
- **Tomcat**<br/>
|
||||
accesses, threads, free memory, volume
|
||||
|
||||
- **web server log files**<br/>
|
||||
extracting in real-time, web server performance metrics and applying several health checks
|
||||
|
||||
- **mySQL databases**<br/>
|
||||
multiple servers, each showing: bandwidth, queries/s, handlers, locks, issues,
|
||||
tmp operations, connections, binlog metrics, threads, innodb metrics, and more
|
||||
|
@ -188,12 +199,21 @@ This is a list of what it currently monitors:
|
|||
- **Redis databases**<br/>
|
||||
multiple servers, each showing: operations, hit rate, memory, keys, clients, slaves
|
||||
|
||||
- **mongodb**<br/>
|
||||
operations, clients, transactions, cursors, connections, asserts, locks, etc
|
||||
|
||||
- **memcached databases**<br/>
|
||||
multiple servers, each showing: bandwidth, connections, items
|
||||
|
||||
- **elasticsearch**<br/>
|
||||
search and index performance, latency, timings, cluster statistics, threads statistics, etc
|
||||
|
||||
- **ISC Bind name servers**<br/>
|
||||
multiple servers, each showing: clients, requests, queries, updates, failures and several per view metrics
|
||||
|
||||
- **NSD name servers**<br/>
|
||||
queries, zones, protocols, query types, transfers, etc.
|
||||
|
||||
- **Postfix email servers**<br/>
|
||||
message queue (entries, size)
|
||||
|
||||
|
@ -202,14 +222,26 @@ This is a list of what it currently monitors:
|
|||
|
||||
- **Dovecot** POP3/IMAP servers<br/>
|
||||
|
||||
- **ISC dhcpd**<br/>
|
||||
pools utilization, leases, etc.
|
||||
|
||||
- **IPFS**<br/>
|
||||
bandwidth, peers
|
||||
|
||||
- **Squid proxy servers**<br/>
|
||||
multiple servers, each showing: clients bandwidth and requests, servers bandwidth and requests
|
||||
|
||||
- **HAproxy**<br/>
|
||||
bandwidth, sessions, backends, etc
|
||||
|
||||
- **varnish**<br/>
|
||||
threads, sessions, hits, objects, backends, etc
|
||||
|
||||
- **OpenVPN**<br/>
|
||||
status per tunnel
|
||||
|
||||
- **Hardware sensors**<br/>
|
||||
temperature, voltage, fans, power, humidity
|
||||
`lm_sensors` and `IPMI`: temperature, voltage, fans, power, humidity
|
||||
|
||||
- **NUT and APC UPSes**<br/>
|
||||
load, charge, battery voltage, temperature, utility metrics, output metrics
|
||||
|
@ -220,11 +252,16 @@ This is a list of what it currently monitors:
|
|||
- **hddtemp**<br/>
|
||||
disk temperatures
|
||||
|
||||
- **smartd**<br/>
|
||||
disk S.M.A.R.T. values
|
||||
|
||||
- **SNMP devices**<br/>
|
||||
can be monitored too (although you will need to configure these)
|
||||
|
||||
And you can extend it, by writing plugins that collect data from any source, using any computer language.
|
||||
- **statsd**<br/>
|
||||
[netdata is a fully featured statsd server](https://github.com/firehol/netdata/wiki/statsd)
|
||||
|
||||
And you can extend it, by writing plugins that collect data from any source, using any computer language.
|
||||
|
||||
## Links
|
||||
|
||||
|
|
|
@ -17,10 +17,6 @@
|
|||
wrong_user=0
|
||||
wrong_path=1
|
||||
incorrect_path=1
|
||||
corrupt_source=0
|
||||
fail_download_source=0
|
||||
port_already_use=0
|
||||
final_path_already_use=0
|
||||
;;; Levels
|
||||
Level 1=auto
|
||||
Level 2=auto
|
||||
|
@ -34,3 +30,6 @@
|
|||
Level 8=0
|
||||
Level 9=0
|
||||
Level 10=0
|
||||
;;; Options
|
||||
Email=
|
||||
Notification=none
|
4
conf/app.src
Normal file
4
conf/app.src
Normal file
|
@ -0,0 +1,4 @@
|
|||
SOURCE_URL=https://github.com/firehol/netdata/releases/download/v1.7.0/netdata-1.7.0.tar.gz
|
||||
SOURCE_SUM=d088d5c6c22ac9241b87480df76de65a414ba9955be3399bd593929ca3c7a417
|
||||
SOURCE_FORMAT=tar.gz
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
Section: misc
|
||||
Priority: optional
|
||||
Homepage: https://https://my-netdata.io/
|
||||
Standards-Version: 3.9.2
|
||||
|
||||
Package: netdata-deps
|
||||
Version: 1.6.0-1
|
||||
Depends: zlib1g-dev, uuid-dev, libmnl-dev, gcc, make, git, autoconf, autoconf-archive, autogen, automake, pkg-config, curl, jq, nodejs, python-mysqldb, libipmimonitoring-dev
|
||||
Architecture: all
|
||||
Description: meta package for NetData dependencies
|
||||
netdata is a system for distributed real-time performance and health monitoring. It provides unparalleled insights, in real-time, of everything happening on the system it runs (including applications such as web and database servers), using modern interactive web dashboards.
|
||||
.
|
||||
This meta-package is only responsible of installing its dependencies.
|
|
@ -1,8 +1,8 @@
|
|||
location YNH_WWW_PATH {
|
||||
return 301 YNH_WWW_PATH/;
|
||||
}
|
||||
#for-subdir location __PATH__ {
|
||||
#for-subdir return 301 __PATH__/;
|
||||
#for-subdir }
|
||||
|
||||
location ~ YNH_WWW_PATH/(?<ndpath>.*) {
|
||||
location ~ __PATH__/(?<ndpath>.*) {
|
||||
proxy_redirect off;
|
||||
proxy_set_header Host $host;
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
location / {
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
proxy_set_header X-Forwarded-Server $host;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Accept-Encoding "";
|
||||
proxy_pass http://127.0.0.1:19999;
|
||||
proxy_http_version 1.1;
|
||||
proxy_pass_request_headers on;
|
||||
proxy_set_header Connection "keep-alive";
|
||||
proxy_store off;
|
||||
|
||||
# Include SSOWAT user panel.
|
||||
include conf.d/yunohost_panel.conf.inc;
|
||||
}
|
|
@ -15,7 +15,7 @@
|
|||
"url": ""
|
||||
},
|
||||
"requirements": {
|
||||
"yunohost": ">> 2.4.0"
|
||||
"yunohost": ">= 2.7.2"
|
||||
},
|
||||
"multi_instance": false,
|
||||
"services": [
|
||||
|
|
|
@ -3,42 +3,32 @@
|
|||
# Common variables
|
||||
#
|
||||
|
||||
# Application version
|
||||
VERSION="1.7.0"
|
||||
pkg_dependencies="zlib1g-dev uuid-dev libmnl-dev gcc make git autoconf autoconf-archive autogen automake pkg-config curl jq nodejs python-mysqldb libipmimonitoring-dev"
|
||||
|
||||
# Remote URL to fetch application source archive
|
||||
APPLICATION_SOURCE_URL="https://github.com/firehol/netdata/releases/download/v${VERSION}/netdata-${VERSION}.tar.gz"
|
||||
# Configure NetData
|
||||
configure_netdata() {
|
||||
# Create netdata user to monitor MySQL (if needed)
|
||||
is_mysql_user_existing=$(ynh_mysql_execute_as_root "select user from mysql.user where user = 'netdata';")
|
||||
if [ -z "$is_mysql_user_existing" ] ; then
|
||||
ynh_mysql_execute_as_root "create user 'netdata'@'localhost';
|
||||
grant usage on *.* to 'netdata'@'localhost' with grant option;
|
||||
flush privileges;"
|
||||
fi
|
||||
|
||||
# Package name for NetData dependencies
|
||||
DEPS_PKG_NAME="netdata-deps"
|
||||
# Give dovecot privileges to netdata user to monitor Dovecot
|
||||
# Need dovecot 2.2.16+
|
||||
setfacl -m u:netdata:rw /var/run/dovecot/stats
|
||||
|
||||
#
|
||||
# Common helpers
|
||||
#
|
||||
# Add netdata to the adm group to access web logs
|
||||
usermod -a -G adm netdata
|
||||
|
||||
# Download and extract application sources to the given directory
|
||||
# usage: extract_application_to DESTDIR
|
||||
extract_application() {
|
||||
TMPDIR=$(mktemp -d)
|
||||
chmod 755 $TMPDIR
|
||||
archive="${TMPDIR}/application.tar.gz"
|
||||
wget -q -O "$archive" "$APPLICATION_SOURCE_URL" \
|
||||
|| ynh_die "Unable to download application archive"
|
||||
tar xf "$archive" -C "$TMPDIR" --strip-components 1 \
|
||||
|| ynh_die "Unable to extract application archive"
|
||||
rm "$archive"
|
||||
echo "$TMPDIR"
|
||||
# Declare service for YunoHost monitoring
|
||||
yunohost service add netdata --log "/opt/netdata/var/log/netdata/error.log" "/opt/netdata/var/log/netdata/access.log" "/opt/netdata/var/log/netdata/debug.log"
|
||||
|
||||
# Restart NetData
|
||||
systemctl restart netdata
|
||||
|
||||
# Store the uninstaller for the removal script
|
||||
mv ./netdata-uninstaller.sh /opt/netdata/etc/netdata
|
||||
}
|
||||
|
||||
# Fix path if needed
|
||||
# usage: fix_patch PATH_TO_FIX
|
||||
fix_path() {
|
||||
local path=$1
|
||||
if [ "${path:0:1}" != "/" ] && [ ${#path} -gt 0 ]; then
|
||||
path="/$path"
|
||||
fi
|
||||
if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then
|
||||
path="${path:0:${#path}-1}"
|
||||
fi
|
||||
echo "$path"
|
||||
}
|
|
@ -1,17 +1,45 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Exit on command errors and treat unset variables as an error
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
# Exit on command errors and treat access to unset variables as an error
|
||||
set -eu
|
||||
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
if [ ! -e _common.sh ]; then
|
||||
# Get the _common.sh file if it's not in the current directory
|
||||
cp ../settings/scripts/_common.sh ./_common.sh
|
||||
chmod a+rx _common.sh
|
||||
fi
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
# Source YunoHost helpers
|
||||
source /usr/share/yunohost/helpers
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
|
||||
#=================================================
|
||||
# STANDARD BACKUP STEPS
|
||||
#=================================================
|
||||
# BACKUP THE APP CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Backup configuration files
|
||||
# Note: the last argument is where to save this path, see the restore script.
|
||||
ynh_backup "/opt/netdata/etc/netdata" "conf"
|
||||
ynh_backup "/opt/netdata/etc/netdata"
|
||||
|
||||
# Copy NGINX configuration
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
|
||||
#=================================================
|
||||
# BACKUP THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
|
158
scripts/install
158
scripts/install
|
@ -1,89 +1,121 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Exit on command errors and treat unset variables as an error
|
||||
set -eu
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
shopt -s extglob # sets extended pattern matching options in the bash shell
|
||||
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
|
||||
|
||||
#=================================================
|
||||
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
||||
#=================================================
|
||||
|
||||
domain=$YNH_APP_ARG_DOMAIN
|
||||
path_url=$YNH_APP_ARG_PATH
|
||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
# Source local helpers
|
||||
source ./_common.sh
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
||||
#=================================================
|
||||
|
||||
SRCPATH=$(pwd)
|
||||
# Normalize the url path syntax
|
||||
path_url=$(ynh_normalize_url_path $path_url)
|
||||
|
||||
# Retrieve arguments
|
||||
domain=$YNH_APP_ARG_DOMAIN
|
||||
path=$YNH_APP_ARG_PATH
|
||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||
# Check web path availability
|
||||
ynh_webpath_available $domain $path_url
|
||||
# Register (book) web path
|
||||
ynh_webpath_register $app $domain $path_url
|
||||
|
||||
# Source YunoHost helpers
|
||||
source /usr/share/yunohost/helpers
|
||||
#=================================================
|
||||
# STORE SETTINGS FROM MANIFEST
|
||||
#=================================================
|
||||
|
||||
# Save app settings
|
||||
ynh_app_setting_set "$app" is_public "$is_public"
|
||||
ynh_app_setting_set $app domain $domain
|
||||
ynh_app_setting_set $app path $path_url
|
||||
ynh_app_setting_set $app is_public $is_public
|
||||
|
||||
# Fix path if needed
|
||||
path=$(fix_path $path)
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
#=================================================
|
||||
# INSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
|
||||
# Check domain/path availability
|
||||
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
||||
|| ynh_die "Path not available: ${domain}${path}"
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
# Download and extract application
|
||||
NETDATA_TMPDIR=$(extract_application)
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
||||
# Install dependencies
|
||||
ynh_package_install_from_equivs ../conf/${DEPS_PKG_NAME}.control \
|
||||
|| ynh_die "Unable to install dependencies"
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
NETDATA_TMPDIR=$(mktemp -d)
|
||||
ynh_setup_source "$NETDATA_TMPDIR"
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
nginx_conf="../conf/nginx.conf"
|
||||
if [ "$path_url" = "/" ]
|
||||
then
|
||||
# Handle root path, avoid double slash.
|
||||
# Temporary fix, in waiting for an upgrade of the helper. (#361)
|
||||
path_url_slash_less=${path_url%/}
|
||||
ynh_replace_string "__PATH__/" "$path_url_slash_less/" $nginx_conf
|
||||
else
|
||||
# Move prefix comment #for-subdir at end of lines
|
||||
ynh_replace_string "#for-subdir\(.*\)" "\1 #for-subdir" $nginx_conf
|
||||
fi
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC SETUP
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# INSTALL AND CONFIGURE NETDATA
|
||||
#=================================================
|
||||
|
||||
# Launch netdata installation in /opt directory
|
||||
cd $NETDATA_TMPDIR
|
||||
sudo ./netdata-installer.sh --install /opt --dont-wait
|
||||
pushd $NETDATA_TMPDIR
|
||||
./netdata-installer.sh --install /opt --dont-wait
|
||||
|
||||
# Create netdata user to monitor MySQL
|
||||
ynh_mysql_execute_as_root "create user 'netdata'@'localhost';
|
||||
grant usage on *.* to 'netdata'@'localhost' with grant option;
|
||||
flush privileges;"
|
||||
configure_netdata
|
||||
|
||||
# Give dovecot privileges to netdata user to monitor Dovecot
|
||||
# Need dovecot 2.2.16+
|
||||
sudo setfacl -m u:netdata:rw /var/run/dovecot/stats
|
||||
# Store the app.src file
|
||||
popd
|
||||
cp ../conf/app.src /opt/netdata/etc/netdata
|
||||
|
||||
# Add netdata to the adm group to access web logs
|
||||
sudo usermod -a -G adm netdata
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
|
||||
# Extend weblog path to process logs for every domain
|
||||
sed -i "s@path: '/var/log/nginx/access.log'@path: '/var/log/nginx/*-access.log'@g" /opt/netdata/etc/netdata/python.d/web_log.conf
|
||||
|
||||
# Declare service for YunoHost monitoring
|
||||
sudo yunohost service add netdata --log "/opt/netdata/var/log/netdata/error.log" "/opt/netdata/var/log/netdata/access.log" "/opt/netdata/var/log/netdata/debug.log"
|
||||
|
||||
# Restart NetData
|
||||
sudo systemctl restart netdata
|
||||
|
||||
# Store the uninstaller for the removal script
|
||||
sudo mv ./netdata-uninstaller.sh /opt/netdata/etc/netdata
|
||||
|
||||
# Store useful files for backup/restore scripts
|
||||
sudo cp $SRCPATH/_common.sh /opt/netdata/etc/netdata
|
||||
sudo cp $SRCPATH/../conf/netdata-deps.control /opt/netdata/etc/netdata
|
||||
|
||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||
if [[ "$path" == "/" ]] ; then
|
||||
nginx_conf=$SRCPATH/../conf/nginx_root.conf
|
||||
else
|
||||
nginx_conf=$SRCPATH/../conf/nginx_sub_dir.conf
|
||||
fi
|
||||
|
||||
sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf
|
||||
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
|
||||
# If app is public, add url to SSOWat conf as skipped_uris
|
||||
if [[ $is_public -eq 1 ]]; then
|
||||
if [ $is_public -eq 1 ]; then
|
||||
# unprotected_uris allows SSO credentials to be passed anyway.
|
||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||
fi
|
||||
|
||||
# Reload services
|
||||
sudo systemctl reload nginx
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
systemctl reload nginx
|
||||
|
|
|
@ -1,53 +1,65 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Treat unset variables as an error
|
||||
set -u
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
# See comments in install script
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
# Source YunoHost helpers
|
||||
if [ ! -e _common.sh ]; then
|
||||
# Get file fonction if not been to the current directory
|
||||
cp ../settings/scripts/_common.sh ./_common.sh
|
||||
chmod a+rx _common.sh
|
||||
fi
|
||||
# Source app helpers
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# Source local helpers
|
||||
source ./_common.sh
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
# Retrieve app settings
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
|
||||
#=================================================
|
||||
# STANDARD REMOVE
|
||||
#=================================================
|
||||
# REMOVE DEPENDENCIES
|
||||
#=================================================
|
||||
|
||||
# Remove metapackage and its dependencies
|
||||
ynh_remove_app_dependencies
|
||||
|
||||
#=================================================
|
||||
# REMOVE APP
|
||||
#=================================================
|
||||
|
||||
# Prepare to execute uninstaller(generated by NetData install script)
|
||||
UNINSTALL_SCRIPT="netdata-uninstaller.sh"
|
||||
|
||||
# Move outside the directory (which will be removed)
|
||||
sudo mv /opt/netdata/etc/netdata/${UNINSTALL_SCRIPT} /tmp
|
||||
mv /opt/netdata/etc/netdata/${UNINSTALL_SCRIPT} /tmp
|
||||
cd /tmp
|
||||
|
||||
# Remove the need for interaction
|
||||
sudo sed -i "s/rm -i/rm -f/g" ${UNINSTALL_SCRIPT}
|
||||
sudo sed -i "s/rm -I/rm -f/g" ${UNINSTALL_SCRIPT}
|
||||
ynh_replace_string "rm -i" "rm -f" ${UNINSTALL_SCRIPT}
|
||||
ynh_replace_string "rm -I" "rm -f" ${UNINSTALL_SCRIPT}
|
||||
# Execute the uninstall script
|
||||
sudo ./${UNINSTALL_SCRIPT} --force
|
||||
./${UNINSTALL_SCRIPT} --force
|
||||
|
||||
# Remove app dependencies
|
||||
ynh_package_autoremove "$DEPS_PKG_NAME" || true
|
||||
#=================================================
|
||||
# REMOVE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Remove access rights for Dovecot monitoring
|
||||
sudo setfacl -x u:netdata /var/run/dovecot/stats
|
||||
|
||||
# Remove user and group
|
||||
sudo userdel netdata
|
||||
|
||||
# Remove service from YunoHost monitoring
|
||||
sudo yunohost service remove netdata
|
||||
|
||||
# Remove MySQL user
|
||||
echo "drop user 'netdata'@'localhost';" | mysql -uroot -p$(sudo cat /etc/yunohost/mysql)
|
||||
|
||||
# Remove nginx configuration file
|
||||
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
sudo rm -rf /home/yunohost.app/$app
|
||||
|
||||
# Reload nginx service
|
||||
sudo systemctl reload nginx
|
||||
# Remove the dedicated nginx config
|
||||
ynh_remove_nginx_config
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC REMOVE
|
||||
#=================================================
|
||||
|
||||
# The following command is kept as a matter of transition with the previous way
|
||||
# of managing dependencies
|
||||
ynh_package_autoremove "netdata-deps" || true
|
||||
|
|
113
scripts/restore
113
scripts/restore
|
@ -1,67 +1,88 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Exit on command errors and treat unset variables as an error
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
# Exit on command errors and treat access to unset variables as an error
|
||||
set -eu
|
||||
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
if [ ! -e _common.sh ]; then
|
||||
# Get the _common.sh file if it's not in the current directory
|
||||
cp ../settings/scripts/_common.sh ./_common.sh
|
||||
chmod a+rx _common.sh
|
||||
fi
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
# Source YunoHost helpers
|
||||
source /usr/share/yunohost/helpers
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
path_url=$(ynh_app_setting_get $app path)
|
||||
|
||||
# Retrieve old app settings
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
path=$(ynh_app_setting_get "$app" path)
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE RESTORED
|
||||
#=================================================
|
||||
|
||||
# Source local helpers
|
||||
source ./conf/_common.sh
|
||||
SRCPATH=$(pwd)
|
||||
ynh_webpath_available $domain $path_url \
|
||||
|| ynh_die "Path not available: ${domain}${path_url}"
|
||||
|
||||
# Fix path if needed
|
||||
path=$(fix_path $path)
|
||||
#=================================================
|
||||
# STANDARD RESTORATION STEPS
|
||||
#=================================================
|
||||
# RESTORE THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Check domain/path availability
|
||||
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
||||
|| ynh_die "Path not available: ${domain}${path}"
|
||||
|
||||
# Download and extract application
|
||||
NETDATA_TMPDIR=$(extract_application)
|
||||
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
# Install dependencies
|
||||
ynh_package_install_from_equivs ./conf/${DEPS_PKG_NAME}.control \
|
||||
|| ynh_die "Unable to install dependencies"
|
||||
#=================================================
|
||||
# INSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
||||
# Retrieve app.src from archive for ynh_setup_source helper
|
||||
mkdir ../conf
|
||||
cp opt/netdata/etc/netdata/app.src ../conf
|
||||
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
NETDATA_TMPDIR=$(mktemp -d)
|
||||
ynh_setup_source "$NETDATA_TMPDIR"
|
||||
|
||||
#=================================================
|
||||
# INSTALL AND RESTORE THE APP CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Launch netdata installation in /opt directory
|
||||
cd $NETDATA_TMPDIR
|
||||
sudo ./netdata-installer.sh --install /opt --dont-wait
|
||||
./netdata-installer.sh --install /opt --dont-wait
|
||||
|
||||
# Create netdata user to monitor MySQL (if needed)
|
||||
echo "select User from mysql.user where User = 'netdata';"| mysql -uroot -p$(sudo cat /etc/yunohost/mysql) || echo "create user 'netdata'@'localhost';
|
||||
grant usage on *.* to 'netdata'@'localhost' with grant option;
|
||||
flush privileges;" | mysql -uroot -p$(sudo cat /etc/yunohost/mysql)
|
||||
|
||||
# Give dovecot privileges to netdata user to monitor Dovecot
|
||||
# Need dovecot 2.2.16+
|
||||
sudo setfacl -m u:netdata:rw /var/run/dovecot/stats
|
||||
|
||||
# Add netdata to the adm group to access web logs
|
||||
sudo usermod -a -G adm netdata
|
||||
|
||||
# Restart NetData
|
||||
sudo systemctl restart netdata
|
||||
|
||||
# Store the uninstaller for the removal script
|
||||
sudo mv ./netdata-uninstaller.sh /opt/netdata
|
||||
configure_netdata
|
||||
|
||||
# Restore configuration files
|
||||
conf_path="/opt/netdata/etc/netdata"
|
||||
sudo cp -a $SRCPATH/conf/* "$conf_path"
|
||||
ynh_restore_file "/opt/netdata/etc/netdata"
|
||||
|
||||
# Restore permissions to app files
|
||||
# you may need to make some file and/or directory writeable by www-data (nginx user)
|
||||
sudo chown -R root: "$conf_path"
|
||||
chown -R root: "/opt/netdata/etc/netdata"
|
||||
|
||||
# Restore NGINX configuration
|
||||
sudo cp -a $SRCPATH/nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||
#=================================================
|
||||
# GENERIC FINALISATION
|
||||
#=================================================
|
||||
# RELOAD NGINX AND PHP-FPM
|
||||
#=================================================
|
||||
|
||||
# Restart webserver
|
||||
sudo systemctl reload nginx
|
||||
systemctl reload nginx
|
||||
|
|
146
scripts/upgrade
146
scripts/upgrade
|
@ -1,38 +1,86 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Exit on command errors and treat unset variables as an error
|
||||
set -eu
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
shopt -s extglob # sets extended pattern matching options in the bash shell
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
# Source local helpers
|
||||
source ./_common.sh
|
||||
SRCPATH=$(pwd)
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
path_url=$(ynh_app_setting_get $app path)
|
||||
is_public=$(ynh_app_setting_get $app is_public)
|
||||
|
||||
# Source YunoHost helpers
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# Retrieve app settings
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
path=$(ynh_app_setting_get "$app" path)
|
||||
is_public=$(ynh_app_setting_get "$app" is_public)
|
||||
#=================================================
|
||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
|
||||
# Fix path if needed
|
||||
path=$(fix_path $path)
|
||||
ynh_backup_before_upgrade # Backup the current version of the app
|
||||
ynh_clean_setup () {
|
||||
ynh_restore_upgradebackup # restore it if the upgrade fails
|
||||
}
|
||||
ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée.
|
||||
|
||||
# Upgrade dependencies
|
||||
ynh_package_install_from_equivs ../conf/${DEPS_PKG_NAME}.control \
|
||||
|| ynh_die "Unable to upgrade dependencies"
|
||||
#=================================================
|
||||
# CHECK THE PATH
|
||||
#=================================================
|
||||
|
||||
# Download and extract application
|
||||
NETDATA_TMPDIR=$(extract_application)
|
||||
# Normalize the URL path syntax
|
||||
path_url=$(ynh_normalize_url_path $path_url)
|
||||
|
||||
#=================================================
|
||||
# STANDARD UPGRADE STEPS
|
||||
#=================================================
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
nginx_conf="../conf/nginx.conf"
|
||||
if [ "$path_url" = "/" ]
|
||||
then
|
||||
# Handle root path, avoid double slash.
|
||||
# Temporary fix, in waiting for an upgrade of the helper. (#361)
|
||||
path_url_slash_less=${path_url%/}
|
||||
ynh_replace_string "__PATH__/" "$path_url_slash_less/" $nginx_conf
|
||||
else
|
||||
# Move prefix comment #for-subdir at end of lines
|
||||
ynh_replace_string "#for-subdir\(.*\)" "\1 #for-subdir" $nginx_conf
|
||||
fi
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# UPGRADE DEPENDENCIES
|
||||
#=================================================
|
||||
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
NETDATA_TMPDIR=$(mktemp -d)
|
||||
ynh_setup_source "$NETDATA_TMPDIR"
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC UPGRADE
|
||||
#=================================================
|
||||
|
||||
# signal netdata to start saving its database
|
||||
# this is handy if your database is big
|
||||
pids=$(pidof netdata)
|
||||
[ ! -z "${pids}" ] && sudo kill -USR1 ${pids}
|
||||
[ ! -z "${pids}" ] && kill -USR1 ${pids}
|
||||
|
||||
# create a temporary file for the log
|
||||
tmp=$(mktemp /tmp/netdata-updater-log-XXXXXX.log)
|
||||
|
@ -40,53 +88,29 @@ tmp=$(mktemp /tmp/netdata-updater-log-XXXXXX.log)
|
|||
exec 3>${tmp}
|
||||
|
||||
# Launch netdata installation in /opt directory
|
||||
cd $NETDATA_TMPDIR
|
||||
sudo ./netdata-installer.sh --install /opt --dont-wait >&3 2>&3 || ynh_die "FAILED TO COMPILE/INSTALL NETDATA"
|
||||
pushd $NETDATA_TMPDIR
|
||||
./netdata-installer.sh --install /opt --dont-wait >&3 2>&3 || ynh_die "FAILED TO COMPILE/INSTALL NETDATA"
|
||||
|
||||
# Create netdata user to monitor MySQL (if needed)
|
||||
is_mysql_user_existing=$(ynh_mysql_execute_as_root "select user from mysql.user where user = 'netdata';")
|
||||
if [ -z "$is_mysql_user_existing" ] ; then
|
||||
ynh_mysql_execute_as_root "create user 'netdata'@'localhost';
|
||||
grant usage on *.* to 'netdata'@'localhost' with grant option;
|
||||
flush privileges;"
|
||||
fi
|
||||
configure_netdata
|
||||
|
||||
# Give dovecot privileges to netdata user to monitor Dovecot
|
||||
# Need dovecot 2.2.16+
|
||||
sudo setfacl -m u:netdata:rw /var/run/dovecot/stats
|
||||
|
||||
# Add netdata to the adm group to access web logs
|
||||
sudo usermod -a -G adm netdata
|
||||
|
||||
# Extend weblog path to process logs for every domain
|
||||
sed -i "s@path: '/var/log/nginx/access.log'@path: '/var/log/nginx/*-access.log'@g" /opt/netdata/etc/netdata/python.d/web_log.conf
|
||||
|
||||
# Declare service for YunoHost monitoring
|
||||
sudo yunohost service add netdata --log "/opt/netdata/var/log/netdata/error.log" "/opt/netdata/var/log/netdata/access.log" "/opt/netdata/var/log/netdata/debug.log"
|
||||
|
||||
# Restart NetData
|
||||
sudo systemctl restart netdata
|
||||
|
||||
# Store the uninstaller for the removal script
|
||||
sudo mv ./netdata-uninstaller.sh /opt/netdata/etc/netdata
|
||||
# Store the local helper for backup/restore scripts
|
||||
sudo cp $SRCPATH/_common.sh /opt/netdata/etc/netdata
|
||||
|
||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||
if [[ "$path" == "/" ]] ; then
|
||||
nginx_conf=$SRCPATH/../conf/nginx_root.conf
|
||||
else
|
||||
nginx_conf=$SRCPATH/../conf/nginx_sub_dir.conf
|
||||
fi
|
||||
|
||||
sed -i "s@YNH_WWW_PATH@${path}@g" $nginx_conf
|
||||
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
# Store the app.src file
|
||||
popd
|
||||
cp ../conf/app.src /opt/netdata/etc/netdata
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
# If app is public, add url to SSOWat conf as skipped_uris
|
||||
if [[ $is_public -eq 1 ]]; then
|
||||
# See install script
|
||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||
fi
|
||||
|
||||
# Reload nginx service
|
||||
sudo systemctl reload nginx
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
systemctl reload nginx
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue