Subversion Repositories DevTools

Rev

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

#!/bin/sh
#
# Note: Solaris init.d scripts are run under a 'sh' shell at system startup
#       The above line has does not control this.
#       The script MUST be 'sh' complient

#set -x
BLATUSR=releasem
BLATBIN=/home/${BLATUSR}/blat
PID="${BLATBIN}/run/blat.pid"


ARG=$1
cd "$BLATBIN"

start () {
        echo Starting blat daemon now...
        SU="bash -c "
        [ "$USER" != "$BLATUSR" ] && SU="su - ${BLATUSR} -c "
        $SU "perl $BLATBIN/blat.pl -pid=$PID 2>/tmp/blat.log 1>&2"
}


stop () { 
        if [ -f $PID ]; then
                echo Stopping daemon now...
                kill `cat $PID`;
        else
                echo "No pidfile found (not running?)"
        fi
}

logrotate () {
        echo Triggering a logrotate
        kill -HUP `cat $PID`
}

#
#   Setup init levels
#   Linux and Solaris are different
#
setup() {
    if [ ! -f /etc/init.d/blatdaemon ] ; then
        echo "Error: /etc/init.d/blatdaemon 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/S80blatdaemon
            [ -f $file ] || ln -s /etc/init.d/blatdaemon $file
        done
        
        for ii in 0 1 6 ; do 
            file=/etc/rc.d/rc$ii.d/K30blatdaemon
            [ -f $file ] || ln -s /etc/init.d/blatdaemon $file
        done
        ;;
        
    SunOS)
        for ii in 2 3; do
            file=/etc/rc$ii.d/S80blatdaemon
            [ -f $file ] || ln -s /etc/init.d/blatdaemon $file
        done
        
        for ii in 0 1 S ; do 
            file=/etc/rc$ii.d/K30blatdaemon
            [ -f $file ] || ln -s /etc/init.d/blatdaemon $file
        done
        ;;
        
    *)
        echo "$0 setup - Unknown machine type: $mtype"
        exit 1
        ;;
    esac        
}


case $ARG in
        start)
                start
        ;;

        stop)
                stop
        ;;

        restart)
                stop
                start
        ;;

        logrotate)
                logrotate
        ;;
    
    setup)    
                setup
    ;;   

        *)
                echo "Usage: $0 <start|stop|restart|logrotate|setup>"
                exit 1
        ;;
esac