[RFC] Event prefixing policy

James Hunt james.hunt at ubuntu.com
Thu Jan 31 20:25:08 UTC 2013


For Enhanced User Sessions in Upstart, we originally planned for session jobs
being supervised by a Session Init (upstart running as a non-priv user) to react
to *both* system events and session events when the 'start on' stanza is
specified in the usual form:

  start on foo

However, we now feel that this is likely to be a cause of some confusion since
if there were jobs at both the system (pid 1) level *and* the user level that
reacted to that event, the 'foo' event would cause both of them to start. This
may or may not be desirable :) ...

/etc/init/bar.conf:
   start on foo

$HOME/.config/upstart/bar.conf:
   start on foo

$ sudo initctl emit foo   # OUTCOME: *both* bar jobs start.
$ initctl emit foo        # OUTCOME: only user job starts

To avoid confusion, there are 2 approaches we're looking at (if you can think of
others, please speak up):

(1) Require session jobs to specify the ':sys:' prefix to react to system events
(no prefix or ':user:' would therefore match user events).

  start on :sys:foo  # start if 'foo' event emitted at PID 1 level.
  start on foo       # start if 'foo' event emitted at Session Init level.
  start on :user:foo # start if 'foo' event emitted at Session Init level.

(2) Require session jobs to specify the ':user:' prefix to react to user events
(no prefix or ':sys:' would therefore match system events).

  start on :user:foo # start if 'foo' event emitted at Session Init level.
  start on foo       # start if 'foo' event emitted at PID 1 level.
  start on :sys:foo  # start if 'foo' event emitted at PID 1 level.

Option (1) has the virtue of being explicit so there is no doubt about what is
being requested. This probably wins wrt the Principle of Least Astonishment, but
may be unwieldy if users have more jobs reacting to system events that session
events (*).

Option (2) has the virtue that it would allow users to develop a job, test it
via a Session Init and then deploy as a system job with no syntax change. Since
we imagine session jobs may wish to react to udev messages, this would simplify
the jobs and make them compatible with system-level jobs. Compare:

  start on      net-device-added INTERFACE=eth0
  start on :sys:net-device-added INTERFACE=eth0



If a user _really_ wants a job to react to both system- and user-level events,
we could change the meaning of the '::' prefix to mean 'match all prefixes'.
This is probably clearer than making the 'no prefix' mean 'match all prefixes'
since the extra syntactical sugar gives some indication that this isn't a normal
event match.

Thoughts?

Kind regards,

James.

[1] -
https://wiki.ubuntu.com/FoundationsTeam/Specs/RaringUpstartUserSessions#Proposed_Changes_to_Events

(*) - They may of course be mixed:

        start on (foo and (::bar and (:sys:baz or :user:qux)))

--
James Hunt
____________________________________
http://upstart.ubuntu.com/cookbook
http://upstart.ubuntu.com/cookbook/upstart_cookbook.pdf



More information about the upstart-devel mailing list