diff options
author | Nik Lutz <nik@netstyle.ch> | 2016-05-18 08:49:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@open-infrastructure.net> | 2016-05-18 18:26:08 +0000 |
commit | 198710f9359e09bbb47ef966c671bf686e6989e5 (patch) | |
tree | bf466834603d8eef37135942df7dbe18770e082a | |
parent | Using systemctl to start containers. (diff) | |
download | compute-tools-198710f9359e09bbb47ef966c671bf686e6989e5.tar.xz compute-tools-198710f9359e09bbb47ef966c671bf686e6989e5.zip |
Using systemd to cleanup network interfaces after the container has been stopped.
Signed-off-by: Daniel Baumann <daniel.baumann@open-infrastructure.net>
-rwxr-xr-x | lib/container/stop | 61 | ||||
-rw-r--r-- | share/systemd/container@.service | 1 |
2 files changed, 40 insertions, 22 deletions
diff --git a/lib/container/stop b/lib/container/stop index 18d154c..67cc403 100755 --- a/lib/container/stop +++ b/lib/container/stop @@ -23,9 +23,11 @@ COMMAND="$(basename ${0})" CONFIG="/etc/container-tools/config" MACHINES="/var/lib/machines" +CLEAN="false" + Parameters () { - LONG_OPTIONS="name:,force" + LONG_OPTIONS="name:,force,clean" OPTIONS="n:,f" PARAMETERS="$(getopt --longoptions ${LONG_OPTIONS} --name=${COMMAND} --options ${OPTIONS} --shell sh -- ${@})" @@ -50,6 +52,12 @@ Parameters () FORCE="true" ;; + --clean) + # internal option + CLEAN="true" + shift 1 + ;; + --) shift 1 break @@ -84,6 +92,36 @@ fi STATE="$(machinectl show ${NAME} 2>&1 | awk -F= '/^State=/ { print $2 }')" +# Removing network configuration +case "${CLEAN}" in + true) + NETWORK_VETH_EXTRA_CONF="$(awk -F= '/^network-veth-extra=/ { print $2 }' ${CONFIG}/${NAME}.conf)" + + case "${NETWORK_VETH_EXTRA_CONF}" in + "") + ;; + + *) + for VETH in ${NETWORK_VETH_EXTRA_CONF} + do + INTERFACE="$(echo ${VETH} | awk -F: '{ print $1 }')" + FILE="/etc/network/interfaces.d/${INTERFACE}" + + if [ -f "${FILE}" ] + then + rm -f "${FILE}" + fi + done + ;; + esac + + exit 0 + ;; + + *) + ;; +esac + case "${STATE}" in running) ;; @@ -106,24 +144,3 @@ esac # Run machinectl ${MODE} ${NAME} - -# Removing network configuration -NETWORK_VETH_EXTRA_CONF="$(awk -F= '/^network-veth-extra=/ { print $2 }' ${CONFIG}/${NAME}.conf)" - -case "${NETWORK_VETH_EXTRA_CONF}" in - "") - ;; - - *) - for VETH in ${NETWORK_VETH_EXTRA_CONF} - do - INTERFACE="$(echo ${VETH} | awk -F: '{ print $1 }')" - FILE="/etc/network/interfaces.d/${INTERFACE}" - - if [ -f "${FILE}"] - then - rm -f "${FILE}" - fi - done - ;; -esac diff --git a/share/systemd/container@.service b/share/systemd/container@.service index e69a701..0bd6766 100644 --- a/share/systemd/container@.service +++ b/share/systemd/container@.service @@ -5,6 +5,7 @@ Description="Container: %i" Type=simple ExecStart=/usr/bin/container start --name %i --nspawn ExecStartPost=/usr/bin/container start --name %i --start +ExecStopPost=/usr/bin/container stop -n %i --clean KillMode=mixed [Install] |