diff --git a/CHANGELOG.md b/CHANGELOG.md index 6950104..f1169bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 897f0bf..273261f 100644 --- a/README.md +++ b/README.md @@ -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+) diff --git a/conf/app.src b/conf/app.src index 86963b8..b7a7af3 100644 --- a/conf/app.src +++ b/conf/app.src @@ -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 diff --git a/conf/nginx.conf b/conf/nginx.conf index fde6590..9241df9 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,8 +1,10 @@ -#for-subdir location __PATH__ { -#for-subdir return 301 __PATH__/; -#for-subdir } +#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; location ~ __PATH__/(?.*) { + # 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__/(?.*) { 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; } diff --git a/manifest.json b/manifest.json index c84e5d5..5953763 100644 --- a/manifest.json +++ b/manifest.json @@ -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": { diff --git a/scripts/_common.sh b/scripts/_common.sh index 2edd312..56fa45b 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -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 <${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 diff --git a/scripts/remove b/scripts/remove index 48648e9..23af483 100644 --- a/scripts/remove +++ b/scripts/remove @@ -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 diff --git a/scripts/restore b/scripts/restore index 4b6ec37..3e55786 100644 --- a/scripts/restore +++ b/scripts/restore @@ -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 diff --git a/scripts/upgrade b/scripts/upgrade index bfcd2e2..b6ad8ee 100644 --- a/scripts/upgrade +++ b/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