-
Notifications
You must be signed in to change notification settings - Fork 5
/
run.sh
executable file
·123 lines (98 loc) · 1.73 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
SHELL_DIR=$(dirname $0)
CMD=${1:-status}
command -v tput > /dev/null || TPUT=false
_echo() {
if [ -z ${TPUT} ] && [ ! -z $2 ]; then
echo -e "$(tput setaf $2)$1$(tput sgr0)"
else
echo -e "$1"
fi
}
_read() {
if [ -z ${TPUT} ]; then
read -p "$(tput setaf 6)$1$(tput sgr0)" ANSWER
else
read -p "$1" ANSWER
fi
}
_result() {
_echo "# $@" 4
}
_command() {
_echo "$ $@" 3
}
_success() {
_echo "+ $@" 2
exit 0
}
_error() {
_echo "- $@" 1
exit 1
}
_get_pid() {
PID=$(ps -ef | grep node | grep " server[.]js" | head -1 | awk '{print $2}' | xargs)
}
_stop() {
_get_pid
if [ "${PID}" != "" ]; then
_command "kill -9 ${PID}"
kill -9 ${PID}
_result "deepracer-timer is killed: ${PID}"
fi
}
_status() {
_get_pid
if [ "${PID}" != "" ]; then
_result "deepracer-timer was started: ${PID}"
else
_result "deepracer-timer is stopped"
fi
}
_start() {
_get_pid
if [ "${PID}" != "" ]; then
_error "deepracer-timer has already started: ${PID}"
fi
pushd ${SHELL_DIR}
echo "# _start" > nohup.out
_command "nohup node server.js &"
nohup node server.js &
popd
_get_pid
if [ "${PID}" != "" ]; then
_result "deepracer-timer was started: ${PID}"
fi
}
_init() {
pushd ${SHELL_DIR}
git pull
npm run build
popd
}
_log() {
tail -n 500 -f ${SHELL_DIR}/nohup.out
}
case ${CMD} in
init)
_stop
_init
_start
;;
status)
_status
;;
start)
_start
;;
restart)
_stop
_start
;;
stop)
_stop
;;
log)
_log
;;
esac