[379103]: src / mectl Maximize Restore History

Download this file

mectl    149 lines (133 with data), 3.0 kB

#!/bin/sh
#
#  File name:  S75mhive.system
#  Purpose:    Automatically starts MHiveSystemService on Linux/*nix when the
#              system starts
#  Author:     jan.hoelscher@esblab.com
#  Resides in: /etc/rc3.d
#
# chkconfig: 2345 80 30
# description: MHive Service

SELF=$0
echo $SELF
STATUS=-100
# check if self is a symlink
if [ -h $SELF  ]
then
    SELF=`ls -l $SELF | awk '{print $11}'`
    BASE_PATH=`dirname $SELF`/..
    if [ `uname` == Darwin ]
    then
        BASE_PATH=$BASE_PATH/..
    fi    
else

    if [ `expr index "$SELF" /` -gt 1 ]; then
        BASE_PATH=`pwd`/
    fi
    BASE_PATH=$BASE_PATH`dirname $SELF`/..
    cd $BASE_PATH
    BASE_PATH=`pwd`
fi
echo $BASE_PATH
MHIVE_BASE=$BASE_PATH

#when we are on a mac then all is installed into the Resource subdirectory
if [ `uname` == Darwin ]
then
    MHIVE_BASE=$MHIVE_BASE/Resources
    export DYLD_LIBRARY_PATH=$MHIVE_BASE/lib
    
fi

if [ ! -d /usr/bin ]
then                    # /usr not mounted
        exit
fi
prog="MHiveService"

#if [ $(id -u) != "0" ]
#then
#    echo "You must be root to run the configure script.  Login as root and then run the
#configure script."
#    exit 1
#fi

killproc() {            # kill the named process(es)
        pid=`ps x |
             grep -w $1 |
             grep -v grep |
             awk {'print $1'}`
             echo $pid
        [ "$pid" != "" ] && kill -15 $pid
}
unset COLUMNS
checkproc(){

    lsproc=$(ps xa |grep -E "$MHIVE_BASE"|grep -E $1 |grep -v grep|awk '{print $1}')
    echo $lsproc
    return $lsproc
}

usage(){
        echo "Usage: $0 { start | stop | configure | status}"
}

status_runtime(){
	if checkproc "mhiveservice"; then
	    echo "Mhive Runtime is OFF"
	    return 0
#      action $"Running $prog" /bin/false
	else
	    echo "Mhive CLuster Runtime is ON"
      return 1
#      action $"Running $prog" /bin/true
	fi
}

status_server(){
  false
}

start_server(){
#  LAST_DIR=`pwd`
  cd $MHIVE_BASE
    if status_runtime; then
      echo "starting mhive"
      #echo $MHIVE_BASE/bin/mhiveservice >$BASE_PATH/mhivetest
      mkdir $MHIVE_BASE/logs
      #$MHIVE_BASE/bin/mhive -r > $MHIVE_BASE/logs/startup.log&
      /usr/X11/bin/xterm -ls -e $MHIVE_BASE/bin/mhive -r&
      sleep 3
      open http://localhost:8080
      STATUS=$?
      else
        echo "MHive Service is allready running!"
        return
    fi
  status_runtime
#  cd $LAST_DIR
}
run_server(){
  exec $MHIVE_BASE/bin/mhive -r
}

stop_server(){
  killproc $MHIVE_BASE/bin/mhiveservice
  STATUS=$?
}


case "$1" in
    'start')
            # Start the MHive Runtime
            #
            start_server
            ;;
    'run')
            # Start the MHive Runtime
            #
            run_server
            ;;
    'stop')
            stop_server
            ;;
    'status')
            status_runtime
            ;;
    'install')
            # Start the MHive Runtime
            #
            exec $MHIVE_BASE/bin/mhive --install
            ;;
    *)
            start_server
            ;;
esac

exit 0