#!/bin/sh
#$Id: fcgi_manage 29 2008-10-27 11:34:54Z valera $
# global data
PATH=${PATH}:/usr/sbin/:/usr/local/sbin/
ACTIONS="status start stop restart"
LOAD="L M H"
# sourcing config
CONFIG=_CONFIG_MACRO_
. ${CONFIG}
# sourcing common functions
. _FUNCS_MACRO_
# local function definitions
show_help() {
echo "Usage: $0 sitename {status|start|stop|restart}"
echo "Sites are: $HOSTS"
}
# getting list of hosts
HOSTS=$(get_hosts ${CONFIG})
# checking we've got valid number of args
if [ $# != 2 ]; then
show_help
exit 1
fi
# processing command args
HOST=$1
ACTION=$2
# script could be started using either using sudo -u root
# or from site specific fcgi user, so figuring it out
WHOAMI=$(/usr/bin/whoami)
USER=$(get_user $HOST)
if [ "$WHOAMI" = "$USER" ]; then
AS_ADMIN="No"
else
AS_ADMIN="Yes"
fi
# checking that valid host specified
match=1
for x in $HOSTS; do
if [ "X"$x = "X"$HOST ]; then
match=0
fi
done
if [ "$match" != "0" ] ; then
echo "Wrong hostname: $HOST"
show_help
exit 1
fi
# checking that valid action specified
match=1
for x in $ACTIONS; do
if [ "$x" = $ACTION ]; then
match=0
fi
done
if [ "$match" != "0" ] ; then
echo "Wrong action: $ACTION"
show_help
exit 1
fi
#actual job
case "$ACTION" in
start) host_start $HOST ;;
stop) host_stop $HOST ;;
status) host_status $HOST ;;
restart) host_restart $HOST ;;
esac