linux下的启停脚本

liunx 脚本管理应用启动停止重启等操作

脚本代码

install.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash

APP_HOME=/home/go/src/check_people_gin
APP_NAME=checkpeople

case $1 in
start) # 开始
PID=$(ps -ef | grep ${APP_NAME} | grep -v grep | awk '{print $2}')
if [ -z "$PID" ] ;then
echo "start ${APP_NAME}"
nohup ${APP_HOME}/${APP_NAME} > /dev/null 2>&1 &
else
echo "${APP_NAME} is running"
fi
;;

stop) # 停止
PID=$(ps -ef | grep ${APP_NAME} | grep -v grep | awk '{print $2}')
if [ -z "$PID" ] ;then
echo "${APP_NAME} is not running"
else
echo "stop ${APP_NAME}"
kill -9 $PID
fi
;;

restart) # 重启
PID=$(ps -ef | grep ${APP_NAME} | grep -v grep | awk '{print $2}')
if [ -z "$PID" ] ;then
echo "start ${APP_NAME}"
nohup ${APP_HOME}/${APP_NAME} > /dev/null 2>&1 &
else
echo "stop ${APP_NAME}"
kill -9 $PID
echo "start ${APP_NAME}"
nohup ${APP_HOME}/${APP_NAME} > /dev/null 2>&1 &
fi
;;


logs) # 日志
tail -f ${APP_HOME}/logs/checkpeople.log
;;


status) # 状态
PID=$(ps -ef | grep ${APP_NAME} | grep -v grep | awk '{print $2}')
if [ -z "$PID" ] ;then
echo "${APP_NAME} is not running"
else
echo "${APP_NAME} is running, pid $PID"
fi
;;

esac

APP_HOME :程序所在目录

APP_NAME: 程序名称

使用

sh install.sh start

sh install.sh stop

sh install.sh restart

sh install.sh status

sh install.sh logs


linux下的启停脚本
https://zhaops-hub.github.io/2021/12/22/liunx/linux下的启停脚本/
作者
赵培胜
发布于
2021年12月22日
许可协议