-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.sh
More file actions
executable file
·112 lines (95 loc) · 2.18 KB
/
control.sh
File metadata and controls
executable file
·112 lines (95 loc) · 2.18 KB
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
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
RED='\033[0;31m'
LYELLOW='\033[0;93m'
NC='\033[0m' # No Color
PROCESS_NAME=centmonit
PID_FILE=run.pid
_dirname=$(dirname $0)
if [ "$_dirname" != "./" ] && [ "$_dirname" != "." ]; then
printf "${LYELLOW}Go go root folder \"%s\"${NC}\n" $_dirname
cd $_dirname
fi
# ----------------------------------
# -------- Help functions --------
# ----------------------------------
# return 0 => it's already run, don't start process
# return 1 => not run, so you could start process
should_i_run () {
local _allow_run=0
if [ ! -f "$PID_FILE" ]; then
_allow_run=1
else
_pid=`cat $PID_FILE`
if [ "$_pid" -eq 0 ]; then
_allow_run=1
else
_live_pid=$(pgrep $PROCESS_NAME)
if [ -z "$_live_pid" ]; then
_allow_run=1
fi
fi
fi
echo "$_allow_run"
}
start () {
printf "${LYELLOW}"
_runable=$(should_i_run)
if [ "$_runable" -eq 0 ]; then
printf "Already running, pls check \"run.pid\" file\n"
else
printf "${LYELLOW}Starting CentMonit...\n"
nohup ./bin/centmonit >/dev/null 2>&1 & echo $! > $PID_FILE
printf "CentMonit is now running with PID %s\n" $(cat $PID_FILE)
fi
printf "END!${NC}\n"
}
stop () {
printf "${LYELLOW}"
_runable=$(should_i_run)
if [ "$_runable" -eq 1 ]; then
printf "Not running\n"
else
printf "Shutdown CentMonit...\n"
kill -9 $(pgrep $PROCESS_NAME)
echo 0 > $PID_FILE
_pid=$(pgrep $PROCESS_NAME)
if [ -z "$_pid" ]; then
printf "Now stopped\n"
fi
fi
printf "END!${NC}\n"
}
status () {
printf "${LYELLOW}"
printf "Checking CentMonit...\n"
_runable=$(should_i_run)
if [ "$_runable" -eq 1 ]; then
printf "Not running\n"
else
printf "Running with PID %s\n" $(cat $PID_FILE)
fi
printf "END!${NC}\n"
}
# ------------------------
# -------- Main --------
# ------------------------
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
*)
echo -e "${LYELLOW}"
echo "--------------------------------------------------------"
echo "Usage: ./control.sh <start> | <stop> | <status>"
echo "--------------------------------------------------------"
echo -e "${NC}"
exit 1
;;
esac
exit $?