From 9005f8a27ffc7bff682b0e627eeaa76ef5bf95fb Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 30 Oct 2020 17:37:56 +0100 Subject: Cleaning up and harmonizing verbose output for container remove, restart, start, and stop commands. Signed-off-by: Daniel Baumann --- lib/container/remove | 18 ++++++++++++------ lib/container/restart | 33 +++++++++++++++++++++++---------- lib/container/start | 22 ++++++++++++++++------ lib/container/stop | 31 ++++++++++++++++++++++--------- share/man/container-restart.1.txt | 3 +++ share/man/container-stop.1.txt | 3 +++ 6 files changed, 79 insertions(+), 31 deletions(-) diff --git a/lib/container/remove b/lib/container/remove index 820e45e..3ee7195 100755 --- a/lib/container/remove +++ b/lib/container/remove @@ -126,12 +126,6 @@ case "${NAME}" in for NAME in ${NAMES} do - case "${VERBOSE}" in - true) - echo "Removing container ${NAME}..." - ;; - esac - ${PROGRAM} remove --name ${NAME} ${OPTIONS_ALL} || true done @@ -238,9 +232,21 @@ then fi # Run +case "${VERBOSE}" in + true) + echo -n "Removing container ${NAME}..." + ;; +esac + rm --preserve-root --one-file-system -rf ${RM_OPTIONS} "${MACHINES}/${NAME}" rm -f ${RM_OPTIONS} "${CONFIG}/${NAME}.conf" +case "${VERBOSE}" in + true) + echo " done." + ;; +esac + # Post hooks for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}" do diff --git a/lib/container/restart b/lib/container/restart index f78cfff..83859e2 100755 --- a/lib/container/restart +++ b/lib/container/restart @@ -30,8 +30,8 @@ Parameters () { OPTIONS_ALL="" - GETOPT_LONGOPTIONS="name:," - GETOPT_OPTIONS="n:," + GETOPT_LONGOPTIONS="name:,verbose," + GETOPT_OPTIONS="n:,v," PARAMETERS="$(getopt --longoptions ${GETOPT_LONGOPTIONS} --name=${COMMAND} --options ${GETOPT_OPTIONS} --shell sh -- ${@})" @@ -51,6 +51,13 @@ Parameters () shift 2 ;; + -v|--verbose) + VERBOSE="true" + shift 1 + + OPTIONS_ALL="${OPTIONS_ALL} --verbose" + ;; + --) shift 1 break @@ -66,7 +73,7 @@ Parameters () Usage () { - echo "Usage: ${PROGRAM} ${COMMAND} -n|--name NAME" >&2 + echo "Usage: ${PROGRAM} ${COMMAND} -n|--name NAME [-v|--verbose]" >&2 exit 1 } @@ -83,13 +90,7 @@ case "${NAME}" in for NAME in ${NAMES} do - case "${VERBOSE}" in - true) - echo "Restarting container ${NAME}..." - ;; - esac - - ${PROGRAM} restart --name ${NAME} || true + ${PROGRAM} restart --name ${NAME} ${OPTIONS_ALL} || true done exit 0 @@ -112,8 +113,20 @@ do done # Run +case "${VERBOSE}" in + true) + echo -n "Restarting container ${NAME}..." + ;; +esac + machinectl reboot ${NAME} +case "${VERBOSE}" in + true) + echo " done." + ;; +esac + # Post hooks for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}" do diff --git a/lib/container/start b/lib/container/start index 6309fb1..52d7ceb 100755 --- a/lib/container/start +++ b/lib/container/start @@ -77,6 +77,9 @@ Parameters () -v|--verbose) VERBOSE="true" + shift 1 + + OPTIONS_ALL="${OPTIONS_ALL} --verbose" ;; --) @@ -114,12 +117,6 @@ case "${NAME}" in for NAME in ${NAMES} do - case "${VERBOSE}" in - true) - echo "Starting container ${NAME}..." - ;; - esac - ${PROGRAM} start --name ${NAME} ${OPTIONS_ALL} || true done @@ -516,6 +513,19 @@ case "${START}" in *) # Run + + case "${VERBOSE}" in + true) + echo -n "Starting container ${NAME}..." + ;; + esac + ${SETARCH} systemd-nspawn --keep-unit ${BIND} ${BIND_RO} ${BOOT} ${CAPABILITY} ${DIRECTORY} ${DROP_CAPABILITY} ${MACHINE} ${NETWORK_VETH_EXTRA} ${LINK_JOURNAL} ${REGISTER} + + case "${VERBOSE}" in + true) + echo " done." + ;; + esac ;; esac diff --git a/lib/container/stop b/lib/container/stop index a299cb1..899f1a1 100755 --- a/lib/container/stop +++ b/lib/container/stop @@ -33,8 +33,8 @@ Parameters () { OPTIONS_ALL="" - GETOPT_LONGOPTIONS="name:,force,clean," - GETOPT_OPTIONS="n:,f," + GETOPT_LONGOPTIONS="name:,force,clean,verbose," + GETOPT_OPTIONS="n:,f,v," PARAMETERS="$(getopt --longoptions ${GETOPT_LONGOPTIONS} --name=${COMMAND} --options ${GETOPT_OPTIONS} --shell sh -- ${@})" @@ -69,6 +69,13 @@ Parameters () OPTONS_ALL="${OPTIONS_ALL} --clean" ;; + -v|--verbose) + VERBOSE="true" + shift 1 + + OPTIONS_ALL="${OPTIONS_ALL} --verbose" + ;; + --) shift 1 break @@ -84,7 +91,7 @@ Parameters () Usage () { - echo "Usage: ${PROGRAM} ${COMMAND} -n|--name NAME [-f|--force]" >&2 + echo "Usage: ${PROGRAM} ${COMMAND} -n|--name NAME [-f|--force] [-v|--verbose]" >&2 exit 1 } @@ -122,12 +129,6 @@ case "${NAME}" in for NAME in ${NAMES} do - case "${VERBOSE}" in - true) - echo "Stopping container ${NAME}..." - ;; - esac - ${PROGRAM} stop --name ${NAME} ${OPTIONS_ALL} || true done @@ -253,6 +254,12 @@ case "${FORCE}" in esac # Run +case "${VERBOSE}" in + true) + echo -n "Stopping container ${NAME}..." + ;; +esac + machinectl ${MODE} ${NAME} case "${FORCE}" in @@ -266,6 +273,12 @@ case "${FORCE}" in ;; esac +case "${VERBOSE}" in + true) + echo " done." + ;; +esac + # Post hooks for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}" do diff --git a/share/man/container-restart.1.txt b/share/man/container-restart.1.txt index b0d66e2..d130b2d 100644 --- a/share/man/container-restart.1.txt +++ b/share/man/container-restart.1.txt @@ -46,6 +46,9 @@ The following container options are available: *-n, --name='NAME'*:: Specify container name. Specifying 'ALL' will restart all started container. +*-v, --verbose*:: + Explain what is being done. + EXAMPLES -------- diff --git a/share/man/container-stop.1.txt b/share/man/container-stop.1.txt index 4450ba3..b0d268b 100644 --- a/share/man/container-stop.1.txt +++ b/share/man/container-stop.1.txt @@ -49,6 +49,9 @@ The following container options are available: *-f, --force*:: Instead of running the proper shutdown sequence, terminate all processes of the container imediatly. +*-v, --verbose*:: + Explain what is being done. + EXAMPLES -------- -- cgit v1.2.3