summaryrefslogtreecommitdiffstats
path: root/libexec/container/start
diff options
context:
space:
mode:
Diffstat (limited to 'libexec/container/start')
-rwxr-xr-xlibexec/container/start44
1 files changed, 41 insertions, 3 deletions
diff --git a/libexec/container/start b/libexec/container/start
index 089aa7d..1f22325 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+
#
@@ -99,6 +99,9 @@ Parameters ()
Usage ()
{
echo "Usage: ${PROGRAM} ${COMMAND} -n|--name NAME [-f|--force]" >&2
+ echo
+ echo "See ${COMMAND}(1), ${PROGRAM}(1) and ${PROJECT}(7) for more information."
+
exit 1
}
@@ -131,6 +134,12 @@ then
exit 1
fi
+# options
+if grep -Eqs "^ *cnt.start=" "${CONFIG}/${NAME}.conf" | grep -qs force
+then
+ FORCE="true"
+fi
+
case "${START}" in
false)
STATE="$(machinectl show ${NAME} 2>&1 | awk -FState= '/^State=/ { print $2 }')"
@@ -182,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)
;;
@@ -353,7 +369,7 @@ then
NETWORK_VETH_EXTRA="${NETWORK_VETH_EXTRA} --network-veth-extra=${VETH}"
INTERFACE="$(echo ${VETH} | awk -F: '{ print $1 }')"
- if [ "$(echo ${INTERFACE} | wc -c)" -gt 15 ]
+ if [ "$(echo ${INTERFACE} | wc -c)" -gt 16 ]
then
echo "'${INTERFACE}': name exceeds maximum of 15 characters, network might be not working."
fi
@@ -373,7 +389,7 @@ then
INTERFACE="$(echo ${BRIDGE_DEFINITION} | awk -F: '{ print $1 }')"
BRIDGE="$(echo ${BRIDGE_DEFINITION} | awk -F: '{ print $2 }')"
- if [ "$(echo ${INTERFACE} | wc -c)" -gt 15 ]
+ if [ "$(echo ${INTERFACE} | wc -c)" -gt 16 ]
then
echo "'${INTERFACE}': name exceeds maximum of 15 characters, network might be not working."
fi
@@ -381,6 +397,9 @@ then
if [ -n "${BRIDGE}" ] && [ -n "${INTERFACE}" ]
then
+ case "${NETWORK_SUBSYSTEM}" in
+ ifupdown)
+
cat > "/etc/network/interfaces.d/${INTERFACE}" << EOF
allow-hotplug ${INTERFACE}
iface ${INTERFACE} inet manual
@@ -390,6 +409,22 @@ iface ${INTERFACE} inet manual
post-down ip link set ${INTERFACE} down
EOF
+ ;;
+
+ systemd-networkd)
+ mkdir -p /run/systemd/network
+
+cat > "/run/systemd/network/${INTERFACE}.network" << EOF
+[Match]
+Name=${INTERFACE}
+
+[Network]
+Bridge=${BRIDGE}
+EOF
+
+ networkctl reload
+ ;;
+ esac
else
echo "Warning bridge definition '${BRIDGE_DEFINITION}' not recognized (expected <bridge>:<interface>): Ignoring"
fi
@@ -521,6 +556,9 @@ case "${START}" in
;;
esac
+ mkdir -p "/var/lib/${SOFTWARE}/state"
+ echo "start" > "/var/lib/${SOFTWARE}/state/${NAME}.run"
+
${SETARCH} systemd-nspawn --keep-unit ${BIND} ${BIND_RO} ${BOOT} ${CAPABILITY} ${DIRECTORY} ${DROP_CAPABILITY} ${MACHINE} ${NETWORK_VETH_EXTRA} ${LINK_JOURNAL} ${REGISTER}
case "${VERBOSE}" in