Skip to content

Commit

Permalink
implemented a config file based evaluation of the interval time so th…
Browse files Browse the repository at this point in the history
…at our config website is able to allow users to define the execution interval of hm-watchdog.
  • Loading branch information
jens-maus committed Jun 24, 2016
1 parent 64a92d0 commit f56b2f8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
20 changes: 16 additions & 4 deletions rc.d/hm-watchdog
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@ WWWDIR=/usr/local/etc/config/addons/www/${ADDONNAME}
RCDDIR=/usr/local/etc/config/rc.d

start() {
# add our cronjob definitions so that hm-watchdog is executed
# every minute
if ! grep -Fq "${ADDONDIR}/bin/hm-watchdog.sh" /usr/local/crontabs/root; then
(crontab -l ; echo "*/3 * * * * ${ADDONDIR}/bin/hm-watchdog.sh 2>&1 >/dev/null") 2>&1 | grep -v "no crontab" | sort | uniq | crontab -
# lets source in the config
if [ -e ${ADDONDIR}/etc/hm-watchdog.conf ]; then
source ${ADDONDIR}/etc/hm-watchdog.conf
else
HM_WATCHDOG_INTERVAL=3
fi

# add or remove our cronjob definitions so that hm-watchdog is executed
# every three minutes
if [ $HM_WATCHDOG_INTERVAL -gt 0 ]; then
if ! grep -Fq "${ADDONDIR}/bin/hm-watchdog.sh" /usr/local/crontabs/root; then
(crontab -l ; echo "*/${HM_WATCHDOG_INTERVAL} * * * * ${ADDONDIR}/bin/hm-watchdog.sh 2>&1 >/dev/null") 2>&1 | grep -v "no crontab" | sort | uniq | crontab -
fi
else
# remove all cronjob occurances regarding hm-watchdog
(crontab -l) 2>&1 | grep -v "no crontab" | grep -v "${ADDONDIR}/bin/hm-watchdog.sh" | sort | uniq | crontab -
fi
}

Expand Down
7 changes: 7 additions & 0 deletions update_script
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,19 @@ fi
touch /usr/local/etc/config/hm_addons.cfg
${ADDON_DIR}/bin/update_addon hm-watchdog ${ADDON_DIR}/etc/hm-watchdog-addon.cfg

# copy over the default hm-watchdog.conf_default config file
# in case the user hasn't already an own one
if [ ! -e ${ADDON_DIR}/etc/hm-watchdog.conf ]; then
cp -af ${ADDON_DIR}/etc/hm-watchdog.conf_default ${ADDON_DIR}/etc/hm-watchdog.conf
fi

# copy over the default notify.rega_default script
# in case the user hasn't already an own one
if [ ! -e ${ADDON_DIR}/etc/notify.rega ]; then
cp -af ${ADDON_DIR}/etc/notify.rega_default ${ADDON_DIR}/etc/notify.rega
fi


# synchronize filesystem before performing a reboot
# afterwards
sync
7 changes: 6 additions & 1 deletion www/settings/inc/settings.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ proc loadConfigFile { } {
}

if { [ catch {
set HM_WATCHDOG_INTERVAL [exec crontab -l | grep /usr/local/addons/hm-watchdog/bin/hm-watchdog.sh | grep -v grep | cut -f1 -d { } | cut -f2 -d {/}]
set HM_WATCHDOG_INTERVAL [exec grep HM_WATCHDOG_INTERVAL /usr/local/addons/hm-watchdog/etc/hm-watchdog.conf | grep -v grep | cut -f2 -d {=}]
} err ] } {
set HM_WATCHDOG_INTERVAL "0"
}
Expand All @@ -100,6 +100,11 @@ proc saveConfigFile { } {
puts $fd $HM_WATCHDOG_NOTIFY
close $fd

# save the interval value to our config file
set fd [open /usr/local/addons/hm-watchdog/etc/hm-watchdog.conf w]
puts $fd HM_WATCHDOG_INTERVAL=$HM_WATCHDOG_INTERVAL
close $fd

# we have updated our configuration so lets
# stop/restart hm-watchdog
if { $HM_WATCHDOG_INTERVAL == 0 } {
Expand Down

0 comments on commit f56b2f8

Please sign in to comment.