启动脚本如下:
#!/bin/bash echo "Shell start ....." DEPLOY_PATH=/wls/wls81/pmfJbossserver/jboss-as-7.1.1.Final JENKINS_PATH=/wls/wls81/tools/workspace/pmf_dev/pmf-web/target APP_NAME=pmf-web.war echo "shell:kill jboss....." PID_USE=`ps aux | grep java | grep $DEPLOY_PATH | grep -v grep | awk '{print $2}'|xargs` if [ -n "$PID_USE" ]; then kill -9 $PID_USE sleep 9 else echo "pid no" fi rm -rf $DEPLOY_PATH/standalone/deployments/* cp $JENKINS_PATH/$APP_NAME $DEPLOY_PATH/standalone/deployments/$APP_NAME rm -rf $DEPLOY_PATH/bin/nohup.out nohup $DEPLOY_PATH/bin/standalone.sh > $DEPLOY_PATH/bin/nohup.out 2>&1 & tail -f $DEPLOY_PATH/bin/nohup.out ~
详解:
1、grep java | grep $DEPLOY_PATH 只查询含java和DEPLOY_PATH的进程
2、grep -v grep 反向过滤掉grep的进程
3、awk '{print $2}' 选取第二列
4、xargs 列转行
5、if [ -n "$PID_USE" ]; then 判断PID_USE是否为空
6、$DEPLOY_PATH/bin/nohup.out 2>&1:.其中0 表示键盘输入,1表示屏幕输出,2表示错误输出。把标准出错重定向到标准输出,然后输入到nohup.out中