#!/bin/sh # simple shell script for FreeBSD to demote local carp announcements if # a daemon is not running # # crontab: # * * * * * exec /root/watchdog.sh $NAME_OF_DAEMON # # e.g.: # * * * * * exec /root/watchdog.sh httpd # # To prevent carp from taking over during system boot, add this # to /etc/sysctl.conf: # net.inet.carp_demotion=150 PATH=/usr/bin:/bin:/usr/sbin:/sbin DAEMON="$1" LOCKFLAG="$2" if [ -z "$DAEMON" ]; then echo "usage: watchdog.sh " >&2 exit 1 fi if [ -z "$LOCKFLAG" ]; then exec lockf -ks -t 0 "/var/run/watchdog.$DAEMON.lock" "$0" "$DAEMON" x exit 1 fi OID="net.inet.carp.demotion" set_demotion () { local target target=$1 current=`sysctl -n "$OID"` delta=$((target-current)) if [ $delta -ne 0 ]; then sysctl -q "$OID=$delta" | logger -t "watchdog.sh/$DAEMON" fi } trap 'set_demotion 150; exit' 1 2 3 4 5 6 7 8 10 11 12 13 14 15 while true; do target=0 pgrep -q "$DAEMON" || target=150 set_demotion $target sleep 3 done