guess HAVE_EPOLL
[l2tpns.git] / scripts / l2tpns-monitor
1 #!/bin/sh
2 stopfile=/tmp/l2tpns.stop
3 first=`date +%s`
4 min_first_time=3
5 restart_delay=5
6 prog=${0##*/}
7
8 while :
9 do
10         echo "`date`: Starting l2tpns $@"
11         start=`date +%s`
12         /usr/sbin/l2tpns ${1+"$@"}
13         RETVAL=$?
14         stop=`date +%s`
15         t=$(($stop - $start));
16         first=$(($stop - $first));
17         echo "`date`: l2tpns exited after $t seconds, status $RETVAL"
18         if [ $first -lt $min_first_time ]; then
19                 echo "`date`: l2tpns exited immediately, $prog exiting"
20                 exit $RETVAL
21         fi
22         if [ -f $stopfile ]; then
23                 ls -l $stopfile
24                 echo "`date`: stop file found, $prog exiting"
25                 exit
26         fi
27         sleep $restart_delay
28 done >>/var/log/$prog 2>&1      &       # execute in background