Blame view

remove_container.sh 1.18 KB
b1087939   hmalti   Ajout commandes
1
  #!/bin/bash
b02be524   hmalti   Correctifs + gest...
2
  set -x
17bfc359   hmalti   Help Image+contai...
3
4
5
6
7
  while getopts c: o; do
      case $o in
          (c) NAME_CONTAINER_TO_REMOVE=$OPTARG;;   
      esac
  done
b1087939   hmalti   Ajout commandes
8
  #vérification que l'utilisateur donne bien un nom à l'CONTAINER
5721892d   hmalti   Avancées
9
  if [[ -z "$NAME_CONTAINER_TO_REMOVE" ]]; then 
b02be524   hmalti   Correctifs + gest...
10
    echo "Il faut donner le nom du conteneur! Relancez la commande avec les bons arguments."
b1087939   hmalti   Ajout commandes
11
12
    exit
  fi
b1087939   hmalti   Ajout commandes
13
  
b02be524   hmalti   Correctifs + gest...
14
15
16
17
18
19
  PID=$(grep "pid" $PATH_MANIFEST/containers/$NAME_CONTAINER_TO_REMOVE.manifest | cut -d":" -f2)
  
  echo "Kill du container"
  kill $PID
  
  echo "Démontage de /mnt/baleine/$NAME_CONTAINER_TO_REMOVE"
5721892d   hmalti   Avancées
20
  umount /mnt/baleine/$NAME_CONTAINER_TO_REMOVE
b02be524   hmalti   Correctifs + gest...
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  
  echo "Suppression de /mnt/baleine/$NAME_CONTAINER_TO_REMOVE"
  
  echo "Suppression de $PATH_BALEINE/containers/$NAME_CONTAINER_TO_REMOVE"
  rm -rf $PATH_BALEINE/containers/$NAME_CONTAINER_TO_REMOVE
  
  INTERFACES=$(grep "interfaces" $PATH_MANIFEST/containers/$NAME_CONTAINER_TO_REMOVE.manifest | cut -d":" -f2)
  
  echo "Suppression des interfaces réseau :"
  IFS=","
  #On supprime les interfaces réseaux associées à ce container
  for interface in $INTERFACES; do
      echo "Suppression de $interface"
      ip link del $interface
  done
  
  echo "Suppression du manifeste du container"
  rm -rf $PATH_MANIFEST/containers/$NAME_CONTAINER_TO_REMOVE.manifest