#!/bin/sh

services="
    dhcpd
    asterisk
    astiumd
    astcfgd
    host_messenger
    android_agent
    ams_agent
    radiusd
"

case $1 in
    master)
        action=restart
        state=on
        /bin/chmod +x /usr/bin/astium-bb
    ;;
    backup)
        action=stop
        state=off
        /bin/chmod -x /usr/bin/astium-bb
    ;;
esac

echo "select requeue(1);" | psql -U astium

for service in $services; do
  /sbin/service "$service" "$action" &
done

wait

if [ -x /usr/local/astium/etc/failover.local ]; then
  /usr/local/astium/etc/failover.local
fi

for service in $services; do
  /sbin/chkconfig --level 345 "$service" "$state"
done

