Commit 38402e4d by Michael H. Warfield Committed by Stéphane Graber

Backport of autoboot/autostart rollup to stable-1.0

Full backport of the autostart / autoboot rollup patch from master to stable-1.0. lxc-autostart: rework boot and group handling This adds new functionality to lxc-autostart. *) The -g / --groups option is multiple cummulative entry. This may be mixed freely with the previous comma separated group list convention. Groups are processed in the order they first appear in the aggregated group list. *) The NULL group may be specified in the group list using either a leading comma, a trailing comma, or an embedded comma. *) Booting proceeds in order of the groups specified on the command line then ordered by lxc.start.order and name collalating sequence. *) Default host bootup is now specified as "-g onboot," meaning that first the "onboot" group is booted and then any remaining enabled containers in the NULL group are booted. *) Adds documentation to lxc-autostart for -g processing order and combinations. *) Parameterizes bootgroups, options, and shutdown delay in init scripts and services. *) Update the various init scripts to use lxc-autostart in a similar way. Reported-by: 's avatarCDR <venefax@gmail.com> Signed-off-by: 's avatarDwight Engen <dwight.engen@oracle.com> Signed-off-by: 's avatarMichael H. Warfield <mhw@WittsEnd.com> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent 3fd1eb05
......@@ -111,6 +111,9 @@ config/missing
config/libtool.m4
config/lt*.m4
config/bash/lxc
config/init/systemd/lxc-autostart-helper
config/init/systemd/lxc.service
config/init/sysvinit/lxc
doc/*.1
doc/*.5
......
......@@ -5,7 +5,17 @@ EXTRA_DIST = \
if INIT_SCRIPT_SYSTEMD
SYSTEMD_UNIT_DIR = $(prefix)/lib/systemd/system
install-systemd: lxc.service lxc-devsetup
lxc-autostart-helper: ../sysvinit/lxc.in $(top_builddir)/config.status
$(AM_V_GEN)sed \
-e 's|[@]SYSCONFDIR[@]|$(sysconfdir)|g' \
-e 's|[@]LOCALSTATEDIR[@]|$(localstatedir)|g' \
-e 's|[@]BINDIR[@]|$(bindir)|g' \
< $< > $@-t && \
chmod a+x $@-t && \
mv $@-t $@
BUILT_SOURCES = lxc-autostart-helper
install-systemd: lxc.service lxc-devsetup lxc-autostart-helper
$(MKDIR_P) $(DESTDIR)$(SYSTEMD_UNIT_DIR)
$(INSTALL_DATA) lxc.service $(DESTDIR)$(SYSTEMD_UNIT_DIR)/
......@@ -13,7 +23,7 @@ uninstall-systemd:
rm -f $(DESTDIR)$(SYSTEMD_UNIT_DIR)/lxc.service
rmdir $(DESTDIR)$(SYSTEMD_UNIT_DIR) || :
pkglibexec_SCRIPTS = lxc-devsetup
pkglibexec_SCRIPTS = lxc-devsetup lxc-autostart-helper
install-data-local: install-systemd
uninstall-local: uninstall-systemd
......
[Unit]
Description=LXC Container Initialization and Autoboot Code
After=syslog.target
After=syslog.target network.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/usr/libexec/lxc/lxc-devsetup
ExecStart=/usr/libexec/lxc/lxc-startup start
ExecStop=/usr/libexec/lxc/lxc-startup stop
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
......
......@@ -13,11 +13,44 @@
# 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 -s"
# Source function library.
. /etc/init.d/functions
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 /usr/bin/lxc-autostart ] || exit 1
[ -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
......@@ -25,15 +58,26 @@
# to start
wait_for_bridge()
{
[ -f /etc/lxc/default.conf ] || { return 0; }
[ -f "$sysconfdir"/lxc/default.conf ] || { return 0; }
BRNAME=`grep '^[ ]*lxc.network.link' /etc/lxc/default.conf | sed 's/^.*=[ ]*//'`
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
ifconfig -a |grep "^$BRNAME" >/dev/null 2>&1
eval $cmd |grep "^$BRNAME" >/dev/null 2>&1
if [ $? = 0 ]; then
return
fi
......@@ -44,16 +88,30 @@ wait_for_bridge()
# See how we were called.
case "$1" in
start)
[ ! -f /var/lock/subsys/lxc ] || { exit 0; }
[ ! -f "$localstatedir"/lock/subsys/lxc ] || { exit 0; }
if [ -n "$BOOTGROUPS" ]
then
BOOTGROUPS="-g $BOOTGROUPS"
fi
# Start containers
wait_for_bridge
action $"Starting LXC containers: " /usr/bin/lxc-autostart
touch /var/lock/subsys/lxc
# 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)
action $"Stopping LXC containers: " /usr/bin/lxc-autostart -s
rm -f /var/lock/subsys/lxc
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
......
......@@ -6,6 +6,30 @@ stop on starting rc RUNLEVEL=[016]
env LXC_AUTO="false"
# These can be overridden in /etc/default/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
env BOOTGROUPS="onboot,"
# SHUTDOWNDELAY - Wait time for a container to shut down.
# Container shutdown can result in lengthy system
# shutdown times. Even 5 seconds per container can be
# too long.
env SHUTDOWNDELAY=5
# OPTIONS can be used for anything else.
# If you want to boot everything then
# options can be "-a" or "-a -A".
env OPTIONS=
# STOPOPTS are stop options. The can be used for anything else to stop.
# If you want to kill containers fast, use -k
env STOPOPTS="-a -A -s"
pre-start script
[ -f /etc/default/lxc ] && . /etc/default/lxc
......@@ -20,7 +44,13 @@ pre-start script
[ "x$LXC_AUTO" = "xtrue" ] || exit 0
lxc-autostart -L | while read line; do
if [ -n "$BOOTGROUPS" ]
then
BOOTGROUPS="-g $BOOTGROUPS"
fi
# Process the "onboot" group first then the NULL group.
lxc-autostart -L $OPTIONS $BOOTGROUPS | while read line; do
set -- $line
(start lxc-instance NAME=$1 && sleep $2) || true
done
......
......@@ -575,7 +575,9 @@ AC_CONFIG_FILES([
config/bash/lxc
config/init/Makefile
config/init/sysvinit/Makefile
config/init/sysvinit/lxc
config/init/systemd/Makefile
config/init/systemd/lxc.service
config/init/upstart/Makefile
config/etc/Makefile
config/templates/Makefile
......
......@@ -153,8 +153,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
</term>
<listitem>
<para>
Comma separate list of groups to select
(defaults to those without a lxc.group).
Comma separated list of groups to select
(defaults to those without a lxc.group - the NULL group).
This option may be specified multiple times
and the arguments concatenated. The NULL or
empty group may be specified as a leading comma,
trailing comma, embedded double comma, or empty
argument where the NULL group should be processed.
Groups are processed in the order specified on the
command line. Multiple invocations of the -g option
may be freely intermixed with the comma separated
lists and will be combined in specified order.
</para>
</listitem>
</varlistentry>
......@@ -172,6 +181,69 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
</variablelist>
</refsect1>
<refsect1>
<title>Autostart and System Boot</title>
<para>
The <command>lxc-autostart</command> command is used as part of the
LXC system service, when enabled to run on host system at bootup and at
shutdown. It's used to select which containers to start in what order
and how much to delay between each startup when the host system boots.
</para>
<para>
Each container can be part of any number of groups or no group at all.
Two groups are special. One is the NULL group, i.e. the container does
not belong to any group. The other group is the "onboot" group.
</para>
<para>
When the system boots with the LXC service enabled, it will first
attempt to boot any containers with lxc.start.auto == 1 that is a member
of the "onboot" group. The startup will be in order of lxc.start.order.
If an lxc.start.delay has been specified, that delay will be honored
before attempting to start the next container to give the current
container time to begin initialization and reduce overloading the host
system. After starting the members of the "onboot" group, the LXC system
will proceed to boot containers with lxc.start.auto == 1 which are not
members of any group (the NULL group) and proceed as with the onboot
group.
</para>
</refsect1>
<refsect1>
<title>Startup Group Examples</title>
<variablelist>
<varlistentry>
<term>
<option>-g "onboot,"</option>
</term>
<listitem>
<para>
Start the "onboot" group first then the NULL group.
</para>
<para>
This is the equivalent of: <option>-g onboot -g ""</option>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-g "dns,web,,onboot"</option>
</term>
<listitem>
<para>
Starts the "dns" group first, the "web" group second, then
the NULL group followed by the "onboot" group.
</para>
<para>
This is the equivalent of: <option>-g dns,web -g ,onboot</option> or <option>-g dns -g web -g "" -g onboot</option>.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
&seealso;
<refsect1>
......
......@@ -1472,6 +1472,29 @@ mknod errno 0
</varlistentry>
</variablelist>
</refsect2>
<refsect2>
<title>Autostart and System Boot</title>
<para>
Each container can be part of any number of groups or no group at all.
Two groups are special. One is the NULL group, i.e. the container does
not belong to any group. The other group is the "onboot" group.
</para>
<para>
When the system boots with the LXC service enabled, it will first
attempt to boot any containers with lxc.start.auto == 1 that is a member
of the "onboot" group. The startup will be in order of lxc.start.order.
If an lxc.start.delay has been specified, that delay will be honored
before attempting to start the next container to give the current
container time to begin initialization and reduce overloading the host
system. After starting the members of the "onboot" group, the LXC system
will proceed to boot containers with lxc.start.auto == 1 which are not
members of any group (the NULL group) and proceed as with the onboot
group.
</para>
</refsect2>
</refsect1>
<refsect1>
......
......@@ -154,6 +154,7 @@ rm -rf %{buildroot}
%attr(4111,root,root) %{_libexecdir}/%{name}/lxc-user-nic
%if %{with_systemd}
%attr(555,root,root) %{_libexecdir}/%{name}/lxc-devsetup
%attr(555,root,root) %{_libexecdir}/%{name}/lxc-autostart-helper
%endif
%if %{with_python}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment