Linux 启动jar脚本 记录
1 停止服务 stop.sh
#!/bin/bash t_name="resource-management-server-1.0.0.jar" function getPID(){ PID=`ps -ef | grep $t_name | grep -v grep |grep java| awk -F ' ' '{print $2}'` echo $PID } PID=`getPID` if [ "x$PID" = "x" ];then echo "$t_name is not running." else kill -9 $PID NPID=`getPID` if [ "x$NPID" != "x" ];then echo "fail to stop $t_name" else echo "Success stop $t_name, PID is $PID." fi fi
t_name 后面为 jar包名称。可替换
启动命令为 bash stop.sh 成功如下:
2 启动服务
t_name 后面为 jar包名称。可替换
#!/bin/bash t_name="resource-management-server-1.0.0.jar" getPID(){ PID=`ps -ef | grep '\s'$t_name | grep -v grep | awk -F ' ' '{print $2}'` echo $PID } restart(){ kill -9 $PID PID=`getPID` if [ "x$PID" = "x" ];then java -Xms1024m -Xmx2048m -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -jar $t_name > out.log & sleep 1 return 0 else return 1 fi } PID=`getPID` if [ "x$PID" = "x" ];then java -Xms1024m -Xmx2048m -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -jar $t_name > out.log & sleep 1 PID=`getPID` if [ "x$PID" = "x" ];then echo "start $t_name fail" else echo "start $t_name success,PID is $PID" fi else restart result=$? if [ $result -eq 1 ];then exit 1 else NPID=`getPID` echo "restart $t_name success,PID is $NPID" exit 0 fi fi
启动命令 bash start.sh
成功如下: