summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@open-infrastructure.net>2018-01-26 06:45:27 +0000
committerDaniel Baumann <daniel.baumann@open-infrastructure.net>2018-02-18 14:43:19 +0000
commitd6247c49ced964a8f13d0f5a925f35752326039a (patch)
tree488b5ab5aa896c5556f432ceb87cd768bdba23df
parentUpdating year in copyright information for 2018. (diff)
downloadcompute-tools-d6247c49ced964a8f13d0f5a925f35752326039a.tar.xz
compute-tools-d6247c49ced964a8f13d0f5a925f35752326039a.zip
Adding container remove --allow-stop option to override abort of running containers and stop them prior removal.
Signed-off-by: Daniel Baumann <daniel.baumann@open-infrastructure.net>
Diffstat (limited to '')
-rwxr-xr-xlib/container/remove22
-rw-r--r--share/man/container-remove.1.txt6
2 files changed, 24 insertions, 4 deletions
diff --git a/lib/container/remove b/lib/container/remove
index c077cc0..e8dd653 100755
--- a/lib/container/remove
+++ b/lib/container/remove
@@ -28,7 +28,7 @@ MACHINES="/var/lib/machines"
Parameters ()
{
- GETOPT_LONGOPTIONS="name:,force,verbose,"
+ GETOPT_LONGOPTIONS="name:,allow-stop,force,verbose,"
GETOPT_OPTIONS="n:,f,v,"
PARAMETERS="$(getopt --longoptions ${GETOPT_LONGOPTIONS} --name=${COMMAND} --options ${GETOPT_OPTIONS} --shell sh -- ${@})"
@@ -49,6 +49,11 @@ Parameters ()
shift 2
;;
+ --allow-stop)
+ ALLOW_STOP="true"
+ shift 1
+ ;;
+
-f|--force)
FORCE="true"
shift 1
@@ -74,7 +79,7 @@ Parameters ()
Usage ()
{
- echo "Usage: container ${COMMAND} -n|--name NAME [-f|--force] [-v|--verbose]" >&2
+ echo "Usage: container ${COMMAND} -n|--name NAME [--allow-stop] [-f|--force] [-v|--verbose]" >&2
exit 1
}
@@ -116,8 +121,17 @@ STATE="$(machinectl show ${NAME} 2>&1 | awk -F= '/^State=/ { print $2 }')"
case "${STATE}" in
running)
- echo "'${NAME}': container is started" >&2
- exit 1
+ case "${ALLOW_STOP}" in
+ true)
+ echo "'${NAME}': container is started, stopping it now" >&2
+ container stop -n ${NAME}
+ ;;
+
+ *)
+ echo "'${NAME}': container is started" >&2
+ exit 1
+ ;;
+ esac
;;
esac
diff --git a/share/man/container-remove.1.txt b/share/man/container-remove.1.txt
index bb07762..ab807f4 100644
--- a/share/man/container-remove.1.txt
+++ b/share/man/container-remove.1.txt
@@ -48,6 +48,9 @@ The following container options are available:
*-n, --name='NAME'*::
Specify container name.
+*--allow-stop*::
+ Stop container prior removal.
+
*-f, --force*::
Do not prompt before removal.
@@ -63,6 +66,9 @@ EXAMPLES
*Remove example.net container from the system without prompt:*::
sudo container remove -n example.net -f
+*Remove a running container from the system, without prompt:*::
+ sudo container remove -n example.net -f --allow-stop
+
SEE ALSO
--------