啟動腳本如下:
#!/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中
