-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoacis_start.sh
executable file
·65 lines (59 loc) · 1.46 KB
/
oacis_start.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
#!/bin/bash -eu
cd $(dirname $0)
# parse option
usage() {
echo "Usage: ./oacis_start.sh [OPTIONS]"
echo " Restart the stopped container"
echo
echo "Options:"
echo " -h, --help : show this message"
echo
exit 1
}
while (( $# > 0 ))
do
case $1 in
-h | --help)
usage
exit 1
;;
*)
echo "[Error] invalid argument"
usage
exit 1
;;
esac
done
COMPOSE_PS_JSON=$(docker compose ps -a --format json)
echo "${COMPOSE_PS_JSON}"
if [ "${COMPOSE_PS_JSON}" == '[]' ]; then
echo "===== there is no container ============"
exit 1
elif echo "${COMPOSE_PS_JSON}" | grep -q '"State":"running"'; then
echo "===== container is already running ====="
exit 1
elif echo "${COMPOSE_PS_JSON}" | grep -q '"State":"exited"'; then
docker compose start
else
echo "unexpected status"
exit 1
fi
# show logs until OACIS is ready
if [ -e temp.pipe ]; then
rm temp.pipe
fi
mkfifo temp.pipe
docker compose logs -f --since 0s > >(tee temp.pipe) 2> /dev/null &
trap "kill -9 $!" 1 2 3 15
# equivalent to `docker compose logs ... | tee temp.pipe`
# but we use process substitution to get the PID of `docker compose logs`
# in case we receive the signal, we kill `docker compose logs`
set +x
grep --line-buffered -m 1 "OACIS READY" > /dev/null < temp.pipe
# to stop `docker compose logs -f`, multiple signals are needed
# probably due to a bug in this command
while kill -0 $! 2> /dev/null; do
kill -2 $!
sleep 0.1
done
rm temp.pipe