summaryrefslogtreecommitdiffstats
path: root/lib/container
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-02-09 16:18:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-02-09 16:18:22 +0000
commitc011654fff348560957804ce4db060b8f1b40f89 (patch)
tree9065f9029812e692f8ed9c6d6696e58a624ff29c /lib/container
parentAdding upstream version 20201030. (diff)
downloadopen-infrastructure-compute-tools-upstream/20210101.tar.xz
open-infrastructure-compute-tools-upstream/20210101.zip
Adding upstream version 20210101.upstream/20210101
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/container')
-rwxr-xr-xlib/container/auto2
-rwxr-xr-xlib/container/console2
-rwxr-xr-xlib/container/create2
-rwxr-xr-xlib/container/enter2
-rwxr-xr-xlib/container/key2
-rwxr-xr-xlib/container/limit2
-rwxr-xr-xlib/container/list2
-rwxr-xr-xlib/container/log2
-rwxr-xr-xlib/container/move2
-rwxr-xr-xlib/container/remove20
-rwxr-xr-xlib/container/restart35
-rwxr-xr-xlib/container/run127
-rwxr-xr-xlib/container/start24
-rwxr-xr-xlib/container/stop33
-rwxr-xr-xlib/container/top2
-rwxr-xr-xlib/container/version2
16 files changed, 215 insertions, 46 deletions
diff --git a/lib/container/auto b/lib/container/auto
index 16c2933..6c1d47b 100755
--- a/lib/container/auto
+++ b/lib/container/auto
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2020 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/lib/container/console b/lib/container/console
index 2a41bf5..2dc6546 100755
--- a/lib/container/console
+++ b/lib/container/console
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2020 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/lib/container/create b/lib/container/create
index 519a815..bdf9fb4 100755
--- a/lib/container/create
+++ b/lib/container/create
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2020 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/lib/container/enter b/lib/container/enter
index 144a06a..fed1193 100755
--- a/lib/container/enter
+++ b/lib/container/enter
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2020 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/lib/container/key b/lib/container/key
index f4e337c..4cbdaa0 100755
--- a/lib/container/key
+++ b/lib/container/key
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2020 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/lib/container/limit b/lib/container/limit
index 233459a..99ef03a 100755
--- a/lib/container/limit
+++ b/lib/container/limit
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2020 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/lib/container/list b/lib/container/list
index cf7b148..ba794ab 100755
--- a/lib/container/list
+++ b/lib/container/list
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2020 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/lib/container/log b/lib/container/log
index 2740213..a18c421 100755
--- a/lib/container/log
+++ b/lib/container/log
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2020 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/lib/container/move b/lib/container/move
index f87e5a8..e20d8a8 100755
--- a/lib/container/move
+++ b/lib/container/move
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2020 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/lib/container/remove b/lib/container/remove
index 820e45e..75ebd60 100755
--- a/lib/container/remove
+++ b/lib/container/remove
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2020 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
@@ -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..3c84f4d 100755
--- a/lib/container/restart
+++ b/lib/container/restart
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2020 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
@@ -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/run b/lib/container/run
new file mode 100755
index 0000000..f6323c0
--- /dev/null
+++ b/lib/container/run
@@ -0,0 +1,127 @@
+#!/bin/sh
+
+# Copyright (C) 2014-2019 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+#
+# SPDX-License-Identifier: GPL-3.0+
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+PROJECT="open-infrastructure"
+PROGRAM="container"
+COMMAND="$(basename ${0})"
+
+HOOKS="/etc/${PROJECT}/${PROGRAM}/hooks"
+MACHINES="/var/lib/machines"
+
+Parameters ()
+{
+ GETOPT_LONGOPTIONS="name:,"
+ GETOPT_OPTIONS="n:,"
+
+ PARAMETERS="$(getopt --longoptions ${GETOPT_LONGOPTIONS} --name=${COMMAND} --options ${GETOPT_OPTIONS} --shell sh -- ${@})"
+
+ if [ "${?}" != "0" ]
+ then
+ echo "'${COMMAND}': getopt exit" >&2
+ exit 1
+ fi
+
+ eval set -- "${PARAMETERS}"
+
+ while true
+ do
+ case "${1}" in
+ -n|--name)
+ NAME="${2}"
+ shift 2
+ ;;
+
+ --)
+ shift 1
+ break
+ ;;
+
+ *)
+ echo "'${COMMAND}': getopt error" >&2
+ exit 1
+ ;;
+ esac
+ done
+}
+
+Usage ()
+{
+ echo "Usage: ${PROGRAM} ${COMMAND} -n|--name NAME -- COMMAND" >&2
+ exit 1
+}
+
+Parameters "${@}"
+
+if [ -z "${NAME}" ]
+then
+ Usage
+fi
+
+if [ ! -e "${MACHINES}/${NAME}" ]
+then
+ echo "'${NAME}': no such container" >&2
+ exit 1
+fi
+
+STATE="$(machinectl show ${NAME} 2>&1 | awk -F= '/^State=/ { print $2 }')"
+
+case "${STATE}" in
+ running)
+ ;;
+
+ *)
+ echo "'${NAME}': container is not running" >&2
+ exit 1
+ ;;
+esac
+
+LEADER="$(machinectl status ${NAME} | awk '/Leader: / { print $2 }')"
+
+# Pre hooks
+for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
+
+SSH_CLIENT="${SSH_CLIENT:-127.0.0.1 0 0}"
+
+RUN="$(echo ${@} | awk -F-- '{ print $2}')"
+
+# Run
+nsenter --all --target "${LEADER}" --wd="${MACHINES}/${NAME}/root" /usr/bin/script -c "LC_ALL=C.UTF-8 /bin/bash -l -c \"${RUN}\"" -q /dev/null
+
+case "${SSH_CLIENT}" in
+ 127.0.0.1*)
+ unset SSH_CLIENT
+ ;;
+esac
+
+# Post hooks
+for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
diff --git a/lib/container/start b/lib/container/start
index 6309fb1..30aee53 100755
--- a/lib/container/start
+++ b/lib/container/start
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2020 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
@@ -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..6b8caee 100755
--- a/lib/container/stop
+++ b/lib/container/stop
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2020 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
@@ -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/lib/container/top b/lib/container/top
index 81c7436..d9baa1c 100755
--- a/lib/container/top
+++ b/lib/container/top
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2020 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/lib/container/version b/lib/container/version
index 8d7f052..c2b7716 100755
--- a/lib/container/version
+++ b/lib/container/version
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2020 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#