-
Notifications
You must be signed in to change notification settings - Fork 162
/
scion.sh
executable file
·298 lines (266 loc) · 8.09 KB
/
scion.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/bin/bash
# BEGIN subcommand functions
cmd_bazel-remote() {
mkdir -p "$HOME/.cache/bazel/remote"
uid=$(id -u)
gid=$(id -g)
USER_ID="$uid" GROUP_ID="$gid" docker compose --compatibility -f bazel-remote.yml -p bazel_remote up -d
}
cmd_topo-clean() {
set -e
stop_scion || true
cmd_stop-monitoring || true
rm -rf traces/*
mkdir -p logs traces gen gen-cache gen-certs
find gen gen-cache gen-certs -mindepth 1 -maxdepth 1 -exec rm -r {} +
}
cmd_topology() {
set -e
cmd_topo-clean
echo "Create topology, configuration, and execution files."
tools/topogen.py "$@"
if is_docker_be; then
./tools/quiet ./tools/dc run utils_chowner
fi
}
cmd_topodot() {
./tools/topodot.py "$@"
}
start_scion() {
echo "Running the network..."
if is_docker_be; then
docker compose --compatibility -f gen/scion-dc.yml -p scion up -d
return 0
else
run_setup
./tools/quiet tools/supervisor.sh start all
fi
}
cmd_start() {
start_scion
echo "Note that jaeger is not included anymore."
echo "To run jaeger and prometheus, use run_monitoring."
}
cmd_sciond-addr() {
jq -r 'to_entries |
map(select(.key | match("'"$1"'";"i"))) |
if length != 1 then error("No unique match for '"$1"'") else .[0] end |
"[\(.value)]:30255"' gen/sciond_addresses.json
}
cmd_start-monitoring() {
if [ ! -f "gen/monitoring-dc.yml" ]; then
return
fi
echo "Running monitoring..."
./tools/quiet ./tools/dc monitoring up -d
}
cmd_stop-monitoring() {
if [ ! -f "gen/monitoring-dc.yml" ]; then
return
fi
echo "Stopping monitoring..."
./tools/quiet ./tools/dc monitoring down -v
}
cmd_mstart() {
# Run with docker compose or supervisor
if is_docker_be; then
services="$(glob_docker "$@")"
[ -z "$services" ] && { echo "ERROR: No process matched for $@!"; exit 255; }
./tools/dc scion up -d $services
else
run_setup
tools/supervisor.sh mstart "$@"
fi
}
run_setup() {
tools/set_ipv6_addr.py -a
# Ensure base dir for dispatcher socket exists; on ubuntu this symbolic link to /dev/shm always exists.
if [ ! -d /run/shm/ ]; then
sudo ln -s /dev/shm /run/shm;
fi
# Create dispatcher dir or change owner
local disp_dir="/run/shm/dispatcher"
[ -d "$disp_dir" ] || mkdir "$disp_dir"
[ $(stat -c "%U" "$disp_dir") == "$LOGNAME" ] || { sudo -p "Fixing ownership of $disp_dir - [sudo] password for %p: " chown $LOGNAME: "$disp_dir"; }
}
run_teardown() {
tools/set_ipv6_addr.py -d
local disp_dir="/run/shm/dispatcher"
if [ -e "$disp_dir" ]; then
find "$disp_dir" -xdev -mindepth 1 -print0 | xargs -r0 rm -v
fi
}
stop_scion() {
echo "Terminating this run of the SCION infrastructure"
if is_docker_be; then
./tools/quiet ./tools/dc down
else
./tools/quiet tools/supervisor.sh shutdown
run_teardown
fi
}
cmd_stop() {
stop_scion
echo "Note that jaeger is not included anymore."
echo "To stop jaeger and prometheus, use stop-monitoring."
}
cmd_mstop() {
if is_docker_be; then
services="$(glob_docker "$@")"
[ -z "$services" ] && { echo "ERROR: No process matched for $@!"; exit 255; }
./tools/dc scion stop $services
else
tools/supervisor.sh mstop "$@"
fi
}
cmd_status() {
cmd_mstatus '*'
}
cmd_mstatus() {
if is_docker_be; then
services="$(glob_docker "$@")"
[ -z "$services" ] && { echo "ERROR: No process matched for $@!"; exit 255; }
rscount=$(./tools/dc scion ps --status=running --format "{{.Name}}" $services | wc -l)
tscount=$(echo "$services" | wc -w) # Number of all globed services
./tools/dc scion ps -a \
--status=paused \
--status=restarting \
--status=removing \
--status=dead \
--status=created \
--status=exited \
--format "{{.Name}} {{.State}}" $services
[ $rscount -eq $tscount ]
else
if [ $# -ne 0 ]; then
services="$(glob_supervisor "$@")"
[ -z "$services" ] && { echo "ERROR: No process matched for $@!"; exit 255; }
tools/supervisor.sh status "$services" | grep -v RUNNING
else
tools/supervisor.sh status | grep -v RUNNING
fi
[ $? -eq 1 ]
fi
# If all tasks are running, then return 0. Else return 1.
return
}
glob_supervisor() {
[ $# -ge 1 ] || set -- '*'
matches=
for proc in $(tools/supervisor.sh status | awk '{ print $1 }'); do
for spec in "$@"; do
if glob_match $proc "$spec"; then
matches="$matches $proc"
break
fi
done
done
echo $matches
}
glob_docker() {
[ $# -ge 1 ] || set -- '*'
matches=
for proc in $(./tools/dc scion config --services); do
for spec in "$@"; do
if glob_match $proc "scion_$spec"; then
matches="$matches $proc"
break
fi
done
done
echo $matches
}
glob_match() {
# If $1 is matched by $2, return true
case "$1" in
$2) return 0;;
esac
return 1
}
is_docker_be() {
[ -f gen/scion-dc.yml ]
}
traces_name() {
local name=jaeger_read_badger_traces
echo "$name"
}
cmd_start-traces() {
set -e
local trace_dir=${1:-"$(readlink -e .)/traces"}
local port=16687
local name=$(traces_name)
cmd_stop-traces
docker run -d --name "$name" \
-u "$(id -u):$(id -g)" \
-e SPAN_STORAGE_TYPE=badger \
-e BADGER_EPHEMERAL=false \
-e BADGER_DIRECTORY_VALUE=/badger/data \
-e BADGER_DIRECTORY_KEY=/badger/key \
-v "$trace_dir:/badger" \
-p "$port":16686 \
jaegertracing/all-in-one:1.22.0
sleep 3
x-www-browser "http://localhost:$port"
}
cmd_stop-traces() {
local name=$(traces_name)
docker stop "$name" || true
docker rm "$name" || true
}
cmd_help() {
cat <<-_EOF
SCION
$PROGRAM runs a SCION network locally for development and testing purposes.
Two options for process control systems are supported to run the SCION
services.
- supervisord (default)
- docker compose
This can be selected when initially creating the configuration with the
topology subcommand.
Usage:
$PROGRAM topology [-d] [-c TOPOFILE]
Create topology, configuration, and execution files.
All arguments or options are passed to tools/topogen.py
$PROGRAM run
Run network.
$PROGRAM mstart PROCESS
Start multiple processes.
$PROGRAM stop
Terminate this run of the SCION infrastructure.
$PROGRAM mstop PROCESS
Stop multiple processes.
$PROGRAM start-monitoring
Run the monitoring infrastructure.
$PROGRAM stop-monitoring
Terminate this run of the monitoring infrastructure.
$PROGRAM status
Show all non-running tasks.
$PROGRAM mstatus PROCESS
Show status of provided processes.
$PROGRAM sciond-addr ISD-AS
Return the address for the scion daemon for the matching ISD-AS by
consulting gen/sciond_addresses.json.
The ISD-AS parameter can be a substring of the full ISD-AS (e.g. last
three digits), as long as there is a unique match.
$PROGRAM topodot [-s|--show] TOPOFILE
Draw a graphviz graph of a *.topo topology configuration file.
$PROGRAM help
Show this text.
$PROGRAM start-traces [folder]
Serve jaeger traces from the specified folder (default: traces/).
$PROGRAM stop-traces
Stop the jaeger container started during the start-traces command.
$PROGRAM bazel-remote
Starts the bazel remote.
_EOF
}
# END subcommand functions
PROGRAM="${0##*/}"
COMMAND="$1"
shift
case "$COMMAND" in
help|start|start-monitoring|mstart|mstatus|mstop|stop|stop-monitoring|status|topology|sciond-addr|start-traces|stop-traces|topo-clean|topodot|bazel-remote)
"cmd_$COMMAND" "$@" ;;
run) cmd_start "$@" ;;
*) cmd_help; exit 1 ;;
esac