Question

I have a script that I'm making to use to start/stop/etc a JBoss AS (v7.1.1). I'm running on SUSE Enterprise 11, so the provided initscript doesn't work. The problem I'm running into with my script is that the cleanup function is never called.

#!/bin/sh

HOME="/var/rulesserver"
CURRENT=$HOME/logs/current
LOGFILE=$HOME/logs/`date -u +%Y-%m-%d-%H-%M-%S`.log
COMMAND=/usr/local/jboss/bin/standalone.sh
SELF=/usr/sbin/jboss-as-standalone

function cleanup() {
    rm $CURRENT
}

function run() {
    trap cleanup 1 2 3 6 15
    nohup $COMMAND &> $CURRENT
}

case $1 in
    "start" )
        echo "Starting the server..."
        if [ -e $CURRENT ]
        then
            echo "ERROR: The server is already running"
        else
            ln -s $LOGFILE $CURRENT
            run &
            echo "Server started"
        fi
        ;;
    "stop" )
        echo "Stopping the server..."
        killall java
        echo "Server stopped"
        ;;
    "status" )
        if [ -e $CURRENT ]
        then
            echo "The server is currently running"
        else
            echo "The server is currently stopped"
        fi
        ;;
    "cleanup" )
        cleanup
        ;;
    "restart" )
        $SELF stop
        $SELF start
        ;;
    * )
        $SELF start
        ;;
esac
Était-ce utile?

La solution

I may be confused, but can you not just do

function run() {
    ( nohup $COMMAND ; rm $CURRENT )
}

?

$COMMAND would block till i dies and then there would be an rm and then the subshell would exit? There would be no need for trap.

Autres conseils

There is a method provided in the standalone.sh startup script that you can use to control it's behavior. Just set the value of environment variable LAUNCH_JBOSS_IN_BACKGROUND to some value, ie.

LAUNCH_JBOSS_IN_BACKGROUND=true

before calling the script and then you will no longer need nohup to do the job for you, and no cleanup will be necessary.

Also, there is an option to tell JBoss AS to write the "console output" to a file, so you can still have the messages that it will be generating.

One more thing: I personally do not think that killall java is 100% clever thing to do in all the possible circumstances.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top