forked from HiCooper/oss-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
102 lines (89 loc) · 1.62 KB
/
run.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
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env bash
export LANG="en_US.UTF-8"
functionName=$1
APP_NAME=$2
usage() {
echo "Usage: run.sh [start|stop|halt|restart|status]"
exit 1
}
if [[ "${APP_NAME##*.}"x -ne "jar"x ]];then
echo 'not jar file'
exit 1
fi
function checkParams() {
if [[ ! -n ${functionName} ]] || [[ ! -n ${APP_NAME} ]]; then
echo "ERROR!!! Please check the command, need like ./run.sh start app.jar"
exit 1
fi
}
function getPid() {
task_pid=$(ps -ef | grep java | grep ${APP_NAME} | grep -v grep | grep -v kill | awk '{print $2}')
echo ${task_pid}
}
function start() {
checkParams
task_pid=$(getPid)
if [[ -n ${task_pid} ]]; then
echo "progress is running... try restart?"
else
nohup java -jar -Xms1024m -Xmx1024m ${APP_NAME} > /dev/null 2>&1 --spring.profiles.active=cc &
echo ">>> start successed PID=$! <<<"
fi
}
function stop() {
checkParams
task_pid=$(getPid)
if [[ -n ${task_pid} ]]; then
echo "Kill Process! PID:${task_pid}"
kill -9 ${task_pid}
echo 'Stop Success!'
else
echo "Not Running!"
fi
}
function halt() {
checkParams
task_pid=$(getPid)
if [[ -n ${task_pid} ]]; then
echo "Stop Process! PID:${task_pid} Gracefully"
kill -15 ${task_pid}
echo 'Stop Success!'
else
echo "Not Running!"
fi
}
function status() {
checkParams
task_pid=$(getPid)
if [[ -n ${task_pid} ]]; then
echo "Running..."
else
echo "NOT running."
fi
}
function restart() {
stop
sleep 2
start
}
case ${functionName} in
"start")
start
;;
"stop")
stop
;;
"halt")
halt
;;
"status")
status
;;
"restart")
restart
;;
*)
usage
;;
esac
exit 0