1
0
Fork 0

Scripts to check and restart kresd if it does not respond

This commit is contained in:
Luca Beltrame 2022-06-05 22:41:30 +02:00
parent 029201da1e
commit 7dcb836a25
Signed by: einar
GPG key ID: 4707F46E9EC72DEC
3 changed files with 112 additions and 0 deletions

7
sysadmin/dnscheck.config Normal file
View file

@ -0,0 +1,7 @@
# Place this in /etc/config/dnscheck
config setup 'check_service'
option host 'CHANGEME'
option server '127.0.0.1'
option timeout '5'
option maxfailures '3'

41
sysadmin/dnscheck.init Normal file
View file

@ -0,0 +1,41 @@
#!/bin/sh /etc/rc.common
#
# start dnscheck
#
# https://openwrt.org/docs/guide-developer/procd-init-script-example
# Init sequence
START=99
STOP=10
# PROCD
USE_PROCD=1
start_service() {
procd_open_instance dnscheck
procd_set_param command /bin/sh "/usr/lib/dnscheck/dnscheck.sh"
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
procd_set_param stdout 1 # forward stdout of the command to logd
procd_set_param stderr 1 # same for stderr
procd_set_param pidfile /var/run/dnscheck.pid
procd_close_instance
}
stop_service() {
logger -t "dnscheck" "kresd monitoring stopped"
}
service_triggers()
{
procd_add_reload_trigger "dnscheck"
}
reload_service()
{
stop
start
}

View file

@ -0,0 +1,64 @@
# Checks DNS and restarts kresd if necessary
# check prerequisites
. /lib/functions.sh
if [ ! -x "$(command -v host)" ]; then
echo 'dnscheck error: host is not installed, exiting' >&2
exit 1
fi
perform_check() {
local host
local server
local timeout
local maxfailures
local failure=0
config_get host check_service host "CHANGEME"
config_get server check_service server "10.64.0.1"
config_get timeout check_service timeout "5"
config_get maxfailures check_service maxfailures "3"
# check DNS
host -w "${timeout}" "${host}" "${server}" &> /dev/null
if [ $? -ne 0 ]; then
failure=1
logger -p err -t "dnscheck" "kresd failed to respond, ${failcount} of ${maxfailures}"
let "failcount++"
else
if [ $failcount -ge 0 ]; then
logger -p info -t "dnscheck" "kresd is responding again"
fi
failcount=0
fi
if [ $failcount -ge $maxfailures ]; then
failcount=0
logger -p err -t "dnscheck" "kresd not responding, restarting"
# restart service
/etc/init.d/resolver restart
fi
return $failure
}
# read configuration
config_load dnscheck
# check loop
logger -p info -t "dnscheck" "Starting kresd monitoring"
failcount=0
while sleep 10; do
perform_check ${job}
if [ $? -ne 0 ]; then
logger -p err -t "dnscheck" "kresd did not respond and was restarted"
fi
done
exit 0