# 2011-10-12 Patrick Biber
# Version 0.1
# This Script Controlls der server.php script from the MOVERS project

LOG_FILE="/var/www/domains/southpolecarbon.com/movers-log/MOVERS-`date "+%A"`"

echo -e "Start MOVERS SERVER Controll Script (Zurich, `date "+%Y-%m-%d_%H:%M"`) ...\n" > $LOG_FILE

chown www-data $LOG_FILE
chmod 0770 $LOG_FILE

# server.php Aufruf

# Script Ueberwachungs-Schlaufe
MSERVER="`ps aux | grep server.php | grep -v grep`"
if [ "$MSERVER" == "" ]; then
# Falls ein MOVERS SERVER Script Fehler aufgetreten ist
su www-data "-c /usr/local/bin/startmoverphp.sh"
echo -e "\nRestarted MOVERS SERVER (Zurich, `date "+%Y-%m-%d_%H:%M"`) ..." >> $LOG_FILE
echo -e "\nserver.php Service was not running, the controll Script started it again" >> $LOG_FILE
echo -e "\nError mail to $OPERATOR ..." >> $LOG_FILE