首页 > 系统相关 >linux 启动脚本

linux 启动脚本

时间:2022-08-30 17:12:08浏览次数:50  
标签:脚本 NAME 启动 pid APP stop echo start linux

#!/bin/bash
APP_NAME=app_api.jar

#使用说明,用来提示输入参数
usage() {
        echo "please enter the corresponding parameters [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 &
                if [ $? -eq 0 ]; then
                        echo "start ${APP_NAME} is success"
                else
                        echo "start ${APP_NAME} is fail"
                fi  
        fi  
}

#停止方法
stop(){
        is_exist
        if [ $? -eq "0" ]; then
                kill -9 $pid
                if [ $? -eq 0 ]; then
                        echo "stop ${APP_NAME} is success"
                else
                        echo "stop ${APP_NAME} is fail"
                fi
        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

简洁版本

java -jar app-1.0.jar >> server.log 2>&1 &

标签:脚本,NAME,启动,pid,APP,stop,echo,start,linux
From: https://www.cnblogs.com/laroux/p/16640070.html

相关文章

  • Linux bash which command All In One
    LinuxbashwhichcommandAllInOnewhichPython3$whichpython#pythonnotfound$whichpython3/usr/bin/python3VSCode$whichcode/usr/local/b......
  • Linux firewall 命令
    常用命令开启端口命令firewall-cmd--zone=public--add-port=443/tcp--permanent--zone #作用域--add-port=80/tcp#添加端口,格式为:端口/通讯协议--permanent#永......
  • Linux 安装mongodb
    按照以前的习惯找了很多文档,都不可靠。然后选择了官方文档,很简单明了的好用在Ubuntu上安装MongoDBCommunityEdition—MongoDBManual然后就ok了......
  • Python 使用paramiko获取Linux远程端电脑挂载空间使用情况
    安装paramikopipinstallparamiko代码演示importjsonasJSONimportreimportparamikoimportsudsfromsuds.wsseimport*classLinuxMntListen():"""L......
  • redis(linux)
    官网下载安装包https://redis.io/download/安装gcc,命令yuminstallgcc进入安装目录make命令进行编译如果报错-jemalloc/jemalloc.h:没有哪个文件,首先看有没有gcc,然后......
  • linux磁盘初始化
    #新系统初始化注意:由于镜像已经做了初始化,所以拿到服务器后只许做以下操作即可使用1.磁盘挂载如果系统没有做逻辑卷的命令,需要自己安装yum-yinstalllvm2fdisk-lpvcr......
  • Linux系统的SSH优化
    在Linux系统中,我们想使用SSH命令登录到另一台服务器中,在第一次登录时,会提示我们验证指纹,如下所示同一网络下,为了确保你想SSH访问的Linux系统是无误的,可以在另一端确认指......
  • Linux是严格区分大小写的,这一点和 Windows不一样,所以操作时要注意区分大小写的不同,包
    linux下的文件夹名字区分大小写吗?_百度知道 https://zhidao.baidu.com/question/395925577.htmlLinux是严格区分大小写的,这一点和Windows不一样,所以操作时要注意区分......
  • 220830-linux磁盘系统初识
    linux中,每一个设备都会被当做一个文件来看待。在linux中,所有的硬件设备文件都会在/dev这个目录下。而SATA接口的硬盘文件名称会被命名为/dev/sd[a-d]。分区的命名:Windows......
  • Linux输出重定向>和>>的区别是什么?
    Linux输出重定向>和>>的区别是什么-百度经验 https://jingyan.baidu.com/article/358570f64345c4ce4724fcba.htmlLinux输出重定向有>和>>,如果不清楚他们的区别,混淆......