summaryrefslogtreecommitdiff
blob: 1a875c93d3e08fbb4facea31740202d228466fd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
#
# Watchdog for OSCAM by 3PO

#set -x

# read variables
source /etc/conf.d/oscam


LOGDIR="/var/log/oscam"
LOGFILE="oscam_watchdog.log"
EXITLOG="$LOGDIR/exitlog_$(date +%F_%R).log"
OSCAMLOG="$LOGDIR/oscam.log"


[ ! -d "$LOGDIR" ] && mkdir $LOGDIR
LOG="${LOGDIR}/${LOGFILE}"

sleep 10

while sleep $CHECKTIME
do
	PID=`pidof $DAEMON`
	if [ -z "$PID" ] ; then
		echo "$(date) Error, ${DESCRIPTION} is not running" >> $LOG
		echo "$(date) Restarting ${DESCRIPTION} ..." >> $LOG
		tail -n50 $OSCAMLOG > $EXITLOG
		/etc/init.d/$DAEMON restart
		PID=`pidof $DAEMON`
		if [ -z "$PID" ] ; then
			echo "$(date) Error, while restarting ${DESCRIPTION}" >> $LOG
		else
			echo "$(date) ${DESCRIPTION} restarted" >> $LOG
		fi
	fi
done

exit 0