diff options
author | Nik Lutz <nik@netstyle.ch> | 2016-05-12 15:54:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@open-infrastructure.net> | 2016-05-18 18:26:07 +0000 |
commit | 41f464be1472690ef8af3c1487a8184461ab9bbf (patch) | |
tree | 4e4059b09029c9935279d1f5484609b1e02863c1 /lib/container/start | |
parent | Swaping parsing order of NETWORK_VETH_EXTRA and NETWORK_BRIDGES. (diff) | |
download | compute-tools-41f464be1472690ef8af3c1487a8184461ab9bbf.tar.xz compute-tools-41f464be1472690ef8af3c1487a8184461ab9bbf.zip |
Using systemctl to start containers.
Signed-off-by: Daniel Baumann <daniel.baumann@open-infrastructure.net>
Diffstat (limited to 'lib/container/start')
-rwxr-xr-x | lib/container/start | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/lib/container/start b/lib/container/start index d0e7e6e..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 @@ -329,14 +349,25 @@ EOF fi fi -# Run -case "${SET_PROPERTY}" in +case "${SYSTEMCTL}" in + true) + systemctl start container@${NAME}.service + # FIXME start console .. after sleep? + configuration option + exit 0 + ;; +esac + +case "${START}" in true) - ${SETARCH} systemd-nspawn ${BIND} ${BOOT} ${CAPABILITY} ${DIRECTORY} ${DROP_CAPABILITY} ${MACHINE} ${NETWORK_VETH_EXTRA} ${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} + 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_VETH_EXTRA} ${LINK_JOURNAL} ${REGISTER} + # Run + ${SETARCH} systemd-nspawn --keep-unit ${BIND} ${BOOT} ${CAPABILITY} ${DIRECTORY} ${DROP_CAPABILITY} ${MACHINE} ${NETWORK_VETH_EXTRA} ${LINK_JOURNAL} ${REGISTER} ;; esac |