summaryrefslogtreecommitdiffstats
path: root/libexec
diff options
context:
space:
mode:
Diffstat (limited to 'libexec')
-rwxr-xr-xlibexec/container/auto2
-rwxr-xr-xlibexec/container/build2
-rwxr-xr-xlibexec/container/console2
-rwxr-xr-xlibexec/container/enter2
-rwxr-xr-xlibexec/container/get2
-rwxr-xr-xlibexec/container/info2
-rwxr-xr-xlibexec/container/key2
-rwxr-xr-xlibexec/container/limit2
-rwxr-xr-xlibexec/container/list6
-rwxr-xr-xlibexec/container/log2
-rwxr-xr-xlibexec/container/move2
-rwxr-xr-xlibexec/container/rebuild152
-rwxr-xr-xlibexec/container/remove2
-rwxr-xr-xlibexec/container/restart2
-rwxr-xr-xlibexec/container/start38
-rwxr-xr-xlibexec/container/stop20
-rwxr-xr-xlibexec/container/top2
-rwxr-xr-xlibexec/container/update2
-rwxr-xr-xlibexec/container/version2
19 files changed, 222 insertions, 24 deletions
diff --git a/libexec/container/auto b/libexec/container/auto
index de5f292..927eae0 100755
--- a/libexec/container/auto
+++ b/libexec/container/auto
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/libexec/container/build b/libexec/container/build
index d6c938c..48f2d4b 100755
--- a/libexec/container/build
+++ b/libexec/container/build
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/libexec/container/console b/libexec/container/console
index 31da60d..be2b897 100755
--- a/libexec/container/console
+++ b/libexec/container/console
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/libexec/container/enter b/libexec/container/enter
index f1dae7f..b366ba6 100755
--- a/libexec/container/enter
+++ b/libexec/container/enter
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/libexec/container/get b/libexec/container/get
index 2b41ba8..0d0f420 100755
--- a/libexec/container/get
+++ b/libexec/container/get
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/libexec/container/info b/libexec/container/info
index d030780..699a253 100755
--- a/libexec/container/info
+++ b/libexec/container/info
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/libexec/container/key b/libexec/container/key
index e35c56c..5deff0d 100755
--- a/libexec/container/key
+++ b/libexec/container/key
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/libexec/container/limit b/libexec/container/limit
index 2c87b78..b7f6e9b 100755
--- a/libexec/container/limit
+++ b/libexec/container/limit
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/libexec/container/list b/libexec/container/list
index 2600bab..a56c1f8 100755
--- a/libexec/container/list
+++ b/libexec/container/list
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
@@ -387,10 +387,10 @@ do
*)
if ls "${MACHINES}/${CONTAINER}/etc/systemd/network"/*.network > /dev/null 2>&1
then
- ADDRESS="$(awk -FAddress= '/^Address/ { print $2 }' ${MACHINES}/${CONTAINER}/etc/systemd/network/*.network | head -n1)"
+ ADDRESS="$(for IP in $(awk -FAddress= '/^Address/ { print $2 }' ${MACHINES}/${CONTAINER}/etc/systemd/network/*.network); do echo -n "${IP} "; done)"
elif [ -e "${MACHINES}/${CONTAINER}/etc/network/interfaces" ]
then
- ADDRESS="$(awk '/address/ { print $2 }' ${MACHINES}/${CONTAINER}/etc/network/interfaces | head -n1)"
+ ADDRESS="$(for IP in $(awk '/address/ { print $2 }' ${MACHINES}/${CONTAINER}/etc/network/interfaces); do echo -n "${IP} "; done)"
fi
ADDRESS="${ADDRESS:-n/a}"
diff --git a/libexec/container/log b/libexec/container/log
index 9d11fd6..b7a000d 100755
--- a/libexec/container/log
+++ b/libexec/container/log
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/libexec/container/move b/libexec/container/move
index d41c995..fdc19e6 100755
--- a/libexec/container/move
+++ b/libexec/container/move
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/libexec/container/rebuild b/libexec/container/rebuild
new file mode 100755
index 0000000..e526520
--- /dev/null
+++ b/libexec/container/rebuild
@@ -0,0 +1,152 @@
+#!/bin/sh
+
+# Copyright (C) 2014-2022 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 <https://www.gnu.org/licenses/>.
+
+set -e
+
+PROJECT="open-infrastructure"
+SOFTWARE="compute-tools"
+PROGRAM="container"
+COMMAND="$(basename ${0})"
+
+HOOKS="/etc/${SOFTWARE}/hooks"
+MACHINES="/var/lib/machines"
+
+Parameters ()
+{
+ OPTIONS_ALL=""
+
+ GETOPT_LONGOPTIONS="name:,force,verbose,"
+ GETOPT_OPTIONS="n:,f,v,"
+
+ 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
+ ;;
+
+ -f|--force)
+ FORCE="true"
+ shift 1
+
+ OPTIONS_ALL="${OPTIONS_ALL} --force"
+ ;;
+
+ -v|--verbose)
+ VERBOSE="true"
+ shift 1
+
+ OPTIONS_ALL="${OPTIONS_ALL} --verbose"
+ ;;
+
+ --)
+ shift 1
+ break
+ ;;
+
+ *)
+ echo "'${COMMAND}': getopt error" >&2
+ exit 1
+ ;;
+ esac
+ done
+}
+
+Usage ()
+{
+ echo "Usage: ${PROGRAM} ${COMMAND} -n|--name NAME [-f|--force] [-v|--verbose]" >&2
+ echo
+ echo "See ${COMMAND}(1), ${PROGRAM}(1) and ${PROJECT}(7) for more information."
+
+ exit 1
+}
+
+Parameters "${@}"
+
+if [ -z "${NAME}" ]
+then
+ Usage
+fi
+
+case "${NAME}" in
+ ALL)
+ NAMES="$(${PROGRAM} list --format shell --started)"
+
+ for NAME in ${NAMES}
+ do
+ ${PROGRAM} rebuild,start --name ${NAME} ${OPTIONS_ALL} || true
+ done
+
+ exit 0
+ ;;
+esac
+
+if [ ! -e "${MACHINES}/${NAME}" ]
+then
+ echo "'${NAME}': no such container" >&2
+ exit 1
+fi
+
+# Pre hooks
+for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
+
+# Run
+case "${VERBOSE}" in
+ true)
+ echo -n "Rebuilding container ${NAME}..."
+ ;;
+esac
+
+${PROGRAM} stop ${OPTIONS_ALL} --name ${NAME} || true
+sleep 0.5
+${PROGRAM} remove ${OPTIONS_ALL} --name ${NAME} || true
+sleep 0.5
+${PROGRAM} build --name ${NAME} || true
+
+case "${VERBOSE}" in
+ true)
+ echo " done."
+ ;;
+esac
+
+# Post hooks
+for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
diff --git a/libexec/container/remove b/libexec/container/remove
index 03303a7..86f237d 100755
--- a/libexec/container/remove
+++ b/libexec/container/remove
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/libexec/container/restart b/libexec/container/restart
index c172731..fcb28b8 100755
--- a/libexec/container/restart
+++ b/libexec/container/restart
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/libexec/container/start b/libexec/container/start
index da6be24..1b53628 100755
--- a/libexec/container/start
+++ b/libexec/container/start
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
@@ -191,6 +191,13 @@ case "${HOST_ARCHITECTURE}" in
;;
esac
+if systemctl status systemd-networkd > /dev/null 2>&1
+then
+ NETWORK_SUBSYSTEM="systemd-networkd"
+else
+ NETWORK_SUBSYSTEM="ifupdown"
+fi
+
case "${START}" in
start)
;;
@@ -390,7 +397,22 @@ then
if [ -n "${BRIDGE}" ] && [ -n "${INTERFACE}" ]
then
- mkdir -p /run/systemd/network
+ case "${NETWORK_SUBSYSTEM}" in
+ ifupdown)
+
+cat > "/etc/network/interfaces.d/${INTERFACE}" << EOF
+allow-hotplug ${INTERFACE}
+iface ${INTERFACE} inet manual
+ pre-up ip link set ${INTERFACE} up
+ post-up ip link set ${INTERFACE} master ${BRIDGE}
+ pre-down ip link set ${INTERFACE} nomaster
+ post-down ip link set ${INTERFACE} down
+EOF
+
+ ;;
+
+ systemd-networkd)
+ mkdir -p /run/systemd/network
cat > "/run/systemd/network/${INTERFACE}.network" << EOF
[Match]
@@ -398,10 +420,18 @@ Name=${INTERFACE}
[Network]
Bridge=${BRIDGE}
+cat > "/etc/network/interfaces.d/${INTERFACE}" << EOF
+allow-hotplug ${INTERFACE}
+iface ${INTERFACE} inet manual
+ pre-up ip link set ${INTERFACE} up
+ post-up ip link set ${INTERFACE} master ${BRIDGE}
+ pre-down ip link set ${INTERFACE} nomaster
+ post-down ip link set ${INTERFACE} down
EOF
- networkctl reload
-
+ networkctl reload
+ ;;
+ esac
else
echo "Warning bridge definition '${BRIDGE_DEFINITION}' not recognized (expected <bridge>:<interface>): Ignoring"
fi
diff --git a/libexec/container/stop b/libexec/container/stop
index d2db38e..cb85c8d 100755
--- a/libexec/container/stop
+++ b/libexec/container/stop
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
@@ -146,6 +146,13 @@ then
exit 1
fi
+if systemctl status systemd-networkd > /dev/null 2>&1
+then
+ NETWORK_SUBSYSTEM="systemd-networkd"
+else
+ NETWORK_SUBSYSTEM="ifupdown"
+fi
+
# Pre hooks
for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
do
@@ -220,7 +227,16 @@ case "${CLEAN}" in
for VETH in ${VETHS}
do
INTERFACE="$(echo ${VETH} | awk -F: '{ print $1 }')"
- FILE="/run/systemd/network/${INTERFACE}.network"
+
+ case "${NETWORK_SUBSYSTEM}" in
+ ifupdown)
+ FILE="/etc/network/interfaces.d/${INTERFACE}"
+ ;;
+
+ systemd-networkd)
+ FILE="/run/systemd/network/${INTERFACE}.network"
+ ;;
+ esac
if [ -f "${FILE}" ]
then
diff --git a/libexec/container/top b/libexec/container/top
index 20e2a29..268da9a 100755
--- a/libexec/container/top
+++ b/libexec/container/top
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/libexec/container/update b/libexec/container/update
index c5ff6c2..e2d9c80 100755
--- a/libexec/container/update
+++ b/libexec/container/update
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
diff --git a/libexec/container/version b/libexec/container/version
index 3b33a4d..e580688 100755
--- a/libexec/container/version
+++ b/libexec/container/version
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#