cccam-watchdog.sh
Verfasst: Sa 15. Okt 2011, 16:02
				
				Kann mir jemand erklären, wo der Unterschied ist in der cccam-watchdog.sh. Die Orginal im IPC drin ist
und der hier
die ist meine ich auch von hier
			Spoiler
Show
Code: Alles auswählen
#!/bin/bash
# IPC - CCcam-Watchdog
#
. /var/emu/script/functions.sh
readipccfg
[ -z $CCNAME ] && clear && echo -e "\033[1;31mVariablen Konfigurationsfehler!\033[0m" && exit 1
[ -z $CCVERSION ] && clear && echo -e "\033[1;31mVariablen Konfigurationsfehler!\033[0m" && exit 1
[ -z "$TIMESTAMP2" ] && clear && echo -e "\033[1;31mVariablen Konfigurationsfehler!\033[0m" && exit 1
[ -z $CAMLOGS ] && clear && echo -e "\033[1;31mVariablen Konfigurationsfehler!\033[0m" && exit 1
[ -z $CRASHMAIL ] && clear && echo -e "\033[1;31mVariablen Konfigurationsfehler!\033[0m" && exit 1
SUBJECT="$CCNAME Watchdog !"
MESSAGE1="$CCNAME wurde auf `hostname -f` vom Watchdog Überwachungsscript neu gestartet."
MESSAGE2="$CCNAME ist auf `hostname -f` mehrfach gestartet, Konfiguration scheint fehlerhaft zu sein!"
#CCcam gestart ?
PID="$(pgrep -x $CCVERSION)"
if [[ ! -z $PID ]] ; then
	echo "$TIMESTAMP2    Watchdog - CCcam Server laeuft"
else
	cccam start
	echo "$TIMESTAMP2    Watchdog - CCcam wurde neu gestartet" >> $CAMLOGS/CCcam-watchdog.log
	#readipccfg
	[ $CRASHMAIL == 1 ] && mailsend "$SUBJECT" "$MESSAGE1"
fi
#CCcam mehrfach gestartet ?
ANZAHL="$(pgrep -c $CCVERSION)"
if [ $ANZAHL -gt 1 ] ; then
	[ $CRASHMAIL == 1 ] && mailsend "$SUBJECT" "$MESSAGE2"
fi
exit 0Spoiler
Show
Code: Alles auswählen
#!/bin/bash
# IPC - CCcam-Watchdog
# v2
# Enable responding-check ? [1/0]
RESPONDCHECK="1"
# delay interval for lines sent (for responding check) [default: <empty>]
# NOTE: DON'T edit unless you know what you are doing!
# NOTE: if your CCcam-server runs on an 1xChip dbox its possible that the
# respond-check tooks too long for this script. Than you need to set
# this to '-i 3' or '-i 4'... it waits longer befor quit and fail...
NCINTERVAL="-i 1"
CCCAMIP="127.0.0.1"
# -------------------------------------------------------------- #
# >>> >> >  DO NOT MESS WiTH ANYTHiNG BELOW THiS LiNE!  < << <<< #
# -------------------------------------------------------------- #
. /var/emu/script/functions.sh
readipccfg
[ -z $CCNAME ] && clear && echo -e "\033[1;31mVariablen Konfigurationsfehler!\033[0m" && exit 1
[ -z $CCVERSION ] && clear && echo -e "\033[1;31mVariablen Konfigurationsfehler!\033[0m" && exit 1
[ -z "$TIMESTAMP2" ] && clear && echo -e "\033[1;31mVariablen Konfigurationsfehler!\033[0m" && exit 1
[ -z $CAMLOGS ] && clear && echo -e "\033[1;31mVariablen Konfigurationsfehler!\033[0m" && exit 1
[ -z $CRASHMAIL ] && clear && echo -e "\033[1;31mVariablen Konfigurationsfehler!\033[0m" && exit 1
[ -z $RESPONDCHECK ] && clear && echo -e "\033[1;31mVariablen Konfigurationsfehler!\033[0m" && exit 1
[ -z $CCCFG ] && clear && echo -e "\033[1;31mVariablen Konfigurationsfehler!\033[0m" && exit 1
CHECKFILE="/tmp/cccamtest.log"
WATCHDOGLOCK="/tmp/.CCcamWatchdog.lock"
SUBJECT="$CCNAME Watchdog!"
MESSAGE1="$CCNAME wurde auf `hostname -f` vom Watchdog Überwachungsscript neu gestartet"
MESSAGE2="$CCNAME ist auf `hostname -f` mehrfach gestartet, Konfiguration scheint fehlerhaft zu sein!"
proc_SendEMail() {
	msg=$1
	[ $CRASHMAIL != 1 ] && return
	mailsend "$SUBJECT" "$msg"
	echo "CrashEmail verschickt.."
}
# This method checks if CCcam is still responding like it should
check_respond() {
	proc_Get_CCcamcfg
	echo "$CCNAME process is present, now checking if its frozen.."
	echo info|nc $NCINTERVAL $CCCAMIP $CCTPORT >$CHECKFILE
	if [ "$?" != "0" ]; then
		echo "ERROR while connecting to $CCNAME!"
		proc_SendEMail "$CCNAME: Fehler beim verbinden für RespondCheck auf `hostname -f`!"
		proc_exit
	fi
	CHECKED=$(ls -s $CHECKFILE)
	if [ "$CHECKED" = "0" ]; then
		echo " BAD - $CCNAME is frozen, restarting: $CCVERSION"
		cccam restart
		MESSAGE1+=" weil es nicht mehr reagierte!"
		proc_SendEMail "$MESSAGE1"
	else
		echo " OK - $CCNAME is responding like it should!"
		# FixMe: output responding to shell if its triggered with: -v
		if [ "$1" = "-v" ]; then
			echo "$CCNAME responding:"
			echo $(cat $CHECKFILE)
		fi
	fi
}
# read CCcam.cfg
proc_Get_CCcamcfg() {
	CCTELNET=$(grep -i "ALLOW TELNETINFO" $CCCFG | cut -d ":" -f2 | sed -e 's/ //g' | sed -e 's/\r//g' | awk {'print $1'})
	CCTPORT=$(grep -i "TELNETINFO LISTEN PORT" $CCCFG | cut -d ":" -f2 | sed -e 's/ //g' | sed -e 's/\r//g')
	CCTUSER=$(grep -i "TELNETINFO USERNAME" $CCCFG | cut -d ":" -f2 | sed -e 's/ //g' | sed -e 's/\r//g')
	CCTPASS=$(grep -i "TELNETINFO PASSWORD" $CCCFG | cut -d ":" -f2 | sed -e 's/ //g' | sed -e 's/\r//g')
	[ "$CCTELNET" != "yes" ] && clear && echo -e "\033[1;31mKonfigurationsfehler! ALLOW TELNETINFO muss auf \"yes\" gestellt werden\033[0m" && proc_exit
	[ -z "$CCTPORT" -a "$CCTELNET" == "yes" ] && CCTPORT="16000"
}
proc_exit() {
	rm -f $WATCHDOGLOCK
	exit 0
}
## Script darf nur einmal gleichzeitig ausfuehren werden (innerhalb 1min)
if [ -e "$WATCHDOGLOCK" ]; then
	if [ "`find \"$WATCHDOGLOCK\" -type f -mmin -1`" ]; then
		echo "Lockfile $WATCHDOGLOCK exists and is not 1 minutes old yet. Quitting!"
		exit 0
	else
		echo "Lockfile exists, but its older then 1 minutes. Removing lockfile."
		touch "$WATCHDOGLOCK"
	fi
else
	touch "$WATCHDOGLOCK"
fi
#CCcam gestart?
PID="$(pgrep -x $CCVERSION)"
if [[ ! -z $PID ]] ; then
	echo "$TIMESTAMP2	 Watchdog - CCcam Server laeuft"
	[ $RESPONDCHECK == 1 ] && check_respond
else
	cccam start
	echo "$TIMESTAMP2	 Watchdog - CCcam wurde neu gestartet" >> $CAMLOGS/CCcam-watchdog.log
	proc_SendEMail "$MESSAGE1"
fi
#CCcam mehrfach gestartet?
ANZAHL="$(pgrep -c $CCVERSION)"
if [ $ANZAHL -gt 1 ] ; then
	proc_SendEMail "$MESSAGE2"
fi
proc_exit