首页 > 其他分享 >springboot 启动脚本

springboot 启动脚本

时间:2022-11-20 11:33:50浏览次数:50  
标签:脚本 springboot 启动 APP xxx pid echo sh NAME

springboot项目打包有是一个jar包,需要启动,如下命令

启动命令:nohup java -jar app.jar > ./log.out 2>&1 &
但使用脚本会更加方便,脚本如下:

#!/bin/bash
#这里可替换为你自己的执行程序,其他代码无需更改
APP_NAME=md-1.0.2-SNAPSHOT.jar

#APP_DIR=/usr/local/program
APP_DIR=`pwd`
echo "当前路径"
echo $APP_DIR

#使用说明,用来提示输入参数
usage() {
 echo "Usage: sh console.sh [start|stop|restart|status]"
 exit 1
}
 
#检查程序是否在运行
is_exist(){
 pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' `

 echo "ps number is: ${pid}"
 #如果不存在返回1,存在返回0 
 if [ -z "${pid}" ]; then
 return 1
 else
 return 0
 fi
}
 
#启动方法
start(){
 is_exist
 if [ $? -eq "0" ]; then
 echo "${APP_NAME} is already running. pid=${pid} ."
 else
 nohup java -jar $APP_DIR/$APP_NAME > $APP_DIR/log.out 2>&1 &
 #nohup java -jar $APP_DIR/$APP_NAME
 echo "${APP_NAME} start success"
 fi
}
 
#停止方法
stop(){
 is_exist
 if [ $? -eq "0" ]; then
 kill -9 $pid
 else
 echo "${APP_NAME} is not running"
 fi 
}
 
#输出运行状态
status(){
 is_exist
 if [ $? -eq "0" ]; then
 echo "${APP_NAME} is running. Pid is ${pid}"
 else
 echo "${APP_NAME} is NOT running."
 fi
}
 
#重启
restart(){
 stop
 start
}
 
#根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
 "start")
 start
 ;;
 "stop")
 stop
 ;;
 "status")
 status
 ;;
 "restart")
 restart
 ;;
 *)
 usage
 ;;
esac

#脚本编写完成后,可以使用命令sh xxx.sh执行,也可以使用./xxx.sh执行。
#sh xxx.sh与./xxx.sh区别
#sh xxx.sh 是不需要有执行权限
#./xxx.sh 是需要有执行权限的,可以通过 chmod +x xxx.sh 赋予权限。

  

标签:脚本,springboot,启动,APP,xxx,pid,echo,sh,NAME
From: https://www.cnblogs.com/lean-blog/p/16908115.html

相关文章

  • springboot整合redis详解
    springboot整合redis1.首先创建springboot工程2.配置pom.xml文件<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns......
  • 集群分发xsync xcall 脚本命令
     建立hosts白名单127.0.0.1localhostlocalhost.localdomainlocalhost4localhost4.localdomain4::1localhostlocalhost.localdomainlocalhost6loca......
  • 自己制作AM启动方式,不需要每次输入密码和用户名
    第一布,查看用户名,数据库等信息在记事本中写以下信息,保存后,后缀改为bat,双击此文件即可启动hulldesign模块且无黑框框的控制台哦C:\AVEVA\Marine\OH12.1.SP4\marine.bat......
  • [YURIS引擎] 寻找脚本密钥
    [YURIS引擎]寻找脚本密钥0x00背景在寻找密钥之前来了解一下yuris的脚本yuris的脚本一般放在一个叫bn.ypforysbin.ypf的封包里。有兴趣了解结构的可以看看这个链接......
  • k8s配置禁止以 root 用户启动容器
    描述通过禁止以root用户启动容器,可以限制容器内进程的可用权限,降低被容器中恶意进程通过root权限入侵/破坏用户应用、主机甚至整个集群的风险。如果确认当前工作负载确......
  • SpringBoot13(springboot自定义Starter)
    实现:一、自定义Starter最简实现1、classpath(springboot下是resources)路径下创建MATA-INF/spring.factories文件,写入需要加载的......
  • spring ioc 容器启动过程中 调用的核心方法 - invokeBeanFactoryPostProcessors
    invokeBeanFactoryPostProcessors:调用bean工厂的后置处理器,解析配置类,将配置类注册成Bean定义。调用所有的BeanDefinitionRegistryPostProcessor和BeanFactoryPostProce......
  • ECMAScript客户端脚本语言的标准 注释 数据类型
    1基本语法:1,与html结合方式  1,内部js  定义<script>,标签内容就算js代码2,外部JS定义<script>,通过src属性引入外部的js......
  • springboot整合kafka
    1.引入kakka依赖<dependency><groupId>org.springframework.kafka</groupId><artifactId>spring-kafka</artifactId></dependency>2.修改配置文件#应用名称......
  • SQLserver服务器启动不了解决方案(端口占用异常)
    一、问题描述: 二、问题原因:排查方法1:telnet127.0.0.11433看能ping通不能,如果不能说明端口被占用。排查方法2:打开“计算机管理”→“系统工具”→“事件查看器”......