diff options
Diffstat (limited to '')
-rw-r--r-- | Makefile | 11 | ||||
-rwxr-xr-x | bin/container-autostart | 47 | ||||
-rwxr-xr-x | lib/container/create | 16 | ||||
-rw-r--r-- | share/config/container.conf.in | 1 | ||||
-rwxr-xr-x | share/scripts/debootstrap | 5 | ||||
-rw-r--r-- | share/systemd/container-autostart.service | 15 |
6 files changed, 91 insertions, 4 deletions
@@ -76,7 +76,18 @@ install: build ln -s container.1 $(DESTDIR)/usr/share/man/man1/cnt.1 ln -s container-shell.1 $(DESTDIR)/usr/share/man/man1/cntsh.1 + mkdir -p $(DESTDIR)/lib/systemd/system + cp -r share/systemd/* $(DESTDIR)/lib/systemd/system + uninstall: + for FILE in share/systemd*; \ + do \ + if [ -e "$${FILE}" ]; \ + then \ + rm -f $(DESTDIR)/lib/systemd/system/$$(basename $${FILE}); \ + fi; \ + done + for SECTION in $$(seq 1 8); \ do \ for FILE in share/man/*.$${SECTION}; \ diff --git a/bin/container-autostart b/bin/container-autostart new file mode 100755 index 0000000..28a7f27 --- /dev/null +++ b/bin/container-autostart @@ -0,0 +1,47 @@ +#!/bin/sh + +# Open Infrastructure: container-tools +# Copyright (C) 2014-2016 Daniel Baumann <daniel.baumann@open-infrastructure.net> +# +# 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 + +if [ ! -x /usr/bin/screen ] +then + echo "'${NAME}': /usr/bin/screen - no such file." >&2 + exit 1 +fi + +HOST="$(hostname -f)" + +HOME="${HOME:-/root}" +SHELL="/bin/bash" +export HOME SHELL + +cd "${HOME}" + +#screen -S container -A -d -m -t cnt bash -cl "cntsh && bash -l" +screen -S container -A -d -m -t cnt bash -l + +for CONFIG in /etc/container-tools/config/*.conf +do + if grep -Eqs "^ *cnt.autostart=true" "${CONFIG}" || grep -Eqs "^ *cnt.autostart=${HOST}" "${CONFIG}" + then + CONTAINER="$(basename ${CONFIG} .conf)" + TITLE="$(echo ${CONTAINER} | awk -F. '{ print $1 }')" + + screen -S container -X screen -t ${TITLE} bash -cl "cnt start -n ${CONTAINER} && bash -l" + fi +done diff --git a/lib/container/create b/lib/container/create index d267641..cfee91a 100755 --- a/lib/container/create +++ b/lib/container/create @@ -25,8 +25,8 @@ MACHINES="/var/lib/machines" Parameters () { - LONG_OPTIONS="name:,bind:,script:" - OPTIONS="n:,b:,s:" + LONG_OPTIONS="name:,cnt.autostart:,bind:,script:" + OPTIONS="n:,b:,c:,d:,s:" PARAMETERS="$(getopt --longoptions ${LONG_OPTIONS} --name=${COMMAND} --options ${OPTIONS} --shell sh -- ${@})" @@ -46,6 +46,11 @@ Parameters () shift 2 ;; + --cnt.autostart) + CNT_AUTOSTART="${2}" + shift 2 + ;; + -b|--bind) BIND="${2}" shift 2 @@ -71,7 +76,7 @@ Parameters () Usage () { - echo "Usage: container ${COMMAND} -n|--name NAME [-b|--bind DIRECTORY:DIRECTORY[:OPTIONS]] [-s|--script SCRIPT] [-- SCRIPT_OPTIONS]" >&2 + echo "Usage: container ${COMMAND} -n|--name NAME [--cnt.autostart=true|false|FQDN] [-b|--bind DIRECTORY:DIRECTORY[:OPTIONS]] [-s|--script SCRIPT] [-- SCRIPT_OPTIONS]" >&2 exit 1 } @@ -95,6 +100,8 @@ then echo "'${SCRIPT}': no such script" >&2 fi +CNT_AUTOSTART="${CNT_AUTOSTART:-$(hostname -f)}" + BINDS="$(echo ${BIND} | sed -e 's|;| |g')" for ENTRY in ${BINDS} @@ -110,7 +117,8 @@ done # config mkdir -p "${CONFIG}" -sed -e "s|@NAME@|${NAME}|g" \ +sed -e "s|@CNT_AUTOSTART@|${CNT_AUTOSTART}|g" \ + -e "s|@NAME@|${NAME}|g" \ -e "s|@BIND@|${BIND}|g" \ -e "s|@BOOT@|yes|g" \ -e "s|@DIRECTORY@|${MACHINES}/${NAME}|g" \ diff --git a/share/config/container.conf.in b/share/config/container.conf.in index 7a0d826..5b52c7d 100644 --- a/share/config/container.conf.in +++ b/share/config/container.conf.in @@ -1,6 +1,7 @@ # container-tools: @NAME@ [start] +cnt.autostart=@CNT_AUTOSTART@ bind=@BIND@ boot=@BOOT@ directory=@DIRECTORY@ diff --git a/share/scripts/debootstrap b/share/scripts/debootstrap index 0961fc9..c1699f7 100755 --- a/share/scripts/debootstrap +++ b/share/scripts/debootstrap @@ -45,6 +45,11 @@ Parameters () shift 2 ;; + --cnt.autostart) + # ignore + shift 2 + ;; + -s|--script) # ignore shift 2 diff --git a/share/systemd/container-autostart.service b/share/systemd/container-autostart.service new file mode 100644 index 0000000..1424ce8 --- /dev/null +++ b/share/systemd/container-autostart.service @@ -0,0 +1,15 @@ +[Unit] +Description=container-tools automatic start +After=syslog.target network.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/bin/container-autostart +#ExecStop= +Delegate=yes +StandardOutput=syslog +StandardError=syslog + +[Install] +WantedBy=multi-user.target |