diff options
Diffstat (limited to 'lib')
-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 |