From 5776f47d6e5ee4fe7797ec31aad2e3bbbb08b8d2 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 17 Feb 2019 18:40:15 +0100 Subject: Adding upstream version 20190217. Signed-off-by: Daniel Baumann --- lib/container/auto | 7 ++- lib/container/console | 5 +- lib/container/create | 16 +++--- lib/container/enter | 5 +- lib/container/key | 5 +- lib/container/limit | 5 +- lib/container/list | 17 +++--- lib/container/log | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/container/move | 7 ++- lib/container/remove | 13 +++-- lib/container/restart | 11 ++-- lib/container/start | 13 +++-- lib/container/status | 5 +- lib/container/stop | 13 +++-- lib/container/top | 3 +- lib/container/version | 7 ++- 16 files changed, 214 insertions(+), 61 deletions(-) create mode 100755 lib/container/log (limited to 'lib/container') diff --git a/lib/container/auto b/lib/container/auto index 8477915..5e192da 100755 --- a/lib/container/auto +++ b/lib/container/auto @@ -1,7 +1,6 @@ #!/bin/sh -# container-tools - Manage systemd-nspawn containers -# Copyright (C) 2014-2018 Daniel Baumann +# Copyright (C) 2014-2019 Daniel Baumann # # SPDX-License-Identifier: GPL-3.0+ # @@ -22,8 +21,8 @@ set -e COMMAND="$(basename ${0})" -CONFIG="/etc/container-tools/config" -HOOKS="/etc/container-tools/hooks" +CONFIG="/etc/compute-tools/container/config" +HOOKS="/etc/compute-tools/container/hooks" Parameters () { diff --git a/lib/container/console b/lib/container/console index dfc9b5c..2b579c8 100755 --- a/lib/container/console +++ b/lib/container/console @@ -1,7 +1,6 @@ #!/bin/sh -# container-tools - Manage systemd-nspawn containers -# Copyright (C) 2014-2018 Daniel Baumann +# Copyright (C) 2014-2019 Daniel Baumann # # SPDX-License-Identifier: GPL-3.0+ # @@ -22,7 +21,7 @@ set -e COMMAND="$(basename ${0})" -HOOKS="/etc/container-tools/hooks" +HOOKS="/etc/compute-tools/container/hooks" MACHINES="/var/lib/machines" Parameters () diff --git a/lib/container/create b/lib/container/create index 561584c..73c5493 100755 --- a/lib/container/create +++ b/lib/container/create @@ -1,7 +1,6 @@ #!/bin/sh -# container-tools - Manage systemd-nspawn containers -# Copyright (C) 2014-2018 Daniel Baumann +# Copyright (C) 2014-2019 Daniel Baumann # # SPDX-License-Identifier: GPL-3.0+ # @@ -22,10 +21,11 @@ set -e COMMAND="$(basename ${0})" -CONFIG="/etc/container-tools/config" -HOOKS="/etc/container-tools/hooks" +CONFIG="/etc/compute-tools/container/config" +HOOKS="/etc/compute-tools/container/hooks" MACHINES="/var/lib/machines" -SCRIPTS="/usr/share/container-tools/scripts" +SCRIPTS="/usr/share/compute-tools/container/scripts" +CONFIG_TEMPLATE="/usr/share/compute-tools/container/config/container.conf.in" Parameters () { @@ -141,8 +141,8 @@ then TARGET="$(basename $(readlink ${SCRIPTS}/default))" case "${TARGET}" in - container-tools_script) - TARGET="$(basename $(readlink /etc/alternatives/container-tools_script))" + container_script) + TARGET="$(basename $(readlink /etc/alternatives/container_script))" ;; esac @@ -251,7 +251,7 @@ sed -e "s|@CNT_AUTO@|${CNT_AUTO}|g" \ -e "s|@NETWORK_VETH_EXTRA@|${NETWORK_VETH_EXTRA}|g" \ -e "s|@PRIVATE_USERS@|no|g" \ -e "s|@REGISTER@|yes|g" \ -/usr/share/container-tools/config/container.conf.in > "${CONFIG}/${NAME}.conf" +"${CONFIG_TEMPLATE}" > "${CONFIG}/${NAME}.conf" # Run "${SCRIPTS}/${SCRIPT}" $(echo "${@}" | sed -e 's| -- | |') diff --git a/lib/container/enter b/lib/container/enter index 72b3b1c..a96c399 100755 --- a/lib/container/enter +++ b/lib/container/enter @@ -1,7 +1,6 @@ #!/bin/sh -# container-tools - Manage systemd-nspawn containers -# Copyright (C) 2014-2018 Daniel Baumann +# Copyright (C) 2014-2019 Daniel Baumann # # SPDX-License-Identifier: GPL-3.0+ # @@ -22,7 +21,7 @@ set -e COMMAND="$(basename ${0})" -HOOKS="/etc/container-tools/hooks" +HOOKS="/etc/compute-tools/container/hooks" MACHINES="/var/lib/machines" Parameters () diff --git a/lib/container/key b/lib/container/key index 3f0f57b..c2c31f1 100755 --- a/lib/container/key +++ b/lib/container/key @@ -1,7 +1,6 @@ #!/bin/sh -# container-tools - Manage systemd-nspawn containers -# Copyright (C) 2014-2018 Daniel Baumann +# Copyright (C) 2014-2019 Daniel Baumann # # SPDX-License-Identifier: GPL-3.0+ # @@ -22,7 +21,7 @@ set -e COMMAND="$(basename ${0})" -KEYS="/etc/container-tools/keys" +KEYS="/etc/compute-tools/container/keys" Parameters () { diff --git a/lib/container/limit b/lib/container/limit index f2d6bfa..68eb732 100755 --- a/lib/container/limit +++ b/lib/container/limit @@ -1,7 +1,6 @@ #!/bin/sh -# container-tools - Manage systemd-nspawn containers -# Copyright (C) 2014-2018 Daniel Baumann +# Copyright (C) 2014-2019 Daniel Baumann # # SPDX-License-Identifier: GPL-3.0+ # @@ -22,7 +21,7 @@ set -e COMMAND="$(basename ${0})" -HOOKS="/etc/container-tools/hooks" +HOOKS="/etc/compute-tools/container/hooks" MACHINES="/var/lib/machines" Parameters () diff --git a/lib/container/list b/lib/container/list index 816d521..c32203a 100755 --- a/lib/container/list +++ b/lib/container/list @@ -1,7 +1,6 @@ #!/bin/sh -# container-tools - Manage systemd-nspawn containers -# Copyright (C) 2014-2018 Daniel Baumann +# Copyright (C) 2014-2019 Daniel Baumann # # SPDX-License-Identifier: GPL-3.0+ # @@ -22,8 +21,8 @@ set -e COMMAND="$(basename ${0})" -CONFIG="/etc/container-tools/config" -HOOKS="/etc/container-tools/hooks" +CONFIG="/etc/compute-tools/container/config" +HOOKS="/etc/compute-tools/container/hooks" MACHINES="/var/lib/machines" VERSION="$(container version)" @@ -233,7 +232,7 @@ EOF csv) cat << EOF -# container-tools version ${VERSION} +# compute-tools version ${VERSION} Host${CSV_SEPARATOR}Container${CSV_SEPARATOR}Status${CSV_SEPARATOR}IPv4-Address EOF @@ -243,7 +242,7 @@ EOF cat << EOF { - "container-tools": { + "compute-tools": { "version": "${VERSION}", }, "host": { @@ -258,7 +257,7 @@ EOF NETWORK="$(echo ${HOST} | sed -e 's|\.|_|g')" cat << EOF -# container-tools ${VERSION} +# compute-tools ${VERSION} nwdiag { external_connector = none; network ${NETWORK} { @@ -308,9 +307,9 @@ EOF xml) cat << EOF - + ${VERSION} - + ${HOST} diff --git a/lib/container/log b/lib/container/log new file mode 100755 index 0000000..c39c58a --- /dev/null +++ b/lib/container/log @@ -0,0 +1,143 @@ +#!/bin/sh + +# Copyright (C) 2014-2019 Daniel Baumann +# +# 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 . + +set -e + +COMMAND="$(basename ${0})" + +LOG="/var/log/compute-tools/container.log" + +Parameters () +{ + GETOPT_LONGOPTIONS="name:,date:," + GETOPT_OPTIONS="n:,d:," + + 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 + -d|--date) + DATE="${2}" + shift 2 + ;; + + -n|--name) + NAME="${2}" + shift 2 + ;; + + -u|--user) + USER="${2}" + shift 2 + ;; + + --) + shift 1 + break + ;; + + *) + echo "'${COMMAND}': getopt error" >&2 + exit 1 + ;; + esac + done +} + +Usage () +{ + echo "Usage: container ${COMMAND} [-n|--name NAME] [-d|--date DATE|today|today-N|yesterday] [-u|--user USER]" >&2 + exit 1 +} + +Parameters "${@}" + +case "${DATE}" in + today-*) + DAYS="$(echo ${DATE} | awk -F- '{ print $2 }')" + + START="$(date -d "${DAYS} day ago" '+%Y-%m-%d')" + END="$(date +%Y-%m-%d)" + + DATE="(${START}" + + while true + do + DATE="${DATE}|${START}" + + if [ "${START}" = "${END}" ] + then + break + fi + + START="$(date +%Y-%m-%d --date "${START} +1 day")" + done + + DATE="${DATE})" + ;; + + today) + DATE="$(date +%Y-%m-%d)" + ;; + + yesterday) + DATE="$(date -d '1 day ago' '+%Y-%m-%d')" + ;; +esac + +if ls "${LOG}"-*.gz > /dev/null 2>&1 +then + LOGS="$(ls ${LOG}-*.gz) ${LOG}" +else + LOGS="${LOG}" +fi + +# FIXME: user + +for LOG in ${LOGS} +do + case "${LOG}" in + *.gz) + GREP="zgrep" + ;; + + *) + GREP="grep" + ;; + esac + + case "${NAME}" in + "") + ${GREP} -E "^${DATE}" "${LOG}" || true + ;; + + *) + ${GREP} -E "^${DATE}" "${LOG}" | grep " ${NAME}" || true + ;; + esac +done diff --git a/lib/container/move b/lib/container/move index e533b0e..6e12fa0 100755 --- a/lib/container/move +++ b/lib/container/move @@ -1,7 +1,6 @@ #!/bin/sh -# container-tools - Manage systemd-nspawn containers -# Copyright (C) 2014-2018 Daniel Baumann +# Copyright (C) 2014-2019 Daniel Baumann # # SPDX-License-Identifier: GPL-3.0+ # @@ -22,8 +21,8 @@ set -e COMMAND="$(basename ${0})" -CONFIG="/etc/container-tools/config" -HOOKS="/etc/container-tools/hooks" +CONFIG="/etc/compute-tools/container/config" +HOOKS="/etc/compute-tools/container/hooks" MACHINES="/var/lib/machines" Parameters () diff --git a/lib/container/remove b/lib/container/remove index 275c867..7e9d871 100755 --- a/lib/container/remove +++ b/lib/container/remove @@ -1,7 +1,6 @@ #!/bin/sh -# container-tools - Manage systemd-nspawn containers -# Copyright (C) 2014-2018 Daniel Baumann +# Copyright (C) 2014-2019 Daniel Baumann # # SPDX-License-Identifier: GPL-3.0+ # @@ -22,8 +21,8 @@ set -e COMMAND="$(basename ${0})" -CONFIG="/etc/container-tools/config" -HOOKS="/etc/container-tools/hooks" +CONFIG="/etc/compute-tools/container/config" +HOOKS="/etc/compute-tools/container/hooks" MACHINES="/var/lib/machines" Parameters () @@ -125,6 +124,12 @@ case "${NAME}" in for NAME in ${NAMES} do + case "${VERBOSE}" in + true) + echo "Removing container ${NAME}..." + ;; + esac + container remove --name ${NAME} ${OPTIONS_ALL} || true done diff --git a/lib/container/restart b/lib/container/restart index a22b970..7d2e31b 100755 --- a/lib/container/restart +++ b/lib/container/restart @@ -1,7 +1,6 @@ #!/bin/sh -# container-tools - Manage systemd-nspawn containers -# Copyright (C) 2014-2018 Daniel Baumann +# Copyright (C) 2014-2019 Daniel Baumann # # SPDX-License-Identifier: GPL-3.0+ # @@ -22,7 +21,7 @@ set -e COMMAND="$(basename ${0})" -HOOKS="/etc/container-tools/hooks" +HOOKS="/etc/compute-tools/container/hooks" MACHINES="/var/lib/machines" Parameters () @@ -82,6 +81,12 @@ case "${NAME}" in for NAME in ${NAMES} do + case "${VERBOSE}" in + true) + echo "Restarting container ${NAME}..." + ;; + esac + container restart --name ${NAME} || true done diff --git a/lib/container/start b/lib/container/start index ac0275e..8c8db44 100755 --- a/lib/container/start +++ b/lib/container/start @@ -1,7 +1,6 @@ #!/bin/sh -# container-tools - Manage systemd-nspawn containers -# Copyright (C) 2014-2018 Daniel Baumann +# Copyright (C) 2014-2019 Daniel Baumann # # SPDX-License-Identifier: GPL-3.0+ # @@ -22,8 +21,8 @@ set -e COMMAND="$(basename ${0})" -CONFIG="/etc/container-tools/config" -HOOKS="/etc/container-tools/hooks" +CONFIG="/etc/compute-tools/container/config" +HOOKS="/etc/compute-tools/container/hooks" MACHINES="/var/lib/machines" START="false" @@ -106,6 +105,12 @@ case "${NAME}" in for NAME in ${NAMES} do + case "${VERBOSE}" in + true) + echo "Starting container ${NAME}..." + ;; + esac + container start --name ${NAME} ${OPTIONS_ALL} || true done diff --git a/lib/container/status b/lib/container/status index 9c5ab20..6e4dd01 100755 --- a/lib/container/status +++ b/lib/container/status @@ -1,6 +1,5 @@ #!/bin/sh -# container-tools - Manage systemd-nspawn containers # Copyright (C) 2016 Simon Spöehel # # SPDX-License-Identifier: GPL-3.0+ @@ -22,8 +21,8 @@ set -e COMMAND="$(basename ${0})" -CONFIG="/etc/container-tools/config" -HOOKS="/etc/container-tools/hooks" +CONFIG="/etc/compute-tools/container/config" +HOOKS="/etc/compute-tools/container/hooks" MACHINES="/var/lib/machines" Parameters () diff --git a/lib/container/stop b/lib/container/stop index d996282..44977fd 100755 --- a/lib/container/stop +++ b/lib/container/stop @@ -1,7 +1,6 @@ #!/bin/sh -# container-tools - Manage systemd-nspawn containers -# Copyright (C) 2014-2018 Daniel Baumann +# Copyright (C) 2014-2019 Daniel Baumann # # SPDX-License-Identifier: GPL-3.0+ # @@ -22,8 +21,8 @@ set -e COMMAND="$(basename ${0})" -CONFIG="/etc/container-tools/config" -HOOKS="/etc/container-tools/hooks" +CONFIG="/etc/compute-tools/container/config" +HOOKS="/etc/compute-tools/container/hooks" MACHINES="/var/lib/machines" CLEAN="false" @@ -121,6 +120,12 @@ case "${NAME}" in for NAME in ${NAMES} do + case "${VERBOSE}" in + true) + echo "Stopping container ${NAME}..." + ;; + esac + container stop --name ${NAME} ${OPTIONS_ALL} || true done diff --git a/lib/container/top b/lib/container/top index 31ec005..674112e 100755 --- a/lib/container/top +++ b/lib/container/top @@ -1,7 +1,6 @@ #!/bin/sh -# container-tools - Manage systemd-nspawn containers -# Copyright (C) 2014-2018 Daniel Baumann +# Copyright (C) 2014-2019 Daniel Baumann # # SPDX-License-Identifier: GPL-3.0+ # diff --git a/lib/container/version b/lib/container/version index 543d6dc..75b57ce 100755 --- a/lib/container/version +++ b/lib/container/version @@ -1,7 +1,6 @@ #!/bin/sh -# container-tools - Manage systemd-nspawn containers -# Copyright (C) 2014-2018 Daniel Baumann +# Copyright (C) 2014-2019 Daniel Baumann # # SPDX-License-Identifier: GPL-3.0+ # @@ -22,8 +21,8 @@ set -e COMMAND="$(basename ${0})" -HOOKS="/etc/container-tools/hooks" -SHARE="/usr/share/container-tools" +HOOKS="/etc/compute-tools/container/hooks" +SHARE="/usr/share/compute-tools/container" # Pre hooks for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}" -- cgit v1.2.3