[lxc-devel] [PATCH] v2 Refactoring lxc-autostart boot process and group handling.
Michael H. Warfield
mhw at WittsEnd.com
Tue May 20 14:26:13 UTC 2014
On Tue, 2014-05-20 at 11:56 +0200, Stéphane Graber wrote:
> On Mon, May 19, 2014 at 03:57:26PM -0400, Michael H. Warfield wrote:
> > On Mon, 2014-05-19 at 17:22 +0200, Stéphane Graber wrote:
> > > On Fri, May 16, 2014 at 02:07:31PM -0400, Michael H. Warfield wrote:
> > > > Before anyone else spots it... I did miss one spot where I failed to
> > > > toss a list (cmd_group_lists) on exit. So, some memory checkers will
> > > > complain about orphaned memory or leaks (even though it's on exit).
> > > > I'll fix that and add some doco once this has been reviewed further.
> >
> > > Hi,
> >
> > > I took a quick look at the proposed patch and don't have any issue with
> > > it, so please resend with those updates done and I'll do some proper
> > > testing and apply it.
> >
> > > Thanks!
> >
> > Ok... Ask and yea shall receive. Version 2 of the refactoring
> > autostart patch with Dwight's patch and my other patches adding now the
> > fix for the minor cleanup gotcha I spotted plus I enhanced the
> > documentation in lxc-autostart.sgml.in for group handling.
> >
> > While this was going on, I also pinged Dwight about parameterizing the
> > bootup groups and other options in the startup scripts. Consequently,
> > with his concurrence, I've added some boot time configuration options to
> > the sysvinit/systemd init script and the upstart configuration file for
> > BOOTGROUPS, SHUTDOWNDELAY, OPTIONS, and STOPOPTS. For the former
> > (Oracle, RHEL Fedora, CentOS, et al), it's in /etc/sysconfig/lxc and the
> > later (Ubuntu, Debian, etc) in /etc/default/lxc. I've tested the
> > sysvinit/systemd init script. Someone needs to verify the upstart
> > changes.
> >
> > Attached below the jump.
> >
> > Thanks!
> >
> > Regards,
> > Mike
>
> ==> Executing: "./autogen.sh" in /build/git/
> + test -d autom4te.cache
> + aclocal -I config
> + autoheader
> + autoconf
> + automake --add-missing --copy
> configure.ac:31: installing 'config/compile'
> configure.ac:30: installing 'config/config.guess'
> configure.ac:30: installing 'config/config.sub'
> configure.ac:29: installing 'config/install-sh'
> configure.ac:29: installing 'config/missing'
> configure.ac:565: error: required file 'config/init/systemd/lxc.service.in' not found
> configure.ac:565: error: required file 'config/init/sysvinit/lxc.in' not found
> src/lua-lxc/Makefile.am: installing 'config/depcomp'
> + exit 1
> ==> Cleaning up the environment
> ==> Exitting with status FAIL
> Seems like "make dist" is missing a bunch of files...
Crud. Missed them when I did the add and commit. Redoing. Sorry about
that...
Below the jump...
Regards,
Mike
--
Michael H. Warfield (AI4NB) | (770) 978-7061 | mhw at WittsEnd.com
/\/\|=mhw=|\/\/ | (678) 463-0932 | http://www.wittsend.com/mhw/
NIC whois: MHW9 | An optimist believes we live in the best of all
PGP Key: 0x674627FF | possible worlds. A pessimist is sure of it!
--
Added missing files...
Accidentally overlooked two new files when building patch set.
Signed-off-by: Michael H. Warfield <mhw at WittsEnd.com>
---
config/init/systemd/lxc.service.in | 17 +++++
config/init/sysvinit/lxc.in | 124 +++++++++++++++++++++++++++++++++++++
2 files changed, 141 insertions(+)
create mode 100644 config/init/systemd/lxc.service.in
create mode 100644 config/init/sysvinit/lxc.in
diff --git a/config/init/systemd/lxc.service.in b/config/init/systemd/lxc.service.in
new file mode 100644
index 0000000..5f155b6
--- /dev/null
+++ b/config/init/systemd/lxc.service.in
@@ -0,0 +1,17 @@
+[Unit]
+Description=LXC Container Initialization and Autoboot Code
+After=syslog.target network.target
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStartPre=@libexecdir@/lxc/lxc-devsetup
+ExecStart=@libexecdir@/lxc/lxc-autostart-helper start
+ExecStop=@libexecdir@/lxc/lxc-autostart-helper stop
+# Environment=BOOTUP=serial
+# Environment=CONSOLETYPE=serial
+StandardOutput=syslog
+StandardError=syslog
+
+[Install]
+WantedBy=multi-user.target
diff --git a/config/init/sysvinit/lxc.in b/config/init/sysvinit/lxc.in
new file mode 100644
index 0000000..1a876a2
--- /dev/null
+++ b/config/init/sysvinit/lxc.in
@@ -0,0 +1,124 @@
+#!/bin/sh
+#
+# lxc Start/Stop LXC autoboot containers
+#
+# chkconfig: 345 99 01
+# description: Starts/Stops all LXC containers configured for autostart.
+#
+### BEGIN INIT INFO
+# Provides: lxc
+# Default-Start: 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Bring up/down LXC autostart containers
+# Description: Bring up/down LXC autostart containers
+### END INIT INFO
+
+sysconfdir="@SYSCONFDIR@"
+bindir="@BINDIR@"
+localstatedir="@LOCALSTATEDIR@"
+
+# These can be overridden in @SYSCONFDIR@/sysconfig/lxc
+
+# BOOTGROUPS - What groups should start on bootup?
+# Comma separated list of groups.
+# Leading comma, trailing comma or embedded double
+# comma indicates when the NULL group should be run.
+# Example (default): boot the onboot group first then the NULL group
+BOOTGROUPS="onboot,"
+
+# SHUTDOWNDELAY - Wait time for a container to shut down.
+# ner shutdown can result in lengthy system
+# shutdown times. Even 5 seconds per container can be
+# too long.
+SHUTDOWNDELAY=5
+
+# OPTIONS can be used for anything else.
+# If you want to boot everything then
+# options can be "-a" or "-a -A".
+OPTIONS=
+
+# STOPOPTS are stop options. The can be used for anything else to stop.
+# If you want to kill containers fast, use -k
+STOPOPTS="-a -A -s"
+
+# Source function library.
+test ! -r "$sysconfdir"/rc.d/init.d/functions ||
+ . "$sysconfdir"/rc.d/init.d/functions
+
+# Source any configurable options
+test ! -r "$sysconfdir"/sysconfig/lxc ||
+ . "$sysconfdir"/sysconfig/lxc
+
+# Check for needed utility program
+[ -x "$bindir"/lxc-autostart ] || exit 1
+
+# If libvirtd is providing the bridge, it might not be
+# immediately available, so wait a bit for it before starting
+# up the containers or else any that use the bridge will fail
+# to start
+wait_for_bridge()
+{
+ [ -f "$sysconfdir"/lxc/default.conf ] || { return 0; }
+
+ which ifconfig >/dev/null 2>&1
+ if [ $? = 0 ]; then
+ cmd="ifconfig -a"
+ else
+ which ip >/dev/null 2>&1
+ if [ $? = 0 ]; then
+ cmd="ip link list"
+ fi
+ fi
+ [ -n cmd ] || { return 0; }
+
+ BRNAME=`grep '^[ ]*lxc.network.link' "$sysconfdir"/lxc/default.conf | sed 's/^.*=[ ]*//'`
+ if [ -z "$BRNAME" ]; then
+ return 0
+ fi
+
+ for try in `seq 1 30`; do
+ eval $cmd |grep "^$BRNAME" >/dev/null 2>&1
+ if [ $? = 0 ]; then
+ return
+ fi
+ sleep 1
+ done
+}
+
+# See how we were called.
+case "$1" in
+ start)
+ [ ! -f "$localstatedir"/lock/subsys/lxc ] || { exit 0; }
+
+ if [ -n "$BOOTGROUPS" ]
+ then
+ BOOTGROUPS="-g $BOOTGROUPS"
+ fi
+
+ # Start containers
+ wait_for_bridge
+ # Start autoboot containers first then the NULL group "onboot,".
+ action $"Starting LXC autoboot containers: " /usr/bin/lxc-autostart $OPTIONS $BOOTGROUPS
+ touch "$localstatedir"/lock/subsys/lxc
+ ;;
+ stop)
+ if [ -n "$SHUTDOWNDELAY" ]
+ then
+ SHUTDOWNDELAY="-t $SHUTDOWNDELAY"
+ fi
+
+ # The stop is serialized and can take excessive time. We need to avoid
+ # delaying the system shutdown / reboot as much as we can since it's not
+ # parallelized... Even 5 second timout may be too long.
+ action $"Stopping LXC containers: " "$bindir"/lxc-autostart $STOPOPTS $SHUTDOWNDELAY
+ rm -f "$localstatedir"/lock/subsys/lxc
+ ;;
+ restart|reload|force-reload)
+ $0 stop
+ $0 start
+ ;;
+ *)
+ echo $"Usage: $0 {start|stop|restart|reload|force-reload}"
+ exit 2
+esac
+exit $?
--
1.9.0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 482 bytes
Desc: This is a digitally signed message part
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20140520/aef8fe4f/attachment.sig>
More information about the lxc-devel
mailing list