diff --git a/scripts/_common.sh b/scripts/_common.sh index 5cda5f3..56fa45b 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -18,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 + touch $final_path/etc/netdata/.opt-out-from-anonymous-statistics # Add a web_log entry for every YunoHost domain netdata_add_yunohost_web_logs @@ -57,9 +57,9 @@ configure_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 @@ -78,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 >&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 @@ -121,7 +118,7 @@ cp ../conf/app.src /opt/netdata/etc/netdata # 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" +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 @@ -129,7 +126,7 @@ yunohost service add $app --description "Real-time performance and health monito 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" +ynh_systemd_action --service_name=$app --action="restart" --log_path="$final_path/var/log/$app/error.log" #================================================= diff --git a/scripts/remove b/scripts/remove index f24a216..23af483 100644 --- a/scripts/remove +++ b/scripts/remove @@ -54,8 +54,16 @@ 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;" diff --git a/scripts/restore b/scripts/restore index 45c202a..a851615 100644 --- a/scripts/restore +++ b/scripts/restore @@ -55,7 +55,7 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= ynh_script_progression --message="Restoring Netdata configuration directory..." --weight=1 -ynh_restore_file --origin_path="/opt/netdata/etc/netdata" +ynh_restore_file --origin_path="$final_path/etc/netdata" #================================================= # SPECIFIC RESTORATION @@ -72,12 +72,6 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= ynh_script_progression --message="Reinstalling Netdata..." --weight=180 -# 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) @@ -93,14 +87,14 @@ configure_netdata # INTEGRATE SERVICE IN YUNOHOST #================================================= -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" +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="/opt/$app/var/log/$app/error.log" +ynh_systemd_action --service_name=$app --action="start" --log_path="$final_path/var/log/$app/error.log" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 2a5356a..37d9275 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -44,7 +44,7 @@ fi # If final_path doesn't exist, create it if [ -z "$final_path" ]; then - final_path=/var/www/$app + final_path=/opt/$app ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi @@ -62,6 +62,13 @@ ynh_clean_setup () { # 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) + #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -108,9 +115,6 @@ fi # Specific configuration configure_netdata -# Store the app.src file -cp ../conf/app.src /opt/netdata/etc/netdata - #================================================= # NGINX CONFIGURATION #================================================= @@ -147,7 +151,7 @@ fi #================================================= 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" +ynh_systemd_action --service_name=$app --action="restart" --log_path="$final_path/var/log/$app/error.log" #================================================= # RELOAD NGINX