[RFC] allow specifying startup event

Serge E. Hallyn serge.hallyn at canonical.com
Fri Jan 14 17:48:11 UTC 2011

Quoting Scott James Remnant (scott at netsplit.com):
> NAK.

Thanks for taking a look, Scott.  Your ideas do sound better, though
they're not working for me just yet.

> There should be no need to alter the existing code to do what you
> want, and changing things like the startup event means that any job
> specifying:
>     start on startup and...
> would now no longer work!

The lxc.conf which starts on lxc emits startup after doing some
pre-config, so these should keep working.  (And my laptop with
these patches has been booting fine)

Though I'm definately open to a cleaner idea like:

> An existing feature is to use the command-line arguments in a
> different way.  Firstly any kernel command-line argument of the form
> foo=bar is passed to init in its environment.  You can get the values
> of those in jobs with just a bare "env foo".
> So if you boot:
>     container=lxc
> A job can check that with:
>     env container
>     pre-start script
>         [ $container = "lxc" ] && exit 0
>     end script
> (This works today)

It doesn't seem to be working for me though.  A natty container
which is passed 'container=lxc' and does

	console output
	env container
	pre-start script
	echo "container is .$container."
		[ "$container" != "lxc" ] && stop
	end script

prints out:

	container is ..

when upstart was started as:

	10991 execve("/sbin/init", ["/sbin/init", "container=lxc", "builtinfstab=/lib/init/fstab.lxc"], [/* 27 vars */] <unfinished ...>

The whole .conf file is attached in case there is something I'm doing
obviously wrong.

> The longer term plan is regarding bare word arguments (such as
> "quiet", etc.)  These are passed to init as command-line arguments, if
> these specify the name of a known job, that job is taken out of manual
> mode and will be started as normal.  If the argument begins "!" or
> "no" the the job is placed *in* manual mode.  (you could boot with
> nomountall for example)
> If these do not specify a known job, then an artificial "always
> running" job is created (or suppressed).  You can use the states
> system to include jobs or exclude them:
>     while lxc
>     while not splash
> etc.
> This would mean that multiple boot paths could be simultaneously
> supported by a single set of configuration.

That would/will be awesome.

> (separately, in terms of the mountall patch - this is unique to ubuntu
> so not relevant to this ML - however it's worth pointing out that
> "mount" itself somehow needs to know the fstab that mountall used,
> otherwise "mount -a" would try and mount the filesystems listed in
> /lib/init/fstab

I was hoping that was only consulted at boot.  So I've removed that
argument, and have mountall.conf (attached) bind-mounting the alternate

>  which filesystems from that are not actually mounting - maybe they
> shouldn't be in that file?)

-------------- next part --------------
# lxc pre-startup

description "LXC pre-startup"

start on startup
console output

env container
pre-start script
	echo "container is .$container."
	[ "$container" != "lxc" ] && stop
end script

	# A container won't get a net-device-added lo from
	# upstart-udev-bridge, but as of bzr revision 48, only
	# the network-interface.conf will emit net-device-up,
	# not the /etc/network/if-up.d/upstart - so 'ifup -a'
	# in networking.conf doesn't emit the signal

	# Without net-device-added lo, rc-sysinit will never
	# run.  And without that, things like console won't.

	# So we do it here.
	/bin/echo "lxc: setting up lo"
	ifconfig lo up || true
	initctl emit -n net-device-up \
	    IFACE=lo LOGICAL=lo ADDRFAM=inet METHOD=loopback || true
end script
-------------- next part --------------
# mountall - Mount filesystems on boot
# This helper mounts filesystems in the correct order as the devices
# and mountpoints become available.

description	"Mount filesystems on boot"

start on startup
stop on starting rcS

expect daemon

emits virtual-filesystems
emits local-filesystems
emits remote-filesystems
emits all-swaps
emits filesystem
emits mounting
emits mounted

# temporary, until we have progress indication
# and output capture (next week :p)
console output

env builtinfstab
pre-start script
    # It seems more sensible to do this in lxcguest.conf itself, but
    # then we would race with it and perhaps call mountall before lxcguest
    # got around to doing the bind mount
    # lxc will pass 'builtinfstab=/lib/init/fstab.lxc', for intance.
    echo "builtinfstab is .$builtinfstab."
    [ ! -z $builtinfstab ] && mount --bind $builtinfstab /lib/init/fstab

end script

    . /etc/default/rcS
    [ -f /forcefsck ] && force_fsck="--force-fsck"
    [ "$FSCKFIX" = "yes" ] && fsck_fix="--fsck-fix"

    # set $LANG so that messages appearing in plymouth are translated
    if [ -r /etc/default/locale ]; then
        . /etc/default/locale

    exec mountall --daemon $force_fsck $fsck_fix
end script

post-stop script
    rm -f /forcefsck 2>dev/null || true
end script

More information about the upstart-devel mailing list