linux 启动springboot项目脚本

此脚本可以重启,启动,停止等,仅需要传参即可

bash 复制代码
#!/bin/bash
#这里可替换为你自己的执行程序,其他代码无需更改
APP_NAME=test.jar
cd `dirname $0`
#使用说明,用来提示输入参数
usage() {
    echo "Usage: sh 执行脚本.sh [start|stop|restart|status]"
    exit 1
}
#检查程序是否在运行
is_exist(){
  pid=`ps -ef|grep $APP_NAME|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 "${APP_NAME} is already running. pid=${pid} ."
  else
    nohup java -jar $APP_NAME > /dev/null 2>&1 &
    echo "${APP_NAME} is start success"
    #tail -f fileserver-web.out
  fi
}
#停止方法
stop(){
  is_exist
  if [ $? -eq "0" ]; then
    kill -9 $pid
    echo "${APP_NAME} is  stoped"
  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
相关推荐
jiayi_19999 分钟前
Linux 容器安装 conda 和 pip
linux·conda·pip
半夏知半秋31 分钟前
mongodb的复制集整理
服务器·开发语言·数据库·后端·学习·mongodb
一周困⁸天.39 分钟前
Redis 主从复制
linux·redis
ayaya_mana1 小时前
CentOS 7/8/9 一键安装 Python 3.10+ 并配置默认版本
linux·python·centos
The Chosen One9851 小时前
【Linux】Linux权限讲解 :写给文件的一封情书
linux·运维·服务器
IT 小阿姨(数据库)1 小时前
PostgreSQL pg_stat_bgwriter 视图各个字段详解
linux·数据库·sql·postgresql·centos
风语者日志2 小时前
[LitCTF 2023]Vim yyds
linux·编辑器·vim
Thexhy2 小时前
在centos 7上配置FIP服务器的详细教程!!!
linux·运维·centos
chao1898442 小时前
C 文件操作全解速览
服务器·c语言·c#
Java 码农3 小时前
Linux shell sed 命令基础
linux·运维·服务器