#!/bin/bash
# chkconfig: 3332 80 20
# description: Maachang Proxy Server...
################################################################################
# startup(centos) maachangProxy[script].
#
# Copyright (c) 2008 masahito suzuki, Inc. All Rights Reserved.
################################################################################

# Source function library.
. /etc/rc.d/init.d/functions

# target directory.
EXECUTION_USER=
JAVA_HOME=
MAACHANG_PROXY=
TARGET_DIR=
MSTART=${MAACHANG_PROXY}/sh/mproxy
MEND=${MAACHANG_PROXY}/sh/mproxys

mstartup() {
    if [ -f ${MSTART} ]; then
        echo "*** Starting maachang proxy (@v@)//"
        su - ${EXECUTION_USER} -c "export JAVA_HOME=${JAVA_HOME}; \
            export MAACHANG_PROXY=${MAACHANG_PROXY};\
            cd ${TARGET_DIR}; ${MSTART} > /dev/null &"
    fi
}

mshutdown() {
    if [ -f ${MEND} ]; then
        echo "*** Shutdown maachang proxy (XoX)"
        su - ${EXECUTION_USER} -c "export JAVA_HOME=${JAVA_HOME}; \
            export MAACHANG_PROXY=${MAACHANG_PROXY};\
            cd ${TARGET_DIR}; ${MEND}"
    fi
}

case "$1" in
'start')
        mstartup
        ;;
'stop')
        mshutdown
        ;;

'restart')
        mshutdown
        mstartup
        ;;
*)
        echo "Usage: $0 {start stop restart}"
        ;;
esac
exit 0
