Subversion Repositories DevTools

Rev

Rev 894 | Rev 3840 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/bin/sh
#set -x
#
# Start, stop buildtool
#
# Note: This must be a 'sh' compatible script
#       Solaris8 uses sh to source the script. It is not run at startup
#
# Note: This file should be installed into /etc/init.d
#
# Note: Use /etc/init.d/buildtool setup
#        to perform additional setup of adding files to setup sequence
#

pid=0
#pid null if not running, pid if running
check_running() {
        pid=`ps -fe|grep java|grep abtdD.jar|awk '{print $2}'`
}

#
# Start daemons.
#
start() {
    check_running
    if [ "$pid" ]; then
          echo 'running'
    else
          echo 'starting'
          su - buildadm -c 'source /etc/profile;unset GBE_PLATFORM;jats -NoExportVars eprog /home/buildadm/buildtool/abtlaunch 2>/tmp/buildtool 1>&2' &
    fi
}

#
# Stop daemons.
#
stop() {
    check_running
    echo "check_running returned $pid"

    if [ "$pid" ]; then
        for kpid in $pid ; do
            echo "killing $kpid"
            kill -9 $kpid 2>/dev/null 1>&2
        done
    else
        echo 'not running'
    fi
}

#
#   Status the daemons
#
status() {
    check_running

    if [ "$pid" ]; then
          echo 'buildtool running'
    else
          echo 'buildtool not running'
    fi
}

#
#   Setup init levels
#   Linux and Solaris are different
#
setup() {
    if [ ! -f /etc/init.d/buildtool ] ; then
        echo "Error: /etc/init.d/buildtool does not exist"
        exit 1
    fi

    mtype=`uname`
    case "$mtype" in
    Linux)
        for ii in 2 3 4 5; do
            file=/etc/rc.d/rc$ii.d/S80buildtool
            [ -f $file ] || ln -s /etc/init.d/buildtool $file
        done
        
        for ii in 0 1 6 ; do 
            file=/etc/rc.d/rc$ii.d/K30buildtool
            [ -f $file ] || ln -s /etc/init.d/buildtool $file
        done
        ;;
        
    SunOS)
        for ii in 2 3; do
            file=/etc/rc$ii.d/S80buildtool
            [ -f $file ] || ln -s /etc/init.d/buildtool $file
        done
        
        for ii in 0 1 S ; do 
            file=/etc/rc$ii.d/K30buildtool
            [ -f $file ] || ln -s /etc/init.d/buildtool $file
        done
        ;;
        
    *)
        echo "$0 setup - Unknown machine type: $mtype"
        exit 1
        ;;
    esac        
}

#
#   Determine user command
#
case "$1" in
  start)    setup
            start
            ;;
  stop)     stop
            ;;
  status)   status
            RETVAL=$?
            ;;  
  restart)  stop
            start
            ;;
  setup)    setup
            ;;   
  *)        echo "Usage: $0 {start|stop|restart|status|setup}"
            exit 1
            ;;
esac

exit $RETVAL