#!/bin/bash
# chkconfig: 3333 80 20
# description: Maachang Comet Server...
################################################################################
# startup(Linux) maachangComet.
#
# Copyright (c) 2007 masahito suzuki, Inc. All Rights Reserved.
################################################################################

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

# target directory.
EXECUTION_USER=
JAVA_HOME=
MAACHANG_COMET=
TARGET_DIR=
MSTART=${MAACHANG_COMET}/sh/mserver
MEND=${MAACHANG_COMET}/sh/mdown

mstartup() {
    if [ -f ${MSTART} ]; then
        echo "*** Starting maachang comet (~o~)//"
        su - ${EXECUTION_USER} -c "export JAVA_HOME=${JAVA_HOME}; \
            export MAACHANG_COMET=${MAACHANG_COMET};\
            cd ${TARGET_DIR}; ${MSTART} > /dev/null &"
    fi
    return 1
}

mshutdown() {
    if [ -f ${MEND} ]; then
        echo "*** Shutdown maachang comet (^^)"
        su - ${EXECUTION_USER} -c "export JAVA_HOME=${JAVA_HOME}; \
            export MAACHANG_COMET=${MAACHANG_COMET};\
            cd ${TARGET_DIR}; ${MEND}"
    fi
    return 1
}

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

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