nohup
java -jar xxxxxx.jar > catalina.out 2>&1 &
参数解释:
nohup :
意思就是不挂断运行
,没此参数挂断连接会停止程序
>contro_log.out :
意思就是将标准输出重定向到了 ./contro_log.out
2>&1 :
意思就是将标准错误重定向到标准输出。这里标准输出已经重定向到了 ./contro_log.out
,那么标准错误也会输出到./contro_log.out
& :后台运行
附上启动脚本代码:
#!/bin/sh
RESOURCE_NAME=xxxx-1.0-SNAPSHOT.jar
RESOURCE_LOCATION=/home/myapp
bootApp
stop(){
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo '-->Stopping Process...'
kill -15 $tpid
fi
sleep 5
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo '-->Killing Process!'
kill -9 $tpid
else
echo '-->Stop application successful!'
fi
rm -f tpid
}
start(){
echo 'Starting application ['$RESOURCE_NAME']...'
nohup java -Xms256m -Xmx2048m -XX:PermSize=32m -XX:MaxPermSize=256m -jar $RESOURCE_LOCATION/$RESOURCE_NAME > catalina.out 2>&1 &
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ];then
echo '-->PID['${tpid}'],App started success...'
else
echo '-->App started failed...'
fi
rm -f tpid
}
bootApp(){
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'App was started'
stop
start
else
echo 'App was Stopped'
start
fi
}