方法1.启动start.sh文件,关闭shutdown.sh文件
start.sh
nohup java -jar /home/ninestar/app/parts.jar --spring.config.location=classpath:/config/application.yml,/home/ninestar/app/application-uat.yml >/home/ninestar/app/parts.out 2>&1 &
shutdown.sh
#!/bin/bash
#获取PID
SERVICE_NAME="parts.jar"
service_pid=`ps -ef | grep $SERVICE_NAME | grep -v grep | awk '{print $2}'`
echo "进程ID为:$service_pid"
#杀进程
echo "kill service $SERVICE_NAME ..."
for id in $service_pid
do
kill -9 $id
done
echo "$service_pid已杀死..."
方法2.包含起动,关闭,重起脚本app.sh,命令:sh app.sh start/stop/restart/status
#!/bin/bash
APP_NAME=parts.jar
date=`date +%Y%m%d`
#使用说明,用来提示输入参数
usage() {
echo "Usage: sh 脚本名.sh [start|stop|restart|status]