Allow multiple NTS Manager instances to run on the same machine.
[sim/o1-interface.git] / ntsimulator / scripts / clean.sh
1 #!/bin/bash
2 ################################################################################
3 #
4 # Copyright 2020 highstreet technologies GmbH and others
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9
10 #     http://www.apache.org/licenses/LICENSE-2.0
11
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 ################################################################################
18 if [ "$#" -ne 1 ]; then
19     echo "ID Parameter missing."
20         echo "Usage: $0 id
21         
22 where id is the docker container id of the NTS Manager instance that we want to clean. "
23         exit 1
24 fi
25
26 echo "Cleaning up containers started by the NTS Manager $1..."
27
28 mapfile -t NTS_containers < <( docker ps -a --filter "label=NTS_Manager=$1" --format "{{.ID}}" )
29
30 CONTAINERS=""
31
32 if [ ${#NTS_containers[@]} -gt 0 ]
33 then
34
35         for container in "${NTS_containers[@]}"
36         do
37                 CONTAINERS="$CONTAINERS $container"
38         done
39         echo "Cleaning up containers: $CONTAINERS"
40         docker kill $CONTAINERS > /dev/null 2>&1
41         docker rm $CONTAINERS > /dev/null 2>&1
42 fi
43
44 echo "Cleaning NTS Manager $1..."
45 docker kill $1 > /dev/null 2>&1
46 docker rm $1 > /dev/null 2>&1
47
48 echo "All cleaned up!"