1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/netdata_ynh.git synced 2024-09-03 19:46:33 +02:00

Refactor to latest package guidelines

This commit is contained in:
Jimmy Monin 2020-05-13 16:00:07 +02:00
parent e205a9fbfd
commit aa588461eb
8 changed files with 339 additions and 158 deletions

View file

@ -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;
}

View file

@ -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() {
@ -13,9 +20,9 @@ configure_netdata() {
s@# registry to announce = https://registry.my-netdata.io@registry to announce = https://$domain$path_url@
}" /opt/netdata/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 /opt/netdata/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,12 +53,6 @@ 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

View file

@ -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,59 @@ 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
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
# Backup configuration files
ynh_backup "/opt/netdata/etc/netdata"
ynh_systemd_action --service_name=$app --action="stop" --log_path="/opt/$app/var/log/$app/error.log"
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Backing up Netdata configuration directory..." --weight=1
ynh_backup --src_path="/opt/netdata/etc/netdata"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Backing up nginx web server configuration..." --weight=1
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_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/opt/$app/var/log/$app/error.log"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --time --last

View file

@ -24,15 +24,27 @@ app=$YNH_APP_INSTANCE_NAME
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --time --weight=1
# Needed for helper "ynh_add_nginx_config"
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 +65,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="/opt/$app/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

View file

@ -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
@ -30,55 +34,63 @@ app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
### About --weight and --time
### ynh_script_progression will show to your final users the progression of each scripts.
### In order to do that, --weight will represent the relative time of execution compared to the other steps in the script.
### --time is a packager option, it will show you the execution time since the previous call.
### This option should be removed before releasing your app.
### Use the execution time, given by --time, to estimate the weight of a step.
### A common way to do it is to set a weight equal to the execution time in second +1.
### The execution time is given for the duration since the previous call. So the weight should be applied to this previous call.
ynh_script_progression --message="Validating installation parameters..." --weight=1
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
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,10 +99,7 @@ ynh_add_nginx_config
# SPECIFIC SETUP
#=================================================
#=================================================
# INSTALL AND CONFIGURE NETDATA
#=================================================
ynh_script_progression --message="Executing Netdata installer..." --time --weight=180
# Launch netdata installation in /opt directory
pushd $NETDATA_TMPDIR
./netdata-installer.sh --install /opt --dont-wait
@ -101,13 +110,30 @@ configure_netdata
popd
cp ../conf/app.src /opt/netdata/etc/netdata
#=================================================
# GENERIC FINALIZATION
#=================================================
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
yunohost service add $app --description "Real-time performance and health monitoring for systems and applications" --log "/opt/netdata/var/log/netdata/error.log" "/opt/netdata/var/log/netdata/access.log" "/opt/netdata/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="/opt/$app/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 +145,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

View file

@ -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"
@ -44,14 +58,26 @@ cd /tmp
./${UNINSTALL_SCRIPT} --yes --force --env /opt/netdata/etc/netdata/.environment
# 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

View file

@ -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 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,21 +48,30 @@ 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="/opt/netdata/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
# INSTALL AND RESTORE THE APP CONFIGURATION
#=================================================
# Restore configuration files
ynh_restore_file "/opt/netdata/etc/netdata"
ynh_script_progression --message="Reinstalling Netdata..." --weight=180
# Restore permissions to app files
chown -R root: "/opt/netdata/etc/netdata"
@ -64,10 +83,6 @@ cp /opt/netdata/etc/netdata/app.src ../conf
NETDATA_TMPDIR=$(mktemp -d)
ynh_setup_source "$NETDATA_TMPDIR"
#=================================================
# INSTALL AND RESTORE THE APP CONFIGURATION
#=================================================
# Launch netdata installation in /opt directory
cd $NETDATA_TMPDIR
./netdata-installer.sh --install /opt --dont-wait
@ -75,9 +90,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 "/opt/netdata/var/log/netdata/error.log" "/opt/netdata/var/log/netdata/access.log" "/opt/netdata/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="/opt/$app/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

View file

@ -12,63 +12,68 @@ 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=/var/www/$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
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# 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 +98,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
popd
# close fd 3
exec 3<&-
@ -110,11 +111,29 @@ 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 +142,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="/opt/$app/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