diff options
author | Daniel Baumann <mail@daniel-baumann.ch> | 2016-05-18 18:28:46 +0000 |
---|---|---|
committer | Daniel Baumann <mail@daniel-baumann.ch> | 2016-05-18 18:29:07 +0000 |
commit | b90ddebe1d1cb49c30c3a9d99119e3b0d14995fd (patch) | |
tree | a462154b0ea87956dca914338f88544f205ba06a /lib/container/start | |
parent | Releasing debian version 20160501-1. (diff) | |
download | open-infrastructure-compute-tools-b90ddebe1d1cb49c30c3a9d99119e3b0d14995fd.tar.xz open-infrastructure-compute-tools-b90ddebe1d1cb49c30c3a9d99119e3b0d14995fd.zip |
Merging upstream version 20160515.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'lib/container/start')
-rwxr-xr-x | lib/container/start | 102 |
1 files changed, 82 insertions, 20 deletions
diff --git a/lib/container/start b/lib/container/start index 8d5429b..d026bf1 100755 --- a/lib/container/start +++ b/lib/container/start @@ -23,9 +23,12 @@ COMMAND="$(basename ${0})" CONFIG="/etc/container-tools/config" MACHINES="/var/lib/machines" +START="false" +SYSTEMCTL="true" + Parameters () { - LONG_OPTIONS="name:" + LONG_OPTIONS="name:,nspawn,start" OPTIONS="n:" PARAMETERS="$(getopt --longoptions ${LONG_OPTIONS} --name=${COMMAND} --options ${OPTIONS} --shell sh -- ${@})" @@ -46,6 +49,19 @@ Parameters () shift 2 ;; + --nspawn) + # internal option + SYSTEMCTL="false" + shift 1 + ;; + + --start) + # internal option + START="true" + SYSTEMCTL="false" + shift 1 + ;; + --) shift 1 break @@ -78,12 +94,16 @@ then exit 1 fi -STATE="$(machinectl show ${NAME} 2>&1 | awk -F= '/^State=/ { print $2 }')" +case "${START}" in + false) + STATE="$(machinectl show ${NAME} 2>&1 | awk -F= '/^State=/ { print $2 }')" -case "${STATE}" in - running) - echo "'${NAME}': container is already started" >&2 - exit 1 + case "${STATE}" in + running) + echo "'${NAME}': container is already started" >&2 + exit 1 + ;; + esac ;; esac @@ -185,27 +205,58 @@ then MACHINE="--machine=${NAME}" - NETWORK_BRIDGE="$(awk -F= '/^network-bridge=/ { print $2 }' ${CONFIG}/${NAME}.conf)" + NETWORK_VETH_EXTRA_CONF="$(awk -F= '/^network-veth-extra=/ { print $2 }' ${CONFIG}/${NAME}.conf)" + NETWORK_VETH_EXTRA="" - case "${NETWORK_BRIDGE}" in + case "${NETWORK_VETH_EXTRA_CONF}" in "") - NETWORK_BRIDGE="" ;; *) - NETWORK_BRIDGE="--network-bridge=${NETWORK_BRIDGE}" + for VETH in ${NETWORK_VETH_EXTRA_CONF} + do + NETWORK_VETH_EXTRA="${NETWORK_VETH_EXTRA} --network-veth-extra=${VETH}" + INTERFACE="$(echo ${VETH} | awk -F: '{ print $1 }')" + +cat > "/etc/network/interfaces.d/${INTERFACE}" << EOF +allow-hotplug ${INTERFACE} +iface ${INTERFACE} inet manual + pre-up ifconfig ${INTERFACE} up + post-down ifconfig ${INTERFACE} down +EOF + + done ;; esac - NETWORK_VETH="$(awk -F= '/^network-veth=/ { print $2 }' ${CONFIG}/${NAME}.conf || echo yes)" + NETWORK_BRIDGES="$(awk -F= '/^cnt.network-bridge=/ { print $2 }' ${CONFIG}/${NAME}.conf)" - case "${NETWORK_VETH}" in - yes) - NETWORK_VETH="--network-veth" + case "${NETWORK_BRIDGES}" in + "") ;; *) - NETWORK_VETH="" + for BRIDGE_DEFINITION in ${NETWORK_BRIDGES} + do + INTERFACE="$(echo ${BRIDGE_DEFINITION} | awk -F: '{ print $1 }')" + BRIDGE="$(echo ${BRIDGE_DEFINITION} | awk -F: '{ print $2 }')" + + if [ -n "${BRIDGE}" ] && [ -n "${INTERFACE}" ] + then + +cat > "/etc/network/interfaces.d/${INTERFACE}" << EOF +allow-hotplug ${INTERFACE} +iface ${INTERFACE} inet manual + pre-up ifconfig ${INTERFACE} up + post-up brctl addif ${BRIDGE} ${INTERFACE} + pre-down brctl delif ${BRIDGE} ${INTERFACE} + post-down ifconfig ${INTERFACE} down +EOF + + else + echo "Warning bridge definition '${BRIDGE_DEFINITION}' not recognized (expected <bridge>:<interface>): Ignoring" + fi + done ;; esac @@ -298,14 +349,25 @@ then fi fi -# Run -case "${SET_PROPERTY}" in +case "${SYSTEMCTL}" in true) - ${SETARCH} systemd-nspawn ${BIND} ${BOOT} ${CAPABILITY} ${DIRECTORY} ${DROP_CAPABILITY} ${MACHINE} ${NETWORK_BRIDGE} ${NETWORK_VETH} ${LINK_JOURNAL} ${REGISTER} & \ - systemctl --runtime set-property ${NAME} ${BLOCK_IO_DEVICE_WEIGHT} ${BLOCK_IO_READ_BANDWITH} ${BLOCK_IO_WEIGHT} ${BLOCK_IO_WRITE_BANDWITH} ${CPU_QUOTA} ${CPU_SHARES} ${MEMORY_LIMIT} ${TASKS_MAX} + systemctl start container@${NAME}.service + # FIXME start console .. after sleep? + configuration option + exit 0 + ;; +esac + +case "${START}" in + true) + case "${SET_PROPERTY}" in + true) + systemctl --runtime set-property ${NAME} ${BLOCK_IO_DEVICE_WEIGHT} ${BLOCK_IO_READ_BANDWITH} ${BLOCK_IO_WEIGHT} ${BLOCK_IO_WRITE_BANDWITH} ${CPU_QUOTA} ${CPU_SHARES} ${MEMORY_LIMIT} ${TASKS_MAX} + ;; + esac ;; *) - ${SETARCH} systemd-nspawn ${BIND} ${BOOT} ${CAPABILITY} ${DIRECTORY} ${DROP_CAPABILITY} ${MACHINE} ${NETWORK_BRIDGE} ${NETWORK_VETH} ${LINK_JOURNAL} ${REGISTER} + # Run + ${SETARCH} systemd-nspawn --keep-unit ${BIND} ${BOOT} ${CAPABILITY} ${DIRECTORY} ${DROP_CAPABILITY} ${MACHINE} ${NETWORK_VETH_EXTRA} ${LINK_JOURNAL} ${REGISTER} ;; esac |