2011-07-26 20:28:49 +02:00
#!/bin/sh
2011-07-11 18:56:29 +02:00
#This script ensures that ep-lite is automatically restarting after an error happens
#Handling Errors
# 0 silent
# 1 email
ERROR_HANDLING = 0
# Your email address which should recieve the error messages
EMAIL_ADDRESS = "no-reply@example.com"
# Sets the minimun amount of time betweens the sending of error emails.
# This ensures you not get spamed while a endless reboot loop
# It's the time in seconds
TIME_BETWEEN_EMAILS = 600 # 10 minutes
# DON'T EDIT AFTER THIS LINE
LAST_EMAIL_SEND = 0
2013-05-26 23:06:15 +02:00
LOG = " $1 "
2011-07-11 18:56:29 +02:00
#Move to the folder where ep-lite is installed
2011-08-03 23:08:27 +02:00
cd ` dirname $0 `
2011-07-11 18:56:29 +02:00
#Was this script started in the bin folder? if yes move out
if [ -d "../bin" ] ; then
cd "../"
fi
#check if a logfile parameter is set
2013-05-26 23:06:15 +02:00
if [ -z " ${ LOG } " ] ; then
2011-07-11 18:56:29 +02:00
echo "Set a logfile as the first parameter"
exit 1
fi
while [ 1 ]
do
#try to touch the file if it doesn't exist
2013-05-26 23:06:15 +02:00
if [ ! -f ${ LOG } ] ; then
touch ${ LOG } || ( echo " Logfile ' ${ LOG } ' is not writeable " && exit 1 )
2011-07-11 18:56:29 +02:00
fi
#check if the file is writeable
2013-05-26 23:06:15 +02:00
if [ ! -w ${ LOG } ] ; then
echo " Logfile ' ${ LOG } ' is not writeable "
2011-07-11 18:56:29 +02:00
exit 1
fi
#start the application
2013-05-26 23:06:15 +02:00
shift
bin/run.sh $@ >>${ LOG } 2>>${ LOG }
2011-07-11 18:56:29 +02:00
#Send email
2011-07-26 20:28:49 +02:00
if [ $ERROR_HANDLING = 1 ] ; then
2011-07-11 18:56:29 +02:00
TIME_NOW = $( date +%s)
TIME_SINCE_LAST_SEND = $(( $TIME_NOW - $LAST_EMAIL_SEND ))
if [ $TIME_SINCE_LAST_SEND -gt $TIME_BETWEEN_EMAILS ] ; then
2013-05-26 23:06:15 +02:00
printf " Server was restared at: $( date) \nThe last 50 lines of the log before the error happens:\n $( tail -n 50 ${ LOG } ) " | mail -s "Pad Server was restarted" $EMAIL_ADDRESS
2011-07-11 18:56:29 +02:00
LAST_EMAIL_SEND = $TIME_NOW
fi
fi
2013-05-26 23:06:15 +02:00
echo "RESTART!" >>${ LOG }
2011-07-11 18:56:29 +02:00
#Sleep 10 seconds before restart
sleep 10
done