345
return 1
346
}
347
348
+get_os_key() {
349
+ if [ -f /etc/os-release ]; then
350
+ # shellcheck disable=SC1091
351
+ source /etc/os-release || return 1
352
+ echo "${ID}-${VERSION_ID}"
353
+
354
+ elif [ -f /etc/redhat-release ]; then
355
+ echo "$(< /etc/redhat-release)"
356
+ else
357
+ echo "unknown"
358
+ fi
359
+}
360
+
361
issystemd() {
362
local pids p myns ns systemctl
363
392
return 1
393
}
394
395
+get_systemd_service_dir() {
396
+ local SYSTEMD_DIRECTORY=""
397
+ local key
398
+ key="$(get_os_key)"
399
+
400
+ if [ -w "/lib/systemd/system" ]; then
401
+ SYSTEMD_DIRECTORY="/lib/systemd/system"
402
+ elif [ -w "/usr/lib/systemd/system" ]; then
403
+ SYSTEMD_DIRECTORY="/usr/lib/systemd/system"
404
+ elif [ -w "/etc/systemd/system" ]; then
405
+ SYSTEMD_DIRECTORY="/etc/systemd/system"
406
+ fi
407
+
408
+ if [[ ${key} =~ ^devuan* ]] || [ "${key}" = "debian-7" ] || [ "${key}" = "ubuntu-12.04" ] || [ "${key}" = "ubuntu-14.04" ]; then
409
+ SYSTEMD_DIRECTORY="/etc/systemd/system"
410
+ fi
411
+
412
+ echo "${SYSTEMD_DIRECTORY}"
413
+}
414
+
415
install_non_systemd_init() {
416
[ "${UID}" != 0 ] && return 1
417
385
- local key="unknown"
386
- if [ -f /etc/os-release ]; then
387
- # shellcheck disable=SC1091
388
- source /etc/os-release || return 1
389
- key="${ID}-${VERSION_ID}"
390
-
391
- elif [ -f /etc/redhat-release ]; then
392
- key=$(< /etc/redhat-release)
393
- fi
418
+ local key
419
+ key="$(get_os_key)"
420
421
if [ -d /etc/init.d ] && [ ! -f /etc/init.d/netdata ]; then
422
if [[ ${key} =~ ^(gentoo|alpine).* ]]; then
464
local uname
465
uname="$(uname 2> /dev/null)"
466
441
- local key="unknown"
442
- if [ -f /etc/os-release ]; then
443
- # shellcheck disable=SC1091
444
- source /etc/os-release || return 1
445
- key="${ID}-${VERSION_ID}"
446
-
447
- elif [ -f /etc/redhat-release ]; then
448
- key=$(< /etc/redhat-release)
449
- fi
450
-
467
if [ "${UID}" -eq 0 ]; then
468
if [ "${uname}" = "Darwin" ]; then
469
502
NETDATA_STOP_CMD="systemctl stop netdata"
503
NETDATA_INSTALLER_START_CMD="${NETDATA_START_CMD}"
504
489
- SYSTEMD_DIRECTORY=""
490
-
491
- if [ -w "/lib/systemd/system" ]; then
492
- SYSTEMD_DIRECTORY="/lib/systemd/system"
493
- elif [ -w "/usr/lib/systemd/system" ]; then
494
- SYSTEMD_DIRECTORY="/usr/lib/systemd/system"
495
- elif [ -w "/etc/systemd/system" ]; then
496
- SYSTEMD_DIRECTORY="/etc/systemd/system"
497
- fi
498
-
499
- if [[ ${key} =~ ^devuan* ]] || [ "${key}" = "debian-7" ] || [ "${key}" = "ubuntu-12.04" ] || [ "${key}" = "ubuntu-14.04" ]; then
500
- SYSTEMD_DIRECTORY="/etc/systemd/system"
501
- fi
505
+ SYSTEMD_DIRECTORY="$(get_systemd_service_dir)"
506
507
if [ "${SYSTEMD_DIRECTORY}x" != "x" ]; then
508
ENABLE_NETDATA_IF_PREVIOUSLY_ENABLED="run systemctl enable netdata"
905
_get_scheduler_type() {
906
if _get_intervaldir > /dev/null ; then
907
echo 'interval'
908
+ elif issystemd ; then
909
+ echo 'systemd'
910
elif [ -d /etc/cron.d ] ; then
911
echo 'crontab'
912
else
935
cat "${NETDATA_SOURCE_DIR}/packaging/installer/netdata-updater.sh" > "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" || return 1
936
fi
937
938
+ if issystemd && [ -n "$(get_systemd_service_dir)" ]; then
939
+ cat "${NETDATA_SOURCE_DIR}/system/netdata-updater.timer" > "$(get_systemd_service_dir)/netdata-updater.timer"
940
+ cat "${NETDATA_SOURCE_DIR}/system/netdata-updater.service" > "$(get_systemd_service_dir)/netdata-updater.service"
941
+ fi
942
+
943
sed -i -e "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${NETDATA_USER_CONFIG_DIR}/.environment|" "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" || return 1
944
945
chmod 0755 "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh"
955
rm -f "${NETDATA_PREFIX}"/usr/libexec/netdata-updater.sh
956
fi
957
958
+ if issystemd && [ -n "$(get_systemd_service_dir)" ] ; then
959
+ systemctl disable netdata-updater.timer
960
+ rm -f "$(get_systemd_service_dir)/netdata-updater.timer"
961
+ rm -f "$(get_systemd_service_dir)/netdata-updater.service"
962
+ fi
963
+
964
if [ -d /etc/cron.daily ]; then
965
rm -f /etc/cron.daily/netdata-updater.sh
966
rm -f /etc/cron.daily/netdata-updater
979
}
980
981
enable_netdata_updater() {
965
- case "$(_get_scheduler_type)" in
982
+ local updater_type
983
+
984
+ if [ -z "${1}" ] ; then
985
+ updater_type="${1}"
986
+ else
987
+ updater_type="$(_get_scheduler_type)"
988
+ fi
989
+
990
+ case "${updater_type}" in
991
+ "systemd")
992
+ systemctl enable netdata-updater.timer
993
+
994
+ echo >&2 "Auto-updating has been enabled using a systemd timer unit."
995
+ echo >&2
996
+ echo >&2 "If the update process fails, the failure will be logged to the systemd journal just like a regular service failure."
997
+ echo >&2 "Successful updates should produce empty logs."
998
+ echo >&2
999
+ ;;
1000
"interval")
1001
ln -sf "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" "$(_get_intervaldir)/netdata-updater"
1002
1009
"crontab")
1010
cat "${NETDATA_SOURCE_DIR}/system/netdata.crontab" > "/etc/cron.d/netdata-updater"
1011
978
- echo >&2 "Auto-updating has been enabled through cron, using a crontab at ${TPUT_RED}${TPUT_BOLD}/etc/cron.d/netdata${TPUT_RESET}"
1012
+ echo >&2 "Auto-updating has been enabled through cron, using a crontab at ${TPUT_RED}${TPUT_BOLD}/etc/cron.d/netdata-updater${TPUT_RESET}"
1013
echo >&2
1014
echo >&2 "If the update process fails and you have email notifications set up correctly for cron on this system, you should receive an email notification of the failure."
1015
echo >&2 "Successful updates will not send an email."
1028
echo >&2 "You chose *NOT* to enable auto-update, removing any links to the updater from cron (it may have happened if you are reinstalling)"
1029
echo >&2
1030
1031
+ if issystemd && [ -n "$(get_systemd_service_dir)" ] ; then
1032
+ systemctl disable netdata-updater.timer
1033
+ fi
1034
+
1035
if [ -d /etc/cron.daily ]; then
1036
rm -f /etc/cron.daily/netdata-updater.sh
1037
rm -f /etc/cron.daily/netdata-updater