#!/bin/sh
# chkconfig: 2345 99 19
# description: as following
# CVS $Id: wxc2d,v 1.1 2002/11/16 12:00:00 LiangHB Exp $
# Startup processes relative with app function

if [ `whoami` != "root" ] ; then
	echo "Permission denied! Only user root supported!"
	exit
fi
PATH=/usr/sbin:/usr/local/bin:/bin:/usr/bin    ; export PATH
basedir=/usr/local/wxc2
bindir=$basedir/bin
WXC2_BIN_DIR=/usr/local/wxc2/bin   ;    export WXC2_BIN_DIR
LOG_FILE_PATH=$basedir/log       ;    export LOG_FILE_PATH

KILL_LEVEL=15

SERVICE_ALL="wxc2main"

. /etc/rc.d/init.d/functions


case "$1" in
  'start')
    # Start daemon
            backupMB=`du -m /usr/local/backup |awk '{print $1}'`
	    if [ $backupMB -gt 90 ] ; then
		backupMB=90
	    fi
	    freeDiskMB=`df -m  /usr|grep dev|awk '{print $4}'`
	    MinMB=`expr 150 "-" $backupMB`
            echo "There are $freeDiskMB M available in /usr"
            if [ $freeDiskMB -lt $MinMB ] ; then
                echo "mss need $MinMB m disk space at least,No enough space in /usr !!"
                df -h
                exit
            fi



    crontab -u root /usr/local/wxc2/tools/cronset
    cd $bindir

      SERVICE_NAME=wxc2main
      echo -n "Starting $SERVICE_NAME service:"
      ./$SERVICE_NAME -d 2>/dev/null 
      echo
    ;;
  'stop')
    # Stop daemon
             backupMB=`du -m /usr/local/backup |awk '{print $1}'`
	    if [ $backupMB -gt 90 ] ; then
		backupMB=90
	    fi
	    freeDiskMB=`df -m  /usr|grep dev|awk '{print $4}'`
	    MinMB=`expr 150 "-" $backupMB`
            echo "There are $freeDiskMB M available in /usr"
            if [ $freeDiskMB -lt $MinMB ] ; then
                echo "mss need $MinMB m disk space at least,No enough space in /usr !!"
                df -h
                exit
            fi

   crontab -r 
    SERVICE_NAME=wxc2main
    echo -n "Shutting down $SERVICE_NAME service:"
    killproc $SERVICE_NAME -$KILL_LEVEL
    echo
    sleep 2
    ;;
  'status')
    # get status of daemon

    SERVICE_NAME=wxc2main
    status $SERVICE_NAME
    ;;
  *)
    # usage
    echo "usage: $0 start|stop|status"
    exit 1
    ;;
esac
