diff options
Diffstat (limited to 'libexec/container/stop')
-rwxr-xr-x | libexec/container/stop | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/libexec/container/stop b/libexec/container/stop index cb85c8d..8ca98ce 100755 --- a/libexec/container/stop +++ b/libexec/container/stop @@ -34,8 +34,8 @@ Parameters () { OPTIONS_ALL="" - GETOPT_LONGOPTIONS="name:,force,clean,verbose," - GETOPT_OPTIONS="n:,f,v," + GETOPT_LONGOPTIONS="name:,force,interactive,kill,clean,stateless,verbose," + GETOPT_OPTIONS="n:,f,i,k,v," PARAMETERS="$(getopt --longoptions ${GETOPT_LONGOPTIONS} --name=${COMMAND} --options ${GETOPT_OPTIONS} --shell sh -- ${@})" @@ -62,6 +62,20 @@ Parameters () OPTIONS_ALL="${OPTIONS_ALL} --force" ;; + -i|--interactive) + INTERACTIVE="true" + shift 1 + + OPTIONS_ALL="${OPTIONS_ALL} --interactive" + ;; + + -k|--kill) + KILL="true" + shift 1 + + OPTIONS_ALL="${OPTIONS_ALL} --kill" + ;; + --clean) # internal option CLEAN="true" @@ -70,6 +84,14 @@ Parameters () OPTONS_ALL="${OPTIONS_ALL} --clean" ;; + --stateless) + # internal option + STATELESS="true" + shift 1 + + OPTIONS_ALL="${OPTIONS_ALL} --stateless" + ;; + -v|--verbose) VERBOSE="true" shift 1 @@ -92,7 +114,7 @@ Parameters () Usage () { - echo "Usage: ${PROGRAM} ${COMMAND} -n|--name NAME [-f|--force] [-v|--verbose]" >&2 + echo "Usage: ${PROGRAM} ${COMMAND} -n|--name NAME [-f|--force] [-i|--interactive] [-v|--verbose]" >&2 echo echo "See ${COMMAND}(1), ${PROGRAM}(1) and ${PROJECT}(7) for more information." @@ -263,7 +285,7 @@ case "${STATE}" in ;; esac -case "${FORCE}" in +case "${KILL}" in true) MODE="terminate" ;; @@ -273,6 +295,23 @@ case "${FORCE}" in ;; esac +if [ "${FORCE}" != "true" ] || [ "${INTERACTIVE}" = "true" ] +then + echo -n "'${NAME}': stop container '${NAME}' [y|N]? " + read STOP + + STOP="$(echo ${STOP} | tr '[A-Z]' '[a-z]')" + + case "${STOP}" in + y|yes) + ;; + + *) + exit 1 + ;; + esac +fi + # Run case "${VERBOSE}" in true) @@ -282,7 +321,7 @@ esac machinectl ${MODE} ${NAME} -case "${FORCE}" in +case "${KILL}" in true) VETHS="$(awk -Fnetwork-veth-extra= '/^network-veth-extra=/ { print $2 }' ${CONFIG}/${NAME}.conf | awk -F: '{ print $1 }')" @@ -295,6 +334,16 @@ case "${FORCE}" in ;; esac +case "${STATELESS}" in + true) + ;; + + *) + mkdir -p "/var/lib/${SOFTWARE}/state" + echo "stop" > "/var/lib/${SOFTWARE}/state/${NAME}.run" + ;; +esac + case "${VERBOSE}" in true) echo " done." |