summaryrefslogtreecommitdiffstats
path: root/lib/container/remove
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2018-02-18 15:12:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2018-02-18 15:12:33 +0000
commitb609b560db2c50b53a7243e257b0692dd612ad06 (patch)
tree140ac1a219edd21244fc1f2d5989342aa7711f0c /lib/container/remove
parentAdding upstream version 20180118. (diff)
downloadopen-infrastructure-compute-tools-b609b560db2c50b53a7243e257b0692dd612ad06.tar.xz
open-infrastructure-compute-tools-b609b560db2c50b53a7243e257b0692dd612ad06.zip
Adding upstream version 20180218.upstream/20180218
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/container/remove')
-rwxr-xr-xlib/container/remove24
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/container/remove b/lib/container/remove
index 6310597..e8dd653 100755
--- a/lib/container/remove
+++ b/lib/container/remove
@@ -1,7 +1,7 @@
#!/bin/sh
# container-tools - Manage systemd-nspawn containers
-# Copyright (C) 2014-2017 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2018 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
@@ -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