Howto: Oscam watchdog
Oscam is capable of restarting its self on errors/seqfaults. But I wanted to make sure that Oscam is "REALLY" handling some traffic (doing its job properly).
And here comes the Oscam watchdog into play. The idea of the watchdog is quite simple.
If no successful ECM's are logged within a defined time frame, then the Oscam is started again.
Copyright:
All presented information and code is released under the terms of the GPL-v3 licence
Prerequisits:
- Oscam started with level 1 debugging option. Just look at the init script from the first howto.
Installation:
We are going to create two scripts. One is the Oscam watchdog daemon, that will run as a proccess under GNU-Linux.
and a init script for the Oscam watchdog.
touch /opt/oscam/bin/oscam.watchdog.sh
touch /opt/oscam/init/oscamwatchdog
chmod +x /opt/oscam/bin/oscam.watchdog.sh
chmod +x /opt/oscam/init/oscamwatchdog
ln -s /opt/oscam/init/oscamwatchdog /etc/init.d/
update-rc.d oscamwatchdog defaults
Copy the following code into "/opt/oscam/bin/oscam.watchdog.sh"
#!/bin/bash
# Restart/start oscam if we dont log any successful cw transactions within a defined time frame"
OSCAM_INSTANCE="$1"
CCCAM_INSTANCE=cccam.$(echo $OSCAM_INSTANCE|cut -d. -f2)
LOG_FILE="/opt/oscam/log/$OSCAM_INSTANCE.log"
CHECK_INTERVALL=60
DATE_STAMP_LAST_CW=start # Dont touch this
SCRIPTNAME="oscam.watchdog.sh"
CTR=0 # Dont touch this
MAX_RETRY=4
check_oscam( ){
DATE_STAMP_ACTUAL_CW=$(tail -n 1000 $LOG_FILE|grep "fail 0$"|tail -n 1|awk '{print $1 $2}')
if [ ! -z '$DATE_STAMP_ACTUAL_CW' ] ; then
if [ $DATE_STAMP_LAST_CW = 'start' ] ; then
DATE_STAMP_LAST_CW=$DATE_STAMP_ACTUAL_CW
CTR=0
fi
if [ '$DATE_STAMP_LAST_CW' = '$DATE_STAMP_ACTUAL_CW' ] ; then
DATE_STAMP_LAST_CW="$DATE_STAMP_ACTUAL_CW"
((CTR++))
if [ $CTR -gt $MAX_RETRY ] ; then
TIME_FRAME=$((${MAX_RETRY}*${CHECK_INTERVALL}))
logger -t $SCRIPTNAME "No successful cw transaction for $TIME_FRAME sec. Restarting $OSCAM_INSTANCE!"
service $OSCAM_INSTANCE stop > /dev/null 2>&1
sleep 2
service $OSCAM_INSTANCE start > /dev/null 2>&1
if [ -x /etc/init.d/$CCCAM_INSTANCE ] ; then
service $CCCAM_INSTANCE stop > /dev/null 2>&1
sleep 2
service $CCCAM_INSTANCE start > /dev/null 2>&1
fi
CTR=0
fi
else
DATE_STAMP_LAST_CW="$DATE_STAMP_ACTUAL_CW"
fi
else
((CTR++))
if [ $CTR -gt $MAX_RETRY ] ; then
TIME_FRAME=$((${MAX_RETRY}*${CHECK_INTERVALL}))
logger -t $SCRIPTNAME "No successful cw transaction for $TIME_FRAME sec. Restarting $OSCAM_INSTANCE!"
service $OSCAM_INSTANCE stop > /dev/null 2>&1
sleep 2
service $OSCAM_INSTANCE start > /dev/null 2>&1
if [ -x /etc/init.d/$CCCAM_INSTANCE ] ; then
service $CCCAM_INSTANCE stop > /dev/null 2>&1
sleep 2
service $CCCAM_INSTANCE start > /dev/null 2>&1
fi
CTR=0
fi
fi
}
if [ -z $OSCAM_INSTANCE ] ; then
echo "Error: No Oscam instance specified!"
logger -t $SCRIPTNAME "Error: No Oscam instance specified!"
echo "Please give an Oscam instance. Exiting!"
logger -t $SCRIPTNAME "Please give an Oscam instance. Exiting!"
exit 1
fi
if [ ! -x /etc/init.d/$OSCAM_INSTANCE ] ; then
echo "Error: No valid Oscam instance specified!"
logger -t $SCRIPTNAME "Error: No valid Oscam instance specified!"
echo "Please give a valid Oscam instance. Exiting!"
logger -t $SCRIPTNAME "Please give a valid Oscam instance. Exiting!"
exit 1
fi
while true; do
check_oscam
sleep $CHECK_INTERVALL
done
Display More
Copy the following code into "/opt/oscam/init/oscamwatchdog"
#!/bin/bash
OSCAM_SERVERS="oscam.hotbabe1 oscam.hotbabe2 oscam.hotbabe3"
#
OSCAM_WATCHDOG_DIR="/opt/oscam/bin"
OSCAM_WATCHDOG_BIN="oscam.watchdog.sh"
OSCAM_WATCHDOG_PROCESS_NAME="oscam.watchdog"
DEVNULL="/dev/null"
start_oscamwatchdog( ){
for i in $OSCAM_SERVERS; do
"$OSCAM_WATCHDOG_DIR"/"$OSCAM_WATCHDOG_BIN" $i &
done
}
stop_oscamwatchdog( ){
kill -9 $(ps aux|grep -v grep|grep "$OSCAM_WATCHDOG_BIN"|awk '{print $2}')
}
check_oscamwatchdog( ){
ps aux|grep -v grep|grep -q "$OSCAM_WATCHDOG_BIN"
}
case "$1" in
start)
if check_oscamwatchdog ; then
echo "$OSCAM_WATCHDOG_PROCESS_NAME allready running. Exiting!"
exit 1
else
echo "starting $OSCAM_WATCHDOG_PROCESS_NAME daemon!"
start_oscamwatchdog
exit 0
fi
;;
stop)
if check_oscamwatchdog ; then
echo "stopping "$OSCAM_WATCHDOG_PROCESS_NAME" daemon!"
stop_oscamwatchdog
exit 0
else
echo "$OSCAM_WATCHDOG_PROCESS_NAME is stopped. Exiting!"
exit 1
fi
;;
status)
if check_oscamwatchdog ; then
echo "$OSCAM_WATCHDOG_PROCESS_NAME is running!"
exit 0
else
echo "$OSCAM_WATCHDOG_PROCESS_NAME is stopped!"
exit 1
fi
;;
*)
N="/etc/init.d/oscamwatchdog"
echo "Usage: "$N" {start|stop|status}" >&2
exit 1
;;
esac
exit 0
Display More
Now you can start stop status the Oscam watchdog by running
Every time you add a new Oscam instance you have to add it to the variable "OSCAM_SERVERS" in "/opt/oscam/init/oscamwatchdog"
and stop and start the watchdog.
There are also the variables "CHECK_INTERVALL" and "MAX_RETRY" in "/opt/oscam/bin/oscam.watchdog.sh"
With "CHECK_INTERVALL=60" the watchdog will check every 60 sec. This is a reasonable values since it would not stress your system.
Decreasing this value will put more load on your system.
With "MAX_RETRY=4" you tell the wathdog to restart/start Oscam if no ECM's are seen after 4 minutes.
Higher values are better to avoid alot of disconnection/reconnection ... when you are connected to other servers.
Cheers!
All credit to copyleft from oscam.to