-
Notifications
You must be signed in to change notification settings - Fork 3
/
run-nohup.sh
99 lines (84 loc) · 1.85 KB
/
run-nohup.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
#!/bin/bash
NAME="app"
port=7000
RUN_CMD="python3 manage.py runserver 0.0.0.0:${port}"
POSITIONAL=()
model=""
mode=-1
function MyHelp(){
echo "Please read follow:"
echo "-h|--help show the help message"
echo "-restart|--restart switch the mode to restart mode."
}
while [[ $# > 0 ]]; do
case "${1}" in
-f|--flag)
echo flag: "${1}"
shift # shift once since flags have no values
;;
-s|--switch)
echo "switch: ${1} with value: ${2}"
shift 2 # shift twice to bypass switch and its value
;;
-h|--help)
MyHelp
shift ;;
-restart|--restart)
mode=1
shift
;;
-start|--start)
mode=0
shift
;;
-stop|--stop)
mode=2
shift
;;
-m|--model)
# echo "model is ${2}"
model=${2}
shift 2
;;
*) # unknown flag/switch
POSITIONAL+=("${1}")
shift
;;
esac
done
#echo $POSITIONAL
#set -- "${POSITIONAL[@]}" # restore positional params
#echo $POSITIONAL
function start() {
echo "starting now......"
PID_FILE="./${NAME}.pid"
LOG_FILE="./${NAME}.log"
rm $LOG_FILE
nohup ${RUN_CMD} >> ${LOG_FILE} 2>&1 & echo $! > ${PID_FILE}
}
function stop () {
PID=$(pgrep -f ${port})
echo "killing now ......"
kill $PID
}
function restart () {
echo "restarting now ......"
stop
start
}
if [ $mode == 0 ]; then
# start mode
start
elif [ $mode == 1 ]; then
# restart mode
restart
elif [ $mode == 2 ]; then
# stop mode
stop
elif [ $mode == -1 ]; then
#do nothing
echo ""
else
echo "pelease use correctly the flag."
echo "If you don't know how to use it, please enter the --help"
fi