summaryrefslogtreecommitdiffstats
path: root/libexec
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-06-29 11:29:23 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-06-29 11:38:54 +0000
commite07edad5f45907e9c7f4d6c24823b80cbe282316 (patch)
treeeb4049b82fc0765fe2f5d731ef52a3a15cdcd282 /libexec
parentAdding upstream version 20210411. (diff)
downloadopen-infrastructure-compute-tools-e07edad5f45907e9c7f4d6c24823b80cbe282316.tar.xz
open-infrastructure-compute-tools-e07edad5f45907e9c7f4d6c24823b80cbe282316.zip
Adding upstream version 20210628.upstream/20210628
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libexec')
-rwxr-xr-xlibexec/container/create10
-rwxr-xr-xlibexec/container/info214
-rwxr-xr-xlibexec/container/list25
-rwxr-xr-xlibexec/container/start6
4 files changed, 245 insertions, 10 deletions
diff --git a/libexec/container/create b/libexec/container/create
index 418bc35..af85007 100755
--- a/libexec/container/create
+++ b/libexec/container/create
@@ -32,7 +32,7 @@ CONFIG_TEMPLATE="/usr/share/${SOFTWARE}/config/container.conf.in"
Parameters ()
{
- GETOPT_LONGOPTIONS="name:,cnt.container-server:,cnt.overlay:,cnt.overlay-options:,bind:,bind-ro:,capability:,drop-capability:,script:,verbose,"
+ GETOPT_LONGOPTIONS="name:,cnt.container-server:,cnt.overlay:,cnt.overlay-options:,start:,bind:,bind-ro:,capability:,drop-capability:,script:,verbose,"
GETOPT_OPTIONS="n:,b:,c:,d:,s:,v,"
PARAMETERS="$(getopt --longoptions ${GETOPT_LONGOPTIONS} --name=${COMMAND} --options ${GETOPT_OPTIONS} --shell sh -- ${@})"
@@ -73,6 +73,11 @@ Parameters ()
shift 2
;;
+ --cnt.start)
+ CNT_START="${2}"
+ shift 2
+ ;;
+
-b|--bind)
BIND="${2}"
shift 2
@@ -118,7 +123,7 @@ Parameters ()
Usage ()
{
- echo "Usage: ${PROGRAM} ${COMMAND} -n|--name NAME [--cnt.container-server=true|false|FQDN] [--cnt.overlay=DIRECTORY_LOWER:DIRECTORY_UPPER:DIRECTORY_WORK:DIRECTORY_MERGED] [--cnt.overlay-options=OPTION[,OPTION]] [-b|--bind DIRECTORY:DIRECTORY[:OPTIONS]] [--bind-ro DIRECTORY:DIRECTORY[:OPTIONS]] [-c|--capability CAPABILITY[,CAPABILITY]] [-d|--drop-capability DROP_CAPABILITY[,DROP_CAPABILITY]] [-s|--script SCRIPT] [-v|--verbose] [-- SCRIPT_OPTIONS]" >&2
+ echo "Usage: ${PROGRAM} ${COMMAND} -n|--name NAME [--cnt.container-server=true|false|FQDN] [--cnt.overlay=DIRECTORY_LOWER:DIRECTORY_UPPER:DIRECTORY_WORK:DIRECTORY_MERGED] [--cnt.overlay-options=OPTION[,OPTION]] [--cnt.start=OPTION[,OPTION]] [-b|--bind DIRECTORY:DIRECTORY[:OPTIONS]] [--bind-ro DIRECTORY:DIRECTORY[:OPTIONS]] [-c|--capability CAPABILITY[,CAPABILITY]] [-d|--drop-capability DROP_CAPABILITY[,DROP_CAPABILITY]] [-s|--script SCRIPT] [-v|--verbose] [-- SCRIPT_OPTIONS]" >&2
exit 1
}
@@ -248,6 +253,7 @@ sed -e "s|@CNT_AUTO@|${CNT_AUTO}|g" \
-e "s|@CNT_NETWORK_BRIDGE@|${CNT_NETWORK_BRIDGE}|g" \
-e "s|@CNT_OVERLAY@|${CNT_OVERLAY}|g" \
-e "s|@CNT_OVERLAY_OPTIONS@|${CNT_OVERLAY_OPTIONS}|g" \
+ -e "s|@CNT_START@|${CNT_START}|g" \
-e "s|@NAME@|${NAME}|g" \
-e "s|@BIND@|${BIND}|g" \
-e "s|@BIND_RO@|${BIND_RO}|g" \
diff --git a/libexec/container/info b/libexec/container/info
new file mode 100755
index 0000000..63c42ff
--- /dev/null
+++ b/libexec/container/info
@@ -0,0 +1,214 @@
+#!/bin/sh
+
+# Copyright (C) 2014-2021 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})"
+
+CONFIG="/etc/${SOFTWARE}/config"
+HOOKS="/etc/${SOFTWARE}/hooks"
+MACHINES="/var/lib/machines"
+
+VERSION="$(${PROGRAM} version)"
+
+Parameters ()
+{
+ GETOPT_LONGOPTIONS="name:,status,os,ip,"
+ 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
+ ;;
+
+ --status)
+ ACTIONS="${ACTIONS} status"
+ shift 1
+ ;;
+
+ --os)
+ ACTIONS="${ACTIONS} os"
+ shift 1
+ ;;
+
+ --ip)
+ ACTIONS="${ACTIONS} ip"
+ shift 1
+ ;;
+
+ --)
+ shift 1
+ break
+ ;;
+
+ *)
+ echo "'${COMMAND}': getopt error" >&2
+ exit 1
+ ;;
+ esac
+ done
+}
+
+Usage ()
+{
+ echo "Usage: ${PROGRAM} ${COMMAND} -n|--name NAME [--status] [--os] [--ip]" >&2
+ exit 1
+}
+
+Parameters "${@}"
+
+# Pre hooks
+for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
+
+ACTIONS="${ACTIONS:-status os ip}"
+HOST="$(cat /etc/hostname)"
+
+# Run
+
+# Status
+STATUS="$(machinectl show ${NAME} 2>&1 | awk -FState= '/^State=/ { print $2 }')"
+
+if [ -e "${CONFIG}/${NAME}.conf" ]
+then
+ CONTAINER_SERVER="$(awk -Fcnt.container-server= '/^cnt.container-server=/ { print $2 }' ${CONFIG}/${NAME}.conf)"
+ CONTAINER_SERVER="${CONTAINER_SERVER:-false}"
+
+ case "${CONTAINER_SERVER}" in
+ ${HOST}|true)
+ ;;
+
+ *)
+ STATUS="other"
+ ;;
+ esac
+else
+ STATUS="other"
+fi
+
+case "${STATUS}" in
+ running)
+ STATUS="started"
+ ;;
+
+ other)
+ ;;
+
+ *)
+ STATUS="stopped"
+ ;;
+esac
+
+# OS
+VERSION_BASH="$(chroot ${MACHINES}/${NAME} apt-cache policy bash | awk '/Installed: / { print $2 }')"
+
+case "${VERSION_BASH}" in
+ 4.1*)
+ OS="Debian 6 (squeeze)"
+ ;;
+
+ 4.2*)
+ OS="Debian 7 (wheezy)"
+ ;;
+
+ 4.3*)
+ OS="Debian 8 (jessie)"
+ ;;
+
+ 4.4*)
+ OS="Debian 9 (stretch)"
+ ;;
+
+ 5.0*)
+ OS="Debian 10 (buster)"
+ ;;
+
+ 5.1*)
+ OS="Debian 11 (bullseye)"
+ ;;
+
+ *)
+ OS="n/a"
+ ;;
+esac
+
+case "${STATUS}" in
+ started)
+ IP="$(cnt run -n ${NAME} -- hostname -I | awk '{ print $1 }')"
+ ;;
+
+ *)
+ if ls "${MACHINES}/${CONTAINER}/etc/systemd/network"/*.network > /dev/null 2>&1
+ then
+ IP="$(awk -FAddress= '/^Address/ { print $2 }' ${MACHINES}/${CONTAINER}/etc/systemd/network/*.network | head -n1)"
+ elif [ -e "${MACHINES}/${CONTAINER}/etc/network/interfaces" ]
+ then
+ IP="$(awk '/address/ { print $2 }' ${MACHINES}/${CONTAINER}/etc/network/interfaces | head -n1)"
+ fi
+
+ IP="${IP:-n/a}"
+ ;;
+esac
+
+for ACTION in ${ACTIONS}
+do
+ case "${ACTION}" in
+ status)
+ echo "${STATUS}"
+ ;;
+
+ os)
+ echo "${OS}"
+ ;;
+
+ ip)
+ echo "${IP}"
+ ;;
+ esac
+done
+
+# 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/list b/libexec/container/list
index 30446c0..3ef6e49 100755
--- a/libexec/container/list
+++ b/libexec/container/list
@@ -366,15 +366,24 @@ do
ADDRESS=""
- 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)"
- elif [ -e "${MACHINES}/${CONTAINER}/etc/network/interfaces" ]
- then
- ADDRESS="$(awk '/address/ { print $2 }' ${MACHINES}/${CONTAINER}/etc/network/interfaces | head -n1)"
- fi
+ case "${STATE}" in
+ started)
+ ADDRESS="$(cnt run -n ${CONTAINER} -- hostname -I | sed -e 's|\r$||' | awk '{ print $1 }')"
+ ADDRESS="${ADDRESS:-none}"
+ ;;
- ADDRESS="${ADDRESS:-n/a}"
+ *)
+ 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)"
+ elif [ -e "${MACHINES}/${CONTAINER}/etc/network/interfaces" ]
+ then
+ ADDRESS="$(awk '/address/ { print $2 }' ${MACHINES}/${CONTAINER}/etc/network/interfaces | head -n1)"
+ fi
+
+ ADDRESS="${ADDRESS:-n/a}"
+ ;;
+ esac
if echo ${LIST} | grep -qs all
then
diff --git a/libexec/container/start b/libexec/container/start
index 089aa7d..08c3611 100755
--- a/libexec/container/start
+++ b/libexec/container/start
@@ -131,6 +131,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 }')"