jenkins 下linux 的jar 包启动和关闭脚本

下面的启动脚本是启动的main 类,也就是主函数; 主类的名字要从代码里面找,或者咨询开发人员。

#!/bin/bash

SERVER=/usr/local/installed/provider-kaoshi
export JAVA_HOME=/usr/local/java/jdk1.8

cd $SERVER
pid=`ps -ef | grep com.kunpengchina.exam.LuncherProvider | grep -v grep | tr -s " "|cut -d" " -f2 `

start()
{
if [ -n "$pid" ];then
    echo -e "fyt-exam-service  is already running (pid: $pid)"
else
    echo -e "Start fyt-exam-service...."
 cd $SERVER
nohup java   -Dfile.encoding=UTF-8 -classpath "lib/*:.:*"  com.kunpengchina.exam.LuncherProvider >$SERVER/kaoshi.log 2>&1  &
fi
}

status(){
if [ -n "$pid" ];then    
    echo -e "fyt-exam-service is running with pid: $pid"
  else    
    echo -e "fyt-exam-service  is not running"
  fi
}
stop(){
 if [ -n "$pid" ];then    
    kill -9 $pid  
    echo -e "stop complete"
  else    
    echo -e "fyt-exam-service is not running"    
  fi    
 
}
case $1 in start)
start;;
stop)
stop;;
restart)
stop

start;;

status)
status;;
*)
echo 'Usage: $0 {start,stop,status,restart}'
;;
esac

exit 0

或者参考http://blog.csdn.net/blueman2012/article/details/6915464

后记: 此脚本后面发现有时会出现jenkins 在调用的时候无法启动jar包,后面参考了网上的,找到一个比较靠谱的解决方法:

参考:http://blog.csdn.net/lsziri/article/details/70143638

添加

source /etc/profile

然后在命令执行的位置添加下面这行命令:BUILD_ID=dontKillMe
nohup java -jar app.jar > nohup.out & 2>&1 &
注意:source /etc/profile 如果没有,没有错误也不会有java执行的进程
增加 source /etc/profile 后不能直接使用nohup java -jar app.jar & 这时候Jenkins会打印app启动信息,不能很快完毕,甚至就不能完毕,以错误的信息结束,其实,server已经运行了

 
 



猜你喜欢

转载自blog.csdn.net/qq_39427835/article/details/79615181