898
fi
899
}
900
901
-_get_crondir() {
901
+_get_scheduler_type() {
902
+ if _get_intervaldir > /dev/null ; then
903
+ echo 'interval'
904
+ elif [ -d /etc/cron.d ] ; then
905
+ echo 'crontab'
906
+ else
907
+ echo 'none'
908
+ fi
909
+}
910
+
911
+_get_intervaldir() {
912
if [ -d /etc/cron.daily ]; then
913
echo /etc/cron.daily
914
elif [ -d /etc/periodic/daily ]; then
915
echo /etc/periodic/daily
916
else
907
- echo >&2 "Cannot figure out the cron directory to handle netdata-updater.sh activation/deactivation"
908
- return 1
909
- fi
910
-
911
- return 0
912
-}
913
-
914
-_check_crondir_permissions() {
915
- if [ "${UID}" -ne "0" ]; then
916
- # We cant touch cron if we are not running as root
917
- echo >&2 "You need to run the installer as root for auto-updating via cron"
917
return 1
918
fi
919
944
rm -f "${NETDATA_PREFIX}"/usr/libexec/netdata-updater.sh
945
fi
946
948
- crondir="$(_get_crondir)" || return 1
949
- _check_crondir_permissions "${crondir}" || return 1
947
+ if [ -d /etc/cron.daily ]; then
948
+ rm -f /etc/cron.daily/netdata-updater.sh
949
+ rm -f /etc/cron.daily/netdata-updater
950
+ fi
951
951
- if [ -f "${crondir}/netdata-updater.sh" ]; then
952
- echo >&2 "Removing incorrect netdata-updater filename in cron"
953
- rm -f "${crondir}/netdata-updater.sh"
952
+ if [ -d /etc/periodic/daily ]; then
953
+ rm -f /etc/periodic/daily/netdata-updater.sh
954
+ rm -f /etc/periodic/daily/netdata-updater
955
+ fi
956
+
957
+ if [ -d /etc/cron.d ]; then
958
+ rm -f /etc/cron.d/netdata-updater
959
fi
960
961
return 0
962
}
963
964
enable_netdata_updater() {
960
- crondir="$(_get_crondir)" || return 1
961
- _check_crondir_permissions "${crondir}" || return 1
962
-
963
- echo >&2 "Adding to cron"
964
-
965
- rm -f "${crondir}/netdata-updater"
966
- ln -sf "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" "${crondir}/netdata-updater"
967
-
968
- echo >&2 "Auto-updating has been enabled. Updater script linked to: ${TPUT_RED}${TPUT_BOLD}${crondir}/netdata-updater${TPUT_RESET}"
969
- echo >&2
970
- echo >&2 "${TPUT_DIM}${TPUT_BOLD}netdata-updater.sh${TPUT_RESET}${TPUT_DIM} works from cron. It will trigger an email from cron"
971
- echo >&2 "only if it fails (it should not print anything when it can update netdata).${TPUT_RESET}"
972
- echo >&2
965
+ case "$(_get_scheduler_type)" in
966
+ "interval")
967
+ ln -sf "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" "$(_get_interval_dir)/netdata-updater"
968
+
969
+ echo >&2 "Auto-updating has been enabled through cron, updater script linked to ${TPUT_RED}${TPUT_BOLD}$(_get_interval_dir)/netdata-updater${TPUT_RESET}"
970
+ echo >&2
971
+ 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."
972
+ echo >&2 "Successful updates will not send an email."
973
+ echo >&2
974
+ ;;
975
+ "crontab")
976
+ cat "${NETDATA_SOURCE_DIR}/system/netdata.crontab" > "/etc/cron.d/netdata-updater"
977
+
978
+ echo >&2 "Auto-updating has been enabled through cron, using a crontab at ${TPUT_RED}${TPUT_BOLD}/etc/cron.d/netdata${TPUT_RESET}"
979
+ echo >&2
980
+ 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."
981
+ echo >&2 "Successful updates will not send an email."
982
+ echo >&2
983
+ ;;
984
+ *)
985
+ echo >&2 "Unable to determine what type of auto-update scheduling to use, not enabling auto-updates."
986
+ echo >&2
987
+ return 1
988
+ esac
989
990
return 0
991
}
992
993
disable_netdata_updater() {
978
- crondir="$(_get_crondir)" || return 1
979
- _check_crondir_permissions "${crondir}" || return 1
980
-
994
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)"
995
echo >&2
996
984
- if [ -f "${crondir}/netdata-updater" ]; then
985
- echo >&2 "Removing cron reference: ${crondir}/netdata-updater"
986
- echo >&2
987
- rm -f "${crondir}/netdata-updater"
988
- else
989
- echo >&2 "Did not find any cron entries to remove"
990
- echo >&2
997
+ if [ -d /etc/cron.daily ]; then
998
+ rm -f /etc/cron.daily/netdata-updater.sh
999
+ rm -f /etc/cron.daily/netdata-updater
1000
+ fi
1001
+
1002
+ if [ -d /etc/periodic/daily ]; then
1003
+ rm -f /etc/periodic/daily/netdata-updater.sh
1004
+ rm -f /etc/periodic/daily/netdata-updater
1005
+ fi
1006
+
1007
+ if [ -d /etc/cron.d ]; then
1008
+ rm -f /etc/cron.d/netdata-updater
1009
fi
1010
1011
return 0