-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathstart-kernel.sh
executable file
·213 lines (194 loc) · 5.45 KB
/
start-kernel.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash
#
# Start kernel container
#
usage() {
echo "Usage: $0 [--pull TAG] [--boot all|all_no_besched|node|node_no_besched|minnode|besched_node|named|realm_no_besched|spproxyd] [--named ADDRs] [--dbip DBIP] [--mongoip MONGOIP] [--host] [--usedialproxy] [--reserveMcpu rmcpu] kernelid" 1>&2
}
UPDATE=""
TAG="XXX"
BOOT="named"
NAMED="127.0.0.1"
DBIP="x.x.x.x"
MONGOIP="x.x.x.x"
NET="host"
KERNELID=""
DIALPROXY="false"
RMCPU="0"
while [[ "$#" -gt 1 ]]; do
case "$1" in
--boot)
shift
case "$1" in
"all")
BOOT="knamed;besched;lcsched;msched;ux;s3;chunkd;db;mongo;named"
;;
"all_no_besched")
BOOT="knamed;lcsched;msched;ux;s3;chunkd;db;mongo;named"
;;
"node")
BOOT="besched;msched;ux;s3;db;chunkd;mongo"
;;
"node_no_besched")
BOOT="msched;ux;s3;db;chunkd;mongo"
;;
"minnode")
BOOT="msched;ux;s3;chunkd"
;;
"besched_node")
BOOT="besched"
;;
"named")
BOOT="knamed"
;;
"spproxyd")
BOOT="spproxyd"
;;
"realm")
BOOT="knamed;besched;lcsched;msched;realmd;ux;s3;chunkd;db;mongo;named"
;;
"realm_no_besched")
BOOT="knamed;lcsched;msched;realmd;ux;s3;chunkd;db;mongo;named"
;;
*)
echo "unexpected argument $1 to boot"
usage
exit 1
;;
esac
shift
;;
--pull)
shift
TAG=$1
shift
;;
--host)
shift
NET="host"
;;
--usedialproxy)
shift
DIALPROXY="true"
;;
--named)
shift
NAMED=$1
shift
;;
--dbip)
shift
DBIP=$1
shift
;;
--mongoip)
shift
MONGOIP=$1
shift
;;
--reserveMcpu)
shift
RMCPU=$1
shift
;;
-help)
usage
exit 0
;;
*)
echo "unexpected argument $1"
usage
exit 1
;;
esac
done
if [ $# -ne 1 ]; then
usage
exit 1
fi
KERNELID=$1
mkdir -p /tmp/sigmaos
# Perhaps /tmp/spproxyd should not always be mounted/should not be mounted by
# every kernel instance on a machine?
mkdir -p /tmp/spproxyd
mkdir -p /tmp/sigmaos-bin
mkdir -p /tmp/sigmaos-bin/$KERNELID
mkdir -p /tmp/sigmaos-perf
mkdir -p /tmp/sigmaos-data
chmod a+w /tmp/sigmaos-perf
# Pull latest docker images, if not running a local build.
if [ "$TAG" != "local-build" ]; then
docker pull arielszekely/sigmaos:$TAG > /dev/null
docker tag arielszekely/sigmaos:$TAG sigmaos > /dev/null
docker pull arielszekely/sigmauser:$TAG > /dev/null
docker tag arielszekely/sigmauser:$TAG sigmauser > /dev/null
fi
if [ "$NAMED" == ":1111" ] && ! docker ps | grep -q etcd ; then
./start-etcd.sh
fi
if [ "$DBIP" == "x.x.x.x" ] && docker ps | grep -q sigmadb; then
DBIP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' sigmadb):3306
fi
if [ "$MONGOIP" == "x.x.x.x" ] && docker ps | grep -q sigmamongo; then
MONGOIP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' sigmamongo):27017
fi
PROJECT_ROOT=$(realpath $(dirname $0))
# If running in local configuration, mount bin directory.
MOUNTS="--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
--mount type=bind,src=/sys/fs/cgroup,dst=/cgroup \
--mount type=bind,src=/tmp/sigmaos,dst=/tmp/sigmaos \
--mount type=bind,src=/tmp/spproxyd,dst=/tmp/spproxyd \
--mount type=bind,src=/tmp/sigmaos-data,dst=/home/sigmaos/data \
--mount type=bind,src=/tmp/sigmaos-bin/${KERNELID},dst=/home/sigmaos/bin/user/realms \
--mount type=bind,src=/tmp/sigmaos-perf,dst=/tmp/sigmaos-perf \
--mount type=bind,src=${HOME}/.aws,dst=/home/sigmaos/.aws"
if [ "$TAG" == "local-build" ]; then
MOUNTS="$MOUNTS\
--mount type=bind,src=$PROJECT_ROOT/bin/user,dst=/home/sigmaos/bin/user/common \
--mount type=bind,src=$PROJECT_ROOT/bin/kernel,dst=/home/sigmaos/bin/kernel \
--mount type=bind,src=$PROJECT_ROOT/bin/linux,dst=/home/sigmaos/bin/linux"
fi
# Mounting docker.sock is bad idea in general because it requires to
# give rw permission on host to privileged daemon. But maybe ok in
# our case where kernel is trusted.
CID=$(docker run -dit \
$MOUNTS \
--pid host \
--privileged \
--network ${NET} \
--name ${KERNELID} \
-e kernelid=${KERNELID} \
-e named=${NAMED} \
-e boot=${BOOT} \
-e dbip=${DBIP} \
-e mongoip=${MONGOIP} \
-e buildtag=${TAG} \
-e dialproxy=${DIALPROXY} \
-e SIGMAPERF=${SIGMAPERF} \
-e SIGMAFAIL=${SIGMAFAIL} \
-e SIGMADEBUG=${SIGMADEBUG} \
-e reserveMcpu=${RMCPU} \
sigmaos)
if [ -z ${CID} ]; then
echo "Docker run failed $?" 1>&2
exit 1
fi
IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${CID})
if [ -z ${IP} ]; then
# find out what host's IP is (e.g., when running with --network bridge)
IP=$(ip route get 8.8.8.8 | head -1 | cut -d ' ' -f 7)
fi
until [ "`docker inspect -f {{.State.Running}} ${CID}`"=="true" ]; do
echo -n "." 1>&2
sleep 0.1;
done;
# Wait until kernel is ready
while [ ! -f "/tmp/sigmaos/${KERNELID}" ]; do
echo -n "." 1>&2
sleep 0.1
done;
rm -f "/tmp/sigmaos/${KERNELID}"
echo "nproc: $(nproc)"
echo "booted: $BOOT"
echo -n $IP
echo " container ${CID:0:10}" dbIP $DBIP mongoIP $MONGOIP 1>&2