我有一个用于启动/停止/等 JBoss AS (v7.1.1) 的脚本。我在 SUSE Enterprise 11 上运行,所以提供的 initscript 不起作用。我的脚本遇到的问题是清理函数永远不会被调用。
#!/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