mirror of
https://github.com/YunoHost-Apps/netdata_ynh.git
synced 2024-09-03 19:46:33 +02:00
Merge pull request #49 from YunoHost-Apps/enh_refactoring
This commit is contained in:
commit
da8dc02e27
12 changed files with 388 additions and 181 deletions
|
@ -4,6 +4,11 @@ Changelog
|
|||
## Unreleased
|
||||
- Nothing for now...
|
||||
|
||||
## [1.26.0~ynh1](https://github.com/YunoHost-Apps/netdata_ynh/pull/50) - 2020-11-15
|
||||
|
||||
#### Changed
|
||||
* [Update to 1.26.0](https://github.com/YunoHost-Apps/netdata_ynh/pull/50)
|
||||
|
||||
## [1.22.1~ynh1](https://github.com/YunoHost-Apps/netdata_ynh/pull/48) - 2020-05-13
|
||||
|
||||
#### Changed
|
||||
|
|
|
@ -13,10 +13,11 @@ _netdata is **fast** and **efficient**, designed to permanently run on all syste
|
|||
(**physical** & **virtual** servers, **containers**, **IoT** devices), without
|
||||
disrupting their core function._
|
||||
|
||||
**Shipped version:** 1.22.1
|
||||
**Shipped version:** 1.26.0
|
||||
|
||||
**Customization brought by the package:**
|
||||
|
||||
* Netdata Cloud functionality disabled
|
||||
* grant MySQL statistics access via a `netdata` user
|
||||
* nginx root log statistics via putting `netdata` user in the `adm` group
|
||||
* Dovecot statistics via giving access to Dovecot stats stocket to `netdata` user (works only with Dovecot 2.2.16+)
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
SOURCE_URL=https://github.com/netdata/netdata/releases/download/v1.22.1/netdata-v1.22.1.tar.gz
|
||||
SOURCE_SUM=f169c8615a6823448c2f1923c87c286d798132ea29d26f366e96d26e0aec3697
|
||||
SOURCE_URL=https://github.com/netdata/netdata/releases/download/v1.26.0/netdata-v1.26.0.tar.gz
|
||||
SOURCE_SUM=33af27eb57f954e50059a32bec624815aa742fe03182845b1d9b577f1e20e30a
|
||||
SOURCE_FORMAT=tar.gz
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#for-subdir location __PATH__ {
|
||||
#for-subdir return 301 __PATH__/;
|
||||
#for-subdir }
|
||||
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
|
||||
|
||||
location ~ __PATH__/(?<ndpath>.*) {
|
||||
# Force usage of https
|
||||
if ($scheme = http) {
|
||||
rewrite ^ https://$server_name$request_uri? permanent;
|
||||
}
|
||||
proxy_redirect off;
|
||||
proxy_set_header Host $host;
|
||||
|
||||
|
@ -19,7 +21,7 @@ location ~ __PATH__/(?<ndpath>.*) {
|
|||
gzip on;
|
||||
gzip_proxied any;
|
||||
gzip_types *;
|
||||
|
||||
# Include SSOWAT user panel.
|
||||
include conf.d/yunohost_panel.conf.inc;
|
||||
|
||||
# Include SSOWAT user panel.
|
||||
include conf.d/yunohost_panel.conf.inc;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"en": "real-time performance and health monitoring",
|
||||
"fr": "Monitoring serveur en temps reel"
|
||||
},
|
||||
"version": "1.22.1~ynh1",
|
||||
"version": "1.26.0~ynh1",
|
||||
"url": "http://my-netdata.io/",
|
||||
"license": "GPL-3.0",
|
||||
"maintainer": {
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Common variables
|
||||
#
|
||||
|
||||
#=================================================
|
||||
# COMMON VARIABLES
|
||||
#=================================================
|
||||
|
||||
# dependencies used by the app
|
||||
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 acl python-psycopg2 python-pymongo libuv1-dev liblz4-dev libjudy-dev libssl-dev cmake"
|
||||
|
||||
#=================================================
|
||||
# PERSONAL HELPERS
|
||||
#=================================================
|
||||
|
||||
# Configure NetData
|
||||
configure_netdata() {
|
||||
|
||||
|
@ -11,11 +18,11 @@ configure_netdata() {
|
|||
sed -i "/^\[registry\]$/,/^\[/ {
|
||||
s/# enabled = no/enabled = yes/
|
||||
s@# registry to announce = https://registry.my-netdata.io@registry to announce = https://$domain$path_url@
|
||||
}" /opt/netdata/etc/netdata/netdata.conf
|
||||
}" $final_path/etc/netdata/netdata.conf
|
||||
|
||||
# Opt-out from sending anonymous statistics
|
||||
# (see https://docs.netdata.cloud/docs/anonymous-statistics/#opt-out)
|
||||
touch /opt/netdata/etc/netdata/.opt-out-from-anonymous-statistics
|
||||
# Opt-out from sending anonymous statistics
|
||||
# (see https://docs.netdata.cloud/docs/anonymous-statistics/#opt-out)
|
||||
touch $final_path/etc/netdata/.opt-out-from-anonymous-statistics
|
||||
|
||||
# Add a web_log entry for every YunoHost domain
|
||||
netdata_add_yunohost_web_logs
|
||||
|
@ -24,9 +31,9 @@ touch /opt/netdata/etc/netdata/.opt-out-from-anonymous-statistics
|
|||
netdata_add_yunohost_postgres_configuration
|
||||
|
||||
# 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';")
|
||||
is_mysql_user_existing=$(ynh_mysql_execute_as_root --sql="select user from mysql.user where user = 'netdata';")
|
||||
if [ -z "$is_mysql_user_existing" ] ; then
|
||||
ynh_mysql_execute_as_root "create user 'netdata'@'localhost';
|
||||
ynh_mysql_execute_as_root --sql="create user 'netdata'@'localhost';
|
||||
grant usage on *.* to 'netdata'@'localhost' with grant option;
|
||||
flush privileges;"
|
||||
fi
|
||||
|
@ -46,19 +53,13 @@ touch /opt/netdata/etc/netdata/.opt-out-from-anonymous-statistics
|
|||
|
||||
# Add netdata to the adm group to access web logs
|
||||
usermod -a -G adm netdata
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
# Add a web_log entry for every YunoHost domain
|
||||
netdata_add_yunohost_web_logs () {
|
||||
local web_log_file="/opt/netdata/etc/netdata/python.d/web_log.conf"
|
||||
local web_log_file="$final_path/etc/netdata/python.d/web_log.conf"
|
||||
if [ ! -f $web_log_file ] ; then
|
||||
cp /opt/netdata/etc/netdata/orig/python.d/web_log.conf $web_log_file
|
||||
cp $final_path/etc/netdata/orig/python.d/web_log.conf $web_log_file
|
||||
fi
|
||||
if [ -z "$(grep "YUNOHOST" $web_log_file)" ] ; then
|
||||
echo "# ------------YUNOHOST DOMAINS---------------" >> $web_log_file
|
||||
|
@ -77,9 +78,9 @@ EOF
|
|||
|
||||
# If PostgreSQL is installed, add a PostgreSQL entry using instance password
|
||||
netdata_add_yunohost_postgres_configuration () {
|
||||
local postgres_file="/opt/netdata/etc/netdata/python.d/postgres.conf"
|
||||
local postgres_file="$final_path/etc/netdata/python.d/postgres.conf"
|
||||
if [ ! -f $postgres_file ] ; then
|
||||
cp /opt/netdata/etc/netdata/orig/python.d/postgres.conf $postgres_file
|
||||
cp $final_path/etc/netdata/orig/python.d/postgres.conf $postgres_file
|
||||
fi
|
||||
if [ -f /etc/yunohost/psql ] && [ -z "$(grep "yunohost:" $postgres_file)" ] ; then
|
||||
cat >> $postgres_file <<EOF
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
||||
source ../settings/scripts/_common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
|
@ -13,28 +14,68 @@ source /usr/share/yunohost/helpers
|
|||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
ynh_clean_setup () {
|
||||
### Remove this function if there's nothing to clean before calling the remove script.
|
||||
true
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..." --weight=1
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
|
||||
#=================================================
|
||||
# STANDARD BACKUP STEPS
|
||||
#=================================================
|
||||
# BACKUP THE APP CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Backup configuration files
|
||||
ynh_backup "/opt/netdata/etc/netdata"
|
||||
ynh_print_info --message="Declaring files to be backed up..."
|
||||
|
||||
# N.B.: the following 'ynh_backup' calls are only a *declaration* of what needs
|
||||
# to be backuped and not an actual copy of any file. The actual backup that
|
||||
# creates and fill the archive with the files happens in the core after this
|
||||
# script is called. Hence ynh_backups calls takes basically 0 seconds to run
|
||||
|
||||
#=================================================
|
||||
# STOP SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_print_info --message="Stopping a systemd service..."
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="stop" --log_path="$final_path/var/log/$app/error.log"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE APP MAIN DIR
|
||||
#=================================================
|
||||
ynh_print_info --message="Backing up Netdata configuration directory..."
|
||||
|
||||
ynh_backup --src_path="$final_path/etc/netdata"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_print_info --message="Backing up nginx web server configuration..."
|
||||
|
||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC BACKUP
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_print_info --message="Starting a systemd service..."
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="start" --log_path="$final_path/var/log/$app/error.log"
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
|
||||
|
|
|
@ -24,15 +24,26 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..." --time --weight=1
|
||||
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
|
||||
#=================================================
|
||||
# CHECK PATHS SYNTAX
|
||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." --time --weight=1
|
||||
|
||||
test -n "$old_path" || old_path="/"
|
||||
test -n "$new_path" || new_path="/"
|
||||
new_path=$(ynh_normalize_url_path $new_path)
|
||||
old_path=$(ynh_normalize_url_path $old_path)
|
||||
# Backup the current version of the app
|
||||
ynh_backup_before_upgrade
|
||||
ynh_clean_setup () {
|
||||
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
|
||||
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||
|
||||
# restore it if the upgrade fails
|
||||
ynh_restore_upgradebackup
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# CHECK WHICH PARTS SHOULD BE CHANGED
|
||||
|
@ -53,60 +64,66 @@ fi
|
|||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
#=================================================
|
||||
# MODIFY URL IN NGINX CONF FILE
|
||||
# STOP SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
|
||||
|
||||
#=================================================
|
||||
# MODIFY URL IN NGINX CONF
|
||||
#=================================================
|
||||
ynh_script_progression --message="Updating nginx web server configuration..." --weight=1
|
||||
|
||||
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
|
||||
|
||||
# Change the path in the nginx config file
|
||||
if [ $change_path -eq 1 ]
|
||||
then
|
||||
# Make a backup of the original nginx config file if modified
|
||||
ynh_backup_if_checksum_is_different "$nginx_conf_path"
|
||||
ynh_replace_string "location $old_path {" "location $new_path {" "$nginx_conf_path"
|
||||
if [ "$new_path" = "/" ] && [ "$old_path" != "/" ] ; then
|
||||
ynh_replace_string "location ~ $old_path" "location ~ " "$nginx_conf_path"
|
||||
ynh_replace_string "return 301 $old_path/" "return 301 /" "$nginx_conf_path"
|
||||
|
||||
# Move #for-subdir comment at the beginning of the line (line not needed for "/" path)
|
||||
ynh_replace_string "\(.*\) #for-subdir" "#for-subdir \1" "$nginx_conf_path"
|
||||
elif [ "$new_path" != "/" ] && [ "$old_path" = "/" ] ; then
|
||||
# Move #for-subdir comment at the end of the line (line needed for "/path" path)
|
||||
ynh_replace_string "#for-subdir\(.*\)" "\1 #for-subdir" "$nginx_conf_path"
|
||||
|
||||
# Replace path in several location occurrences based on different recognition patterns
|
||||
ynh_replace_string "location ~ " "location ~ $new_path" "$nginx_conf_path"
|
||||
ynh_replace_string "return 301 /" "return 301 $new_path/" "$nginx_conf_path"
|
||||
else
|
||||
ynh_replace_string "location ~ $old_path" "location ~ $new_path" "$nginx_conf_path"
|
||||
ynh_replace_string "return \([[:digit:]]\{3\}\) $old_path" "return \1 $new_path" "$nginx_conf_path"
|
||||
fi
|
||||
# Calculate and store the nginx config file checksum
|
||||
ynh_store_file_checksum "$nginx_conf_path"
|
||||
|
||||
# Change registry link
|
||||
ynh_replace_string "registry to announce = https://$old_domain$old_path" "registry to announce = https://$new_domain$new_path" /opt/netdata/etc/netdata/netdata.conf
|
||||
systemctl restart netdata
|
||||
# Make a backup of the original nginx config file if modified
|
||||
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
|
||||
# Set global variables for nginx helper
|
||||
domain="$old_domain"
|
||||
path_url="$new_path"
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
fi
|
||||
|
||||
# Change the domain for nginx
|
||||
if [ $change_domain -eq 1 ]
|
||||
then
|
||||
# Delete file checksum for the old conf file location
|
||||
ynh_delete_file_checksum "$nginx_conf_path"
|
||||
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
|
||||
# Store file checksum for the new config file location
|
||||
ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||
# Delete file checksum for the old conf file location
|
||||
ynh_delete_file_checksum --file="$nginx_conf_path"
|
||||
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
|
||||
# Store file checksum for the new config file location
|
||||
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC MODIFICATIONS
|
||||
#=================================================
|
||||
|
||||
# Change registry link
|
||||
ynh_replace_string --match_string="registry to announce = https://$old_domain$old_path" --replace_string="registry to announce = https://$new_domain$new_path" --target_file="/opt/netdata/etc/netdata/netdata.conf"
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
# GENERIC FINALISATION
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="restart" --log_path="$final_path/var/log/$app/error.log"
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading nginx web server..." --weight=1
|
||||
|
||||
systemctl reload nginx
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Change of URL completed for $app" --last
|
||||
|
|
|
@ -13,6 +13,10 @@ source /usr/share/yunohost/helpers
|
|||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
ynh_clean_setup () {
|
||||
### Remove this function if there's nothing to clean before calling the remove script.
|
||||
true
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
|
@ -31,54 +35,55 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
||||
#=================================================
|
||||
|
||||
# Normalize the url path syntax
|
||||
path_url=$(ynh_normalize_url_path $path_url)
|
||||
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
||||
|
||||
final_path=/opt/$app
|
||||
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
||||
|
||||
# Check web path availability
|
||||
ynh_webpath_available $domain $path_url
|
||||
# Register (book) web path
|
||||
ynh_webpath_register $app $domain $path_url
|
||||
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
||||
|
||||
#=================================================
|
||||
# STORE SETTINGS FROM MANIFEST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Storing installation settings..." --weight=1
|
||||
|
||||
ynh_app_setting_set $app domain $domain
|
||||
ynh_app_setting_set $app path $path_url
|
||||
ynh_app_setting_set $app admin $admin
|
||||
ynh_app_setting_set $app is_public $is_public
|
||||
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
||||
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
||||
ynh_app_setting_set --app=$app --key=admin --value=$admin
|
||||
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
|
||||
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# INSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Installing dependencies..." --weight=32
|
||||
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Setting up source files..." --weight=11
|
||||
|
||||
### `ynh_setup_source` is used to install an app from a zip or tar.gz file,
|
||||
### downloaded from an upstream source, like a git repository.
|
||||
### `ynh_setup_source` use the file conf/app.src
|
||||
|
||||
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
NETDATA_TMPDIR=$(mktemp -d)
|
||||
ynh_setup_source "$NETDATA_TMPDIR"
|
||||
ynh_setup_source --dest_dir="$NETDATA_TMPDIR"
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring nginx web server..." --weight=2
|
||||
|
||||
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
|
||||
### `ynh_add_nginx_config` will use the file conf/nginx.conf
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
@ -87,27 +92,47 @@ ynh_add_nginx_config
|
|||
# SPECIFIC SETUP
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# INSTALL AND CONFIGURE NETDATA
|
||||
#=================================================
|
||||
ynh_script_progression --message="Executing Netdata installer..." --weight=180
|
||||
|
||||
# create a temporary file for the log
|
||||
tmp=$(mktemp /tmp/netdata-updater-log-XXXXXX.log)
|
||||
# open fd 3 and send it to tmp
|
||||
exec 3>${tmp}
|
||||
|
||||
# Launch netdata installation in /opt directory
|
||||
pushd $NETDATA_TMPDIR
|
||||
./netdata-installer.sh --install /opt --dont-wait
|
||||
|
||||
configure_netdata
|
||||
|
||||
# Store the app.src file
|
||||
./netdata-installer.sh --install /opt --dont-wait --disable-cloud >&3 2>&3 || ynh_die "FAILED TO COMPILE/INSTALL NETDATA"
|
||||
popd
|
||||
cp ../conf/app.src /opt/netdata/etc/netdata
|
||||
|
||||
# close fd 3
|
||||
exec 3<&-
|
||||
|
||||
# Specific configuration
|
||||
configure_netdata
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
|
||||
yunohost service add $app --description "Real-time performance and health monitoring for systems and applications" --log "$final_path/var/log/netdata/error.log" "$final_path/var/log/netdata/access.log" "$final_path/var/log/netdata/debug.log"
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..." --weight=2
|
||||
|
||||
# Start a systemd service
|
||||
ynh_systemd_action --service_name=$app --action="restart" --log_path="$final_path/var/log/$app/error.log"
|
||||
|
||||
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring SSOwat..." --weight=1
|
||||
|
||||
# Make app public if necessary
|
||||
if [ $is_public -eq 1 ]; then
|
||||
|
@ -119,8 +144,16 @@ fi
|
|||
# Add direct access in the portal to admin only
|
||||
ynh_permission_update --permission "main" --add "$admin"
|
||||
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading nginx web server..." --weight=1
|
||||
|
||||
systemctl reload nginx
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Installation of $app completed" --last
|
||||
|
|
|
@ -6,30 +6,44 @@
|
|||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
# Source app helpers
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..." --weight=1
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
|
||||
#=================================================
|
||||
# STANDARD REMOVE
|
||||
#=================================================
|
||||
# REMOVE SERVICE INTEGRATION IN YUNOHOST
|
||||
#=================================================
|
||||
|
||||
# Remove the service from the list of services known by Yunohost (added from `yunohost service add`)
|
||||
if ynh_exec_warn_less yunohost service status $app >/dev/null
|
||||
then
|
||||
ynh_script_progression --message="Removing $app service..." --weight=2
|
||||
yunohost service remove $app
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# REMOVE DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing dependencies..." --weight=8
|
||||
|
||||
# Remove metapackage and its dependencies
|
||||
ynh_remove_app_dependencies
|
||||
|
||||
#=================================================
|
||||
# REMOVE APP
|
||||
# REMOVE APP MAIN DIR
|
||||
#=================================================
|
||||
ynh_script_progression --message="Uninstalling Netdata..." --weight=6
|
||||
|
||||
# Prepare to execute uninstaller(generated by NetData install script)
|
||||
UNINSTALL_SCRIPT="netdata-uninstaller.sh"
|
||||
|
@ -40,18 +54,38 @@ chmod +x /tmp/$UNINSTALL_SCRIPT
|
|||
# Move outside the directory (which will be removed)
|
||||
cd /tmp
|
||||
|
||||
# create a temporary file for the log
|
||||
tmp=$(mktemp /tmp/netdata-uninstaller-log-XXXXXX.log)
|
||||
# open fd 3 and send it to tmp
|
||||
exec 3>${tmp}
|
||||
|
||||
# Execute the uninstall script
|
||||
./${UNINSTALL_SCRIPT} --yes --force --env /opt/netdata/etc/netdata/.environment
|
||||
./${UNINSTALL_SCRIPT} --yes --force --env $final_path/etc/netdata/.environment >&3 2>&3
|
||||
|
||||
# close fd 3
|
||||
exec 3<&-
|
||||
|
||||
# Remove MySQL netdata user
|
||||
ynh_mysql_execute_as_root "drop user 'netdata'@'localhost'; flush privileges;"
|
||||
|
||||
# Remove services from YunoHost monitoring
|
||||
yunohost service remove netdata
|
||||
ynh_mysql_execute_as_root "drop user 'netdata'@'localhost'; flush privileges;"
|
||||
|
||||
#=================================================
|
||||
# REMOVE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing nginx web server configuration..." --weight=1
|
||||
|
||||
# Remove the dedicated nginx config
|
||||
ynh_remove_nginx_config
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC REMOVE
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Removal of $app completed" --last
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
||||
source ../settings/scripts/_common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
|
@ -13,24 +14,33 @@ source /usr/share/yunohost/helpers
|
|||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
ynh_clean_setup () {
|
||||
#### Remove this function if there's nothing to clean before calling the remove script.
|
||||
true
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..." --weight=1
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
path_url=$(ynh_app_setting_get $app path)
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE RESTORED
|
||||
#=================================================
|
||||
ynh_script_progression --message="Validating restoration parameters..." --weight=1
|
||||
|
||||
ynh_webpath_available $domain $path_url \
|
||||
|| ynh_die "Path not available: ${domain}${path_url}"
|
||||
ynh_webpath_available --domain=$domain --path_url=$path_url \
|
||||
|| ynh_die --message="Path not available: ${domain}${path_url}"
|
||||
test ! -d $final_path \
|
||||
|| ynh_die --message="There is already a directory: $final_path "
|
||||
|
||||
#=================================================
|
||||
# STANDARD RESTORATION STEPS
|
||||
|
@ -38,36 +48,35 @@ ynh_webpath_available $domain $path_url \
|
|||
# RESTORE THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# INSTALL DEPENDENCIES
|
||||
# RESTORE THE APP MAIN DIR
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring Netdata configuration directory..." --weight=1
|
||||
|
||||
ynh_restore_file --origin_path="$final_path/etc/netdata"
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC RESTORATION
|
||||
#=================================================
|
||||
# REINSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reinstalling dependencies..." --weight=7
|
||||
|
||||
# Define and install dependencies
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
||||
# Restore configuration files
|
||||
ynh_restore_file "/opt/netdata/etc/netdata"
|
||||
|
||||
# Restore permissions to app files
|
||||
chown -R root: "/opt/netdata/etc/netdata"
|
||||
|
||||
# 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
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Reinstalling Netdata..." --weight=180
|
||||
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
NETDATA_TMPDIR=$(mktemp -d)
|
||||
ynh_setup_source "$NETDATA_TMPDIR"
|
||||
|
||||
# Launch netdata installation in /opt directory
|
||||
cd $NETDATA_TMPDIR
|
||||
./netdata-installer.sh --install /opt --dont-wait
|
||||
|
@ -75,9 +84,29 @@ cd $NETDATA_TMPDIR
|
|||
configure_netdata
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALISATION
|
||||
#=================================================
|
||||
# RELOAD NGINX AND PHP-FPM
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
|
||||
systemctl reload nginx
|
||||
yunohost service add $app --description "A short description of the app" --log "$final_path/var/log/netdata/error.log" "$final_path/var/log/netdata/access.log" "$final_path/var/log/netdata/debug.log"
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="start" --log_path="$final_path/var/log/$app/error.log"
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading nginx web server..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Restoration completed for $app" --last
|
||||
|
|
124
scripts/upgrade
124
scripts/upgrade
|
@ -12,63 +12,82 @@ source /usr/share/yunohost/helpers
|
|||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..." --weight=1
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
path_url=$(ynh_app_setting_get $app path)
|
||||
is_public=$(ynh_app_setting_get $app is_public)
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
||||
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
||||
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
|
||||
#=================================================
|
||||
# CHECK VERSION
|
||||
#=================================================
|
||||
|
||||
upgrade_type=$(ynh_check_app_version_changed)
|
||||
|
||||
#=================================================
|
||||
# ENSURE DOWNWARD COMPATIBILITY
|
||||
#=================================================
|
||||
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
||||
|
||||
# Fix is_public as a boolean value
|
||||
if [ "$is_public" = "Yes" ]; then
|
||||
ynh_app_setting_set --app=$app --key=is_public --value=1
|
||||
is_public=1
|
||||
elif [ "$is_public" = "No" ]; then
|
||||
ynh_app_setting_set --app=$app --key=is_public --value=0
|
||||
is_public=0
|
||||
fi
|
||||
|
||||
# If final_path doesn't exist, create it
|
||||
if [ -z "$final_path" ]; then
|
||||
final_path=/opt/$app
|
||||
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||
fi
|
||||
|
||||
# If final_path wrongly refers to /var/www
|
||||
# see http://tldp.org/LDP/abs/html/comparison-ops.html for syntax reference
|
||||
if [[ $final_path == /var/www* ]]; then
|
||||
final_path=/opt/$app
|
||||
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=3
|
||||
|
||||
ynh_backup_before_upgrade # Backup the current version of the app
|
||||
# Backup the current version of the app
|
||||
ynh_backup_before_upgrade
|
||||
ynh_clean_setup () {
|
||||
ynh_restore_upgradebackup # restore it if the upgrade fails
|
||||
# restore it if the upgrade fails
|
||||
ynh_restore_upgradebackup
|
||||
}
|
||||
ynh_abort_if_errors # Active trap to stop script execution if an error occurs
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# CHECK THE PATH
|
||||
#=================================================
|
||||
|
||||
# Normalize the URL path syntax
|
||||
path_url=$(ynh_normalize_url_path $path_url)
|
||||
path_url=$(ynh_normalize_url_path --path_url=$path_url)
|
||||
|
||||
#=================================================
|
||||
# STANDARD UPGRADE STEPS
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
||||
nginx_conf="../conf/nginx.conf"
|
||||
if [ "$path_url" = "/" ]
|
||||
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||
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
|
||||
ynh_script_progression --message="Upgrading source files..." --weight=180
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# UPGRADE DEPENDENCIES
|
||||
#=================================================
|
||||
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
installed_version=$(cat /opt/netdata/etc/netdata/app.src | grep SOURCE_URL | sed "s|.*/v\(.*\)/.*|\1|g")
|
||||
version_to_install=$(cat ../conf/app.src | grep SOURCE_URL | sed "s|.*/v\(.*\)/.*|\1|g")
|
||||
|
||||
if [ "$installed_version" != "$version_to_install" ] ; then
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
@ -93,12 +112,8 @@ if [ "$installed_version" != "$version_to_install" ] ; then
|
|||
|
||||
# Launch netdata installation in /opt directory
|
||||
pushd $NETDATA_TMPDIR
|
||||
# Remove previous service definition (specific 1.8.0 upgrade)
|
||||
rm -f /etc/systemd/system/netdata.service
|
||||
|
||||
./netdata-installer.sh --install /opt --dont-wait >&3 2>&3 || ynh_die "FAILED TO COMPILE/INSTALL NETDATA"
|
||||
|
||||
popd
|
||||
./netdata-installer.sh --install /opt --dont-wait --disable-cloud >&3 2>&3 || ynh_die "FAILED TO COMPILE/INSTALL NETDATA"
|
||||
popd
|
||||
|
||||
# close fd 3
|
||||
exec 3<&-
|
||||
|
@ -107,14 +122,29 @@ fi
|
|||
# Specific configuration
|
||||
configure_netdata
|
||||
|
||||
# Store the app.src file
|
||||
cp ../conf/app.src /opt/netdata/etc/netdata
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# UPGRADE DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading dependencies..." --weight=7
|
||||
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=1
|
||||
|
||||
# Make app public if necessary
|
||||
if [[ $is_public -eq 1 ]]; then
|
||||
|
@ -123,8 +153,22 @@ if [[ $is_public -eq 1 ]]; then
|
|||
ynh_permission_update --permission "main" --add "visitors"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="restart" --log_path="$final_path/var/log/$app/error.log"
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading nginx web server..." --weight=1
|
||||
|
||||
systemctl reload nginx
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Upgrade of $app completed" --last
|
||||
|
|
Loading…
Add table
Reference in a new issue