1.启动命令
jar名称:
prs_count=jps -l |grep "uc-auth-1.0.0" | wc -l
文件路径:
/home/jdk1.8/jdk1.8.0_131/jre/bin/java -jar /home/uc/uc-auth-1.0.0.jar
使用指定环境挂到后台运行:
--spring.profiles.active=dev &
startup.sh
#!/usr/bin/env bash prs_count=0 prs_count=`jps -l |grep "uc-auth-1.0.0" | wc -l` if [ ${prs_count} -lt 1 ] ; then echo -e "Startup uc-auth..." sleep 10 /home/jdk1.8/jdk1.8.0_131/jre/bin/java -jar /home/har-uc/uc-auth-1.0.0.jar --spring.profiles.active=dev & else echo -e "uc-auth is running..." fi exit 0
2.关闭命令
shutdown.sh
#!/usr/bin/env bash prs_count=0 prs_count=`jps -l |grep "uc-auth-1.0.0.jar" | wc -l` if [ ${prs_count} -lt 1 ] ; then echo -e "uc-auth is not running..." else echo -e "Shutdown uc-auth" sleep 10 kill -9 `jps -l|grep "uc-auth-1.0.0.jar" |awk '{print $1}'` fi exit 0
参考:https://blog.csdn.net/weixin_43687353/article/details/109741782
【工作中的一次调整】
# 切换目录 cd /alidata/www/botella-server/botella-api-base/target # jar文件名 jar_name='botella-api-base.jar' # 增加可执行权限 chmod +x ./${jar_name} prs_count=`/alidata/server/java/jdk17/bin/jps -l | grep ${jar_name} | wc -l` # 关闭jar包 while [ ${prs_count} -ge 1 ] do echo -e "关闭jar包中..." kill -9 `/alidata/server/java/jdk17/bin/jps -l | grep ${jar_name} | awk '{print $1}'` sleep 2 prs_count=`/alidata/server/java/jdk17/bin/jps -l | grep ${jar_name} | wc -l` done # 启动jar包 echo -e "启动jar包中..." nohup /alidata/server/java/jdk17/bin/java -jar ${jar_name} --spring.profiles.active=pro 2>&1 >> debug.log 2>&1 /dev/null & ####################################################################### # 切换目录 cd /alidata/www/botella-server/botella-api-app/target # jar文件名 jar_name='botella-api-app.jar' # 增加可执行权限 chmod +x ./${jar_name} prs_count=`/alidata/server/java/jdk17/bin/jps -l | grep ${jar_name} | wc -l` # 关闭jar包 while [ ${prs_count} -ge 1 ] do echo -e "关闭jar包中..." kill -9 `/alidata/server/java/jdk17/bin/jps -l | grep ${jar_name} | awk '{print $1}'` sleep 2 prs_count=`/alidata/server/java/jdk17/bin/jps -l | grep ${jar_name} | wc -l` done # 启动jar包 echo -e "启动jar包中..." nohup /alidata/server/java/jdk17/bin/java -jar ${jar_name} --spring.profiles.active=pro 2>&1 >> debug.log 2>&1 /dev/null &
其他参考:gocron系统启动脚本 run.sh start|stop|restart
#!/bin/sh case $1 in start) sleep 5 nohup ./gocron 2>&1 >> info.log 2>&1 /dev/null & echo "服务已启动..." ;; stop) sleep 5 killall gocron echo "服务已停止..." ;; restart) sleep 5 killall gocron sleep 5 nohup ./gocron 2>&1 >> info.log 2>&1 /dev/null & echo "服务已重启..." ;; *) echo "$0 {start|stop|restart}" exit 4 ;; esac