[RFC] allow specifying startup event
Scott James Remnant
scott at netsplit.com
Fri Jan 14 07:31:35 UTC 2011
NAK.
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!
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)
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.
(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
which filesystems from that are not actually mounting - maybe they
shouldn't be in that file?)
Scott
On Fri, Jan 14, 2011 at 4:24 AM, Serge E. Hallyn
<serge.hallyn at canonical.com> wrote:
> My goal is to let a natty image, without modification,
> boot both on bare metal (or in kvm), and in an lxc
> container. Certain things don't happen in a container,
> for instance a net-device-added INTERFACE=lo will never
> arrive because lo was created before the container was
> brought up.
>
> So the following patches add a '--startup-event=X' option
> to upstart. If specified, then instead of 'startup',
> upstart will send the specified event name. A corresponding
> patch to lxc adds '--startup-event=lxc' to init's arguments,
> and creates an lxc.conf which sends the lo up event as well
> as the startup event.
>
> The second obstacle to booting a stock natty image in a
> container is that mountall can't boot some of the entries
> in it's stock /lib/init/fstab. So mountall gets a
> '--with-bultin-fstab' option. If mountall.conf sees a
> BUILTIN_FSTAB variable, then it uses that argument. THe
> lxcguest's lxc.conf passes /etc/init/fstab.lxc when emitting
> the startup event.
>
> Does this seem at all acceptable?
>
> Below are the debdiffs for upstart and mountall. A patch
> is needed to lxc, and an lxc guest needs to install the
> 'lxcguest' package to get the lxc upstart jobs. After it
> does, it is safe to boot either as a container, a (kvm,
> vmware, etc) VM, or on bare metal.
>
> Feedback is greatly appreciated.
>
> thanks,
> -serge
>
> Upstart debdiff:
>
> === modified file 'debian/changelog'
> --- debian/changelog 2011-01-04 21:14:44 +0000
> +++ debian/changelog 2011-01-13 18:31:12 +0000
> @@ -1,3 +1,12 @@
> +upstart (0.6.7-3ubuntu2) natty; urgency=low
> +
> + * add '--startup-event' option. If given, then instead of 'startup',
> + an event named as the given argument will be emitted. It is expected
> + that a upstart job will start on that event and eventually emit
> + startup, perhaps with some variables set.
> +
> + -- Serge Hallyn <serge.hallyn at ubuntu.com> Wed, 12 Jan 2011 14:50:22 -0600
> +
> upstart (0.6.7-3) natty; urgency=low
>
> * debian/rules: make sure apparmor-profile-load is executable.
>
> === modified file 'init/main.c'
> --- init/main.c 2011-01-04 21:14:44 +0000
> +++ init/main.c 2011-01-14 04:01:59 +0000
> @@ -87,6 +87,13 @@
> **/
> static int restart = FALSE;
>
> +/**
> + * startup_event:
> + *
> + * If not NULL, then this holds the string to use as the event
> + * signaling startup. If NULL, then STARTUP_EVENT is used.
> + **/
> +static char *startup_event = NULL;
>
> /**
> * options:
> @@ -95,6 +102,7 @@
> **/
> static NihOption options[] = {
> { 0, "restart", NULL, NULL, NULL, &restart, NULL },
> + { 0, "startup-event", NULL, NULL, "startup-event", &startup_event, NULL },
>
> /* Ignore invalid options */
> { '-', "--", NULL, NULL, NULL, NULL, NULL },
> @@ -323,7 +331,12 @@
> if (! restart) {
> DIR *piddir;
>
> - NIH_MUST (event_new (NULL, STARTUP_EVENT, NULL));
> + if (startup_event) {
> + nih_warn("%s: Using startup event %s\n", __func__, startup_event);
> + NIH_MUST (event_new (NULL, startup_event, NULL));
> + } else {
> + NIH_MUST (event_new (NULL, STARTUP_EVENT, NULL));
> + }
>
> /* Total hack, look for .pid files in /dev/.initramfs -
> * if there's a job config for them pretend that we
>
>
> Mountall debdiff:
>
> === modified file 'conf/mountall.conf'
> --- conf/mountall.conf 2010-08-26 06:49:15 +0000
> +++ conf/mountall.conf 2011-01-14 03:57:19 +0000
> @@ -34,7 +34,8 @@
> export LANG LANGUAGE LC_MESSAGES LC_ALL
> fi
>
> - exec mountall --daemon $force_fsck $fsck_fix
> + [ "x$BUILTIN_FSTAB" != "x" ] && builtin_fstab="--with-builtin-fstab $BUILTIN_FSTAB"
> + exec mountall $builtin_fstab --daemon $force_fsck $fsck_fix
> end script
>
> post-stop script
>
> === modified file 'debian/changelog'
> --- debian/changelog 2010-12-16 00:17:36 +0000
> +++ debian/changelog 2011-01-14 03:56:59 +0000
> @@ -1,3 +1,11 @@
> +mountall (2.20+nmu1ubuntu1) natty; urgency=low
> +
> + * Add --with-builtin-fstab option to specify alternate location to
> + use in place of /lib/init/fstab. The first intended use case
> + is for lxc containers.
> +
> + -- Serge Hallyn <serge.hallyn at ubuntu.com> Wed, 12 Jan 2011 19:23:56 -0600
> +
> mountall (2.20+nmu1) natty; urgency=low
>
> * Non-maintainer upload.
>
> === modified file 'src/mountall.c'
> --- src/mountall.c 2010-12-15 17:37:13 +0000
> +++ src/mountall.c 2011-01-14 03:57:46 +0000
> @@ -385,6 +385,14 @@
> **/
> static int no_events = FALSE;
>
> +/**
> + * builtin_fstab:
> + *
> + * The name of the file to use as built-in fstab.
> + * If NULL, then BUILTIN_FSTAB (/lib/init/fstab) will be used.
> + **/
> +static char *builtin_fstab = NULL;
> +
>
> static void
> dequote (char *str)
> @@ -3212,6 +3220,8 @@
> NULL, NULL, &fsck_fix, NULL },
> { 0, "no-events", N_("Do not emit events after mounting filesystems"),
> NULL, NULL, &no_events, NULL },
> + { 0, "with-builtin-fstab", N_("Use argument specified file in place of /lib/init/fstab"),
> + NULL, "with-builtin-fstab", &builtin_fstab, NULL },
>
> NIH_OPTION_LAST
> };
> @@ -3306,7 +3316,11 @@
> * from /etc/fstab and /proc/self/mountinfo to find out what else
> * we need to do.
> */
> - parse_fstab (BUILTIN_FSTAB);
> + if (builtin_fstab) {
> + nih_warn("%s: builtin_fstab is %s\n", __func__, builtin_fstab);
> + parse_fstab (builtin_fstab);
> + } else
> + parse_fstab (BUILTIN_FSTAB);
> parse_fstab (_PATH_MNTTAB);
> parse_mountinfo ();
>
>
>
> --
> upstart-devel mailing list
> upstart-devel at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/upstart-devel
>
More information about the upstart-devel
mailing list