forked from influxdata/sandbox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sandbox2-gpu.sh
executable file
·217 lines (198 loc) · 5.98 KB
/
sandbox2-gpu.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
#!/usr/bin/env bash
set -eo pipefail
IFS=$'\n\t'
if ! [ -x "$(command -v docker)" ]; then
echo 'Error: docker is not installed.' >&2
exit 1
fi
if ! [ -x "$(command -v docker compose)" ]; then
echo 'Error: docker compose is not installed.' >&2
exit 1
fi
sandbox () {
source .env
up () {
case $2 in
influxdb)
echo "Up the influxdb container..."
docker compose -f docker-compose-gpu.yml up -d --build influxdb
;;
kapacitor)
echo "Up the kapacitor container..."
docker compose -f docker-compose-gpu.yml up -d --build kapacitor
;;
logstash)
echo "Up the logstash container..."
docker compose -f docker-compose-gpu.yml up -d --build logstash
;;
etcd)
echo "Up the etcd container..."
docker compose -f docker-compose-gpu.yml up -d --build etcd
;;
*)
echo "Up all containers..."
docker compose -f docker-compose-gpu.yml up -d --build
;;
esac
}
down () {
case $2 in
influxdb)
echo "Down the influxdb container..."
docker compose -f docker-compose-gpu.yml down influxdb
;;
kapacitor)
echo "Down the kapacitor container..."
docker compose -f docker-compose-gpu.yml down kapacitor
;;
logstash)
echo "Down the logstash container..."
docker compose -f docker-compose-gpu.yml down logstash
;;
etcd)
echo "Down the etcd container..."
docker compose -f docker-compose-gpu.yml down etcd
;;
*)
echo "Down all containers..."
docker compose -f docker-compose-gpu.yml down
;;
esac
}
# Enter attaches users to a shell in the desired container
enter () {
case $2 in
influxdb)
echo "Entering /bin/bash session in the influxdb container..."
docker compose -f docker-compose-gpu.yml exec influxdb /bin/bash
;;
kapacitor)
echo "Entering /bin/bash session in the kapacitor container..."
docker compose -f docker-compose-gpu.yml exec kapacitor /bin/bash
;;
logstash)
echo "Entering /bin/sh session in the logstash container..."
docker compose -f docker-compose-gpu.yml exec logstash /bin/bash
;;
etcd)
echo "Entering /bin/sh session in the etcd container..."
docker compose -f docker-compose-gpu.yml exec etcd /bin/sh
;;
*)
echo "sandbox enter (influxdb||kapacitor||logstash||etcd)"
;;
esac
}
# Logs streams the logs from the container to the shell
logs () {
case $2 in
influxdb)
echo "Following the logs from the influxdb container..."
docker compose -f docker-compose-gpu.yml logs -f --tail $3 influxdb
;;
kapacitor)
echo "Following the logs from the kapacitor container..."
docker compose -f docker-compose-gpu.yml logs -f --tail $3 kapacitor
;;
logstash)
echo "Following the logs from the logstash container..."
docker compose -f docker-compose-gpu.yml logs -f --tail $3 logstash
;;
etcd)
echo "Following the logs from the etcd container..."
docker compose -f docker-compose-gpu.yml logs -f --tail $3 etcd
;;
all)
docker compose -f docker-compose-gpu.yml logs -f --tail $3
;;
*)
echo "sandbox2.sh logs (influxdb||kapacitor||logstash||etcd||all) [preview counts]"
;;
esac
}
# Install creates and enables a service file
install () {
if [ -z "$2" ]; then
echo "Error: No working directory specified." >&2
exit 1
fi
local servicePath="/etc/systemd/system/snet-sandbox.service"
echo "Creating service file at $servicePath..."
cat << EOF > "$servicePath"
[Unit]
Description=Snet Sandbox Service
After=network-online.target
[Service]
User=root
Group=root
WorkingDirectory=$2
ExecStart=/usr/local/bin/docker compose -f docker-compose-gpu.yml up -d
KillMode=control-group
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl enable snet-sandbox
systemctl start snet-sandbox
echo "Snet Sandbox Service has been enabled and started."
}
case $1 in
up)
up $@
;;
down)
down $@
;;
restart)
down $@
up $@
;;
delete-data)
echo "deleting all influxdb, kapacitor, etcd data..."
rm -rf kapacitor/data influxdb/data etcd/data
;;
docker-clean)
echo "Stopping and removing running sandbox containers..."
docker compose -f docker-compose-gpu.yml down
echo "Removing influxdb and kapacitor images..."
docker rmi ch/influxdb:$INFLUXDB_TAG ch/kapacitor:$KAPACITOR_TAG ch/logstash:$ELK_TAG quay.io/coreos/etcd:$ETCD_TAG > /dev/null 2>&1
docker rmi $(docker images -f "dangling=true" -q)
docker images
;;
influxdb)
echo "Entering the influx cli..."
docker compose -f docker-compose-gpu.yml exec influxdb /usr/bin/influx
;;
flux)
echo "Entering the flux repl..."
docker compose -f docker-compose-gpu.yml exec influxdb /usr/bin/influx -type flux
;;
enter)
enter $@
;;
logs)
logs $@
;;
install)
install "$@"
;;
*)
cat <<-EOF
sandbox commands:
up -> spin up the sandbox environment
down -> tear down the sandbox environment
restart -> restart the sandbox
influxdb -> attach to the influx cli
flux -> attach to the flux REPL
enter (influxdb||kapacitor||logstash||etcd) -> enter the specified container
logs (influxdb||kapacitor||logstash||etcd) -> stream logs for the specified container or all
install <Directory path where docker-compose.yml is located> -> create and enable a system service for the sandbox environment.
delete-data -> delete all data created by the influxdb and kapacitor and etcd
docker-clean -> stop and remove all running docker containers and images
EOF
;;
esac
}
pushd `dirname $0` > /dev/null
sandbox $@
popd > /dev/null