X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=ntsimulator%2Fscripts%2Fclean.sh;h=5d21e4c936bb216f6e97b051c4484d898e2c52cf;hb=5a191a7449347ed5c419720de89d2e4a0194c21e;hp=cc4daf76b12b65c3f4e269c95055d24e1dd25ebc;hpb=29ce368a8b49cb41f3a1640581ff9958ea50ad8c;p=sim%2Fo1-interface.git diff --git a/ntsimulator/scripts/clean.sh b/ntsimulator/scripts/clean.sh index cc4daf7..5d21e4c 100755 --- a/ntsimulator/scripts/clean.sh +++ b/ntsimulator/scripts/clean.sh @@ -1,25 +1,88 @@ -#/bin/bash +#!/bin/bash +################################################################################ +# +# Copyright 2020 highstreet technologies GmbH and others +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ -echo "Cleaning up..." +if [ "$#" -ne 1 ]; then + echo "ID Parameter missing." + echo "Usage: $0 id/all + +where id is the docker container id of the NTS Manager instance that we want to clean. Use 'all' if you want to clean all containers and all managers." + exit 1 +fi -mapfile -t NTS_containers < <( docker ps -a --filter "label=NTS" --format "{{.ID}}" ) +if [ "$1" = "all" ]; then + echo "Cleaning up all NTS simulated devices..." -CONTAINERS="" + mapfile -t NTS_containers < <( docker ps -a --filter "label=NTS_Manager" --format "{{.ID}}" ) -if [ ${#NTS_containers[@]} -gt 0 ] -then + CONTAINERS="" - for container in "${NTS_containers[@]}" - do - CONTAINERS="$CONTAINERS $container" - done - echo "Cleaning up ontainers: $CONTAINERS" - docker kill $CONTAINERS > /dev/null 2>&1 - docker rm $CONTAINERS > /dev/null 2>&1 -fi + if [ ${#NTS_containers[@]} -gt 0 ] + then + + for container in "${NTS_containers[@]}" + do + CONTAINERS="$CONTAINERS $container" + done + echo "Cleaning up containers: $CONTAINERS" + docker kill $CONTAINERS > /dev/null 2>&1 + docker rm $CONTAINERS > /dev/null 2>&1 + fi + + echo "Cleaning up all NTS Managers..." + + mapfile -t NTS_containers < <( docker ps -a --filter "label=NTS-manager" --format "{{.ID}}" ) + + CONTAINERS="" + + if [ ${#NTS_containers[@]} -gt 0 ] + then -echo "Cleaning NTS Manager container" -docker kill NTS_Manager > /dev/null 2>&1 -docker rm NTS_Manager > /dev/null 2>&1 + for container in "${NTS_containers[@]}" + do + CONTAINERS="$CONTAINERS $container" + done + echo "Cleaning up containers: $CONTAINERS" + docker kill $CONTAINERS > /dev/null 2>&1 + docker rm $CONTAINERS > /dev/null 2>&1 + fi + +else + echo "Cleaning up containers started by the NTS Manager $1..." + + mapfile -t NTS_containers < <( docker ps -a --filter "label=NTS_Manager=$1" --format "{{.ID}}" ) + + CONTAINERS="" + + if [ ${#NTS_containers[@]} -gt 0 ] + then + + for container in "${NTS_containers[@]}" + do + CONTAINERS="$CONTAINERS $container" + done + echo "Cleaning up containers: $CONTAINERS" + docker kill $CONTAINERS > /dev/null 2>&1 + docker rm $CONTAINERS > /dev/null 2>&1 + fi + + echo "Cleaning NTS Manager $1..." + docker kill $1 > /dev/null 2>&1 + docker rm $1 > /dev/null 2>&1 +fi echo "All cleaned up!"