spring boot启动停止重启脚本

一、单个文件启动脚本----gm_app.sh(stop,start,restart)

#!/bin/sh

export JAVA_HOME=/home/weblogic/java

export JRE_HOME=$JAVA_HOME/jre

basepath=(cd \`dirname 0`; pwd)

app_name=gm_app

jar_file={basepath}/{app_name}.jar

log_path=${basepath}/logs

log_file=${log_path}/info-all.log

pid_file={basepath}/{app_name}.pid

#config_file=${basepath}/application.properties

#lib_path=${basepath}/lib

server_port=8840

#gm_start_timer=true

#使用说明,用来提示输入参数

usage() {

echo "Usage: sh 执行脚本.sh [start|stop|restarti|status|log]"

exit 1

}

#检查程序是否在运行

is_exist(){

pid=`ps -ef|grep jar_file\|grep -v grep\|awk '{print 2}' `

#如果不存在返回1,存在返回0

if [ -z "${pid}" ]; then

return 1

else

return 0

fi

}

#启动方法

start(){

is_exist

if [ $? -eq "0" ]; then

echo ">>> {jar_file} is already running PID={pid} <<<"

else

if [ ! -d $log_path ]; then

mkdir $log_path

fi

if [ ! -f $log_file ]; then

touch $log_file

fi

nohup java -server \

-Xms2g -Xmx2g -Xmn1g \

-XX:+AggressiveOpts -XX:+UseParallelGC -XX:+UseBiasedLocking \

-Djava.awt.headless=true \

-Djava.security.egd=file:/dev/../dev/urandom \

-Dspring.profiles.active=prod \

-Dgm_logging_path=${log_path} \

-Dserver_port=${server_port} \

-jar $jar_file >/dev/null 2>&1 &

echo ! \> pid_file

echo ">>> start jar_file successed PID=! <<<"

fi

}

#停止方法

stop(){

#is_exist

pidf=(cat pid_file)

#echo "$pidf"

echo ">>> api PID = pidf begin kill pidf <<<"

kill $pidf

rm -rf $pid_file

sleep 2

is_exist

if [ $? -eq "0" ]; then

echo ">>> api 2 PID = pidf begin kill -9 pidf <<<"

kill -9 $pidf

sleep 2

echo ">>> $jar_file process stopped <<<"

else

echo ">>> ${jar_file} is not running <<<"

fi

}

#输出运行状态

status(){

is_exist

if [ $? -eq "0" ]; then

echo ">>> {jar_file} is running PID is {pid} <<<"

else

echo ">>> ${jar_file} is not running <<<"

fi

}

#重启

restart(){

stop

start

}

#输出warn日志

logall(){

echo ">>> info-all <<<"

tail -f $log_file

}

#根据输入参数,选择执行对应方法,不输入则执行使用说明

case "$1" in

"start")

start

;;

"stop")

stop

;;

"status")

status

;;

"restart")

restart

;;

"log")

logall

;;

*)

usage

;;

esac

exit 0

二、批量启动脚本gm_service.sh

(1、重启 ./gm_service.sh restart

2、关闭 ./gm_service.sh stop

3、开启 ./gm_service.sh stop)

#!/bin/sh

basepath=(cd \`dirname 0`; pwd)

#各个服务启动脚本路径

app_sh=${basepath}/app

back_sh=${basepath}/back

#使用说明,用来提示输入参数

usage() {

echo "Usage: sh 执行脚本.sh [start|stop|restart]"

exit 1

}

#启动方法

start(){

cd ${app_sh}

sh gm_app.sh start

cd ${back_sh}

sh gm_back.sh start

}

#停止

stop(){

cd ${app_sh}

sh gm_app.sh stop

cd ${back_sh}

sh gm_back.sh stop

}

#重启

restart(){

stop

start

}

#根据输入参数,选择执行对应方法,不输入则执行使用说明

case "$1" in

"start")

start

;;

"stop")

stop

;;

"restart")

restart

;;

*)

usage

;;

esac

exit 0

三、查看文件脚本tail.sh

#!/bin/bash

basepath=(cd \`dirname 0`; pwd)

tail -1000f ${basepath}/logs/info-all.log

相关推荐
小丑西瓜6661 小时前
CMake基础用法,cmake_minimum_required,project,add_executable
linux·服务器·c++·camke
晚风吹长发1 小时前
初步了解Linux中的命名管道及简单应用和简单日志
linux·运维·服务器·开发语言·数据结构·c++·算法
我尽力学1 小时前
面试 总结
java·spring boot·面试
大熊背1 小时前
多核架构中,RTOS小核跑sensor 的normal模式,大核linux核跑WDR模式,将小核的曝光时间映射到WDR模式中的曝光时间的方法
linux·自动曝光·wdr
计算机学姐2 小时前
基于SpringBoot的演唱会抢票系统
java·spring boot·后端·spring·tomcat·intellij-idea·推荐算法
全栈测试笔记2 小时前
异步函数与异步生成器
linux·服务器·前端·数据库·python
李慕婉学姐2 小时前
Springboot连锁火锅管理及预测系统sh5s1gn1(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
数据库·spring boot·后端
weixin_462446232 小时前
Linux 下使用 xfreerdp3 远程连接 Windows(从安装到实战使用)
linux·运维·windows
EndingCoder2 小时前
配置 tsconfig.json:高级选项
linux·前端·ubuntu·typescript·json
爱丶狸2 小时前
Linux三剑客之sed
linux·运维·服务器