#!/bin/sh

cd ${0%${0##*/}}.

SERVER=/etc/init.d/bgbilling
SCHEDULER=/etc/init.d/bgscheduler
DATALOADER=/etc/init.d/bgdataloader
TEE=/usr/bin/tee
DATE=/bin/date

time=`${DATE} +%d_%H:%M:%S`

if [ -e ${DATALOADER} ]; then
    echo "# Stopping DataLoader"
    ${DATALOADER} stop
fi
echo "# Stopping Scheduler"
${SCHEDULER} stop
echo "# Stopping Server"
${SERVER} stop
echo "# Start Updating"
 ./bg_installer.sh update | ${TEE} ./log_update_${time}
echo "# Starting Server"
${SERVER} start
echo "# Starting Scheduler"
${SCHEDULER} start
if [ -e ${DATALOADER} ]; then
    echo "# Starting DataLoader"
    ${DATALOADER} start
fi