-
Notifications
You must be signed in to change notification settings - Fork 5
/
nginx-ops-server.sh
92 lines (81 loc) · 1.8 KB
/
nginx-ops-server.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/sh
# author lihao3
# ./nginx-ops-server.sh start 启动
# ./nginx-ops-server.sh stop 停止
# ./nginx-ops-server.sh restart 重启
# ./nginx-ops-server.sh status 状态
SERVER_NAME=nginx-ops-server
APP_NAME=nginx-ops-server.jar
APP_HOME=/www/server/nginx-ops-server
LOG_PATH=$APP_HOME/logs
LOG_CONF_PATH=./config/logback-spring.xml
JVM_OPTS="-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$LOG_PATH -Xms512m -Xmx512m -Xmn256m"
if [ "$1" = "" ]; then
echo -e "\033[0;31m 未输入操作名 \033[0m \033[0;34m {start|stop|restart|status} \033[0m"
exit 1
fi
if [ "$APP_NAME" = "" ]; then
echo -e "\033[0;31m 未输入应用名 \033[0m"
exit 1
fi
# shellcheck disable=SC2112
function start() {
PID=$(ps -ef | grep java | grep $APP_NAME | grep -v grep | awk '{print $2}')
if [ x"$PID" != x"" ]; then
echo "$APP_NAME is running..."
else
export DISPLAY=:0
nohup java $JVM_OPTS -jar $APP_HOME/$APP_NAME > /dev/null 2>&1 &
echo "Start $APP_NAME success..."
fi
}
# shellcheck disable=SC2112
function stop() {
echo "Stop $APP_NAME"
PID=""
query() {
PID=$(ps -ef | grep java | grep $APP_NAME | grep -v grep | awk '{print $2}')
}
query
if [ x"$PID" != x"" ]; then
kill -9 $PID
echo "$APP_NAME (pid:$PID) exiting..."
while [ x"$PID" != x"" ]; do
sleep 1
query
done
echo "$APP_NAME exited."
else
echo "$APP_NAME already stopped."
fi
}
# shellcheck disable=SC2112
function restart() {
stop
sleep 2
start
}
# shellcheck disable=SC2112
function status() {
PID=$(ps -ef | grep java | grep $APP_NAME | grep -v grep | wc -l)
if [ $PID != 0 ]; then
echo "$APP_NAME is running..."
else
echo "$APP_NAME is not running..."
fi
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*) ;;
esac