-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbot.sh
executable file
·99 lines (87 loc) · 2.41 KB
/
bot.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
#!/usr/bin/env bash
script_home=bot_code
script_name="$script_home/bot.py"
pid_file="$script_home/bot.pid"
# returns a boolean and optionally the pid
running() {
local status=false
if [[ -f $pid_file ]]; then
# check to see it corresponds to the running script
local pid=$(< "$pid_file")
local cmdline=/proc/$pid/cmdline
# you may need to adjust the regexp in the grep command
if [[ -f $cmdline ]] && grep -q "$script_name" $cmdline; then
status="true $pid"
fi
fi
echo $status
}
start() {
echo "starting services"
if [ ! `docker inspect -f {{.State.Running}} bidaf 2>/dev/null` ]; then
docker run -d --name bidaf -p 1995:1995 sld3/bi-att-flow:0.1.0
fi
if [ ! `docker inspect -f {{.State.Running}} corenlp 2>/dev/null` ]; then
docker run -d --name corenlp -p 9000:9000 sld3/corenlp:3.6.0
fi
local opennmt_run_cmd="cd /root/opennmt && th tools/translation_server.lua \
-host 0.0.0.0 -port 5556 -model /root/data/model.t7 -beam_size 12"
if [ ! `docker inspect -f {{.State.Running}} opennmt 2>/dev/null` ]; then
docker run -d --name opennmt -it -p 5556:5556 -v $(pwd)/question_generation/data:/root/data sld3/opennmt bash -c "$opennmt_run_cmd"
fi
echo "starting $script_name"
nohup python3 $script_name &
echo $! > "$pid_file"
}
stop() {
kill $1 2>/dev/null
rm "$pid_file"
echo "stopped"
}
stopall() {
kill $1 2>/dev/null
rm "$pid_file"
echo "stopping services"
docker stop bidaf
docker rm bidaf
docker stop opennmt
docker rm opennmt
docker stop corenlp
docker rm corenlp
echo "stopped"
}
read running pid < <(running)
case $1 in
start)
if $running; then
echo "$script_name is already running with PID $pid"
else
start
fi
;;
stop)
stop $pid
;;
stopall)
stopall $pid
;;
restart)
stop $pid
start
;;
restartall)
stopall $pid
start
;;
status)
if $running; then
echo "$script_name is running with PID $pid"
else
echo "$script_name is not running"
fi
;;
*) echo "usage: $0 <start|stop|stopall|restart|restartall|status>"
echo "stop is killing the bot only, while stopall shuts down all the services with it"
exit
;;
esac