-
Notifications
You must be signed in to change notification settings - Fork 13
/
start-docker.sh
executable file
·86 lines (77 loc) · 1.83 KB
/
start-docker.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
#!/usr/bin/env bash
set -e
# From https://guides.micronaut.io/latest/micronaut-docker-image-gradle-java.html
# Set up EC2: https://www.cyberciti.biz/faq/how-to-install-docker-on-amazon-linux-2/
TYPE="docker"
PORT=8080
DELAY=20
usage() {
echo "$0: Time to first request for checkpoint, native, java or docker applications"
echo ""
echo " $0 [-c|-d|-j|-n] [-p port] ARTIFACT"
echo ""
echo " -c : ARTIFACT is a CRaC checkpoint"
echo " -d : ARTIFACT is a docker image (default)"
echo " -j : ARTIFACT is a fat jar"
echo " -n : ARTIFACT is a native executable"
echo " -p : port to check (default 8080)"
echo ""
}
while getopts 'cdjnp:' flag; do
case "${flag}" in
c) TYPE="crac" ;;
d) TYPE="docker" ;;
j) TYPE="java" ;;
n) TYPE="native" ;;
p) PORT="${OPTARG}" ;;
*) usage
exit 1 ;;
esac
done
shift $(($OPTIND - 1))
echo $1
if [ $# -eq 0 ]; then
echo "Needs the docker image or Jar file to run"
exit 1
fi
execute() {
local END=$((SECONDS+DELAY))
while ! curl -o /dev/null -s "http://localhost:${PORT}"; do
if [ $SECONDS -gt $END ]; then
echo "No response from the app in $DELAY seconds" >&2
exit 1
fi
sleep 0.001;
done
}
mytime() {
exec 3>&1 4>&2
mytime=$(TIMEFORMAT="%3R"; { time $1 1>&3 2>&4; } 2>&1)
exec 3>&- 4>&-
echo $mytime
}
if [[ "$TYPE" == "crac" ]]; then
java -XX:CRaCRestoreFrom=$1 &
PID=$!
TTFR=$(mytime execute)
kill -9 $PID
elif [[ "$TYPE" == "java" ]]; then
java -jar $1 &
PID=$!
TTFR=$(mytime execute)
kill -9 $PID
elif [[ "$TYPE" == "docker" ]]; then
CONTAINER=$(docker run -d --rm -p $PORT:$PORT --privileged $1)
TTFR=$(mytime execute)
docker container kill $CONTAINER > /dev/null
else
$1 &
PID=$!
TTFR=$(mytime execute)
kill -9 $PID
fi
if [ "$TTFR" != "" ]; then
echo "${TTFR} seconds"
else
exit 1
fi