[RFC] allow specifying startup event
Serge E. Hallyn
serge.hallyn at canonical.com
Fri Jan 14 04:24:50 UTC 2011
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 ();
More information about the upstart-devel
mailing list