On Wed, 2008-06-18 at 15:21 -0700, Garrett Cooper wrote: > Would the definition of "simple case" be a straight up SIGCHLD? > If the process dies, Upstart will receive SIGCHLD, and if marked "respawn" it will be restarted.
Detecting things like a stoned process is more interesting.
You'd want to do something like this on a regular interval:
[via D-Bus] obtain job object from Upstart controller
(if none, assume job has gone away and exit)
[via D-Bus] obtain running instance object
(if none, assume job is disabled and exit)
[via D-Bus] obtain process id of main job
(if you need it for your poking)
(if none, assume Upstart is respawning job and sleep)
do whatever you need to do to the process to determine whether it is
alive or stoned
if stoned, you can simply KILL the process knowing that Upstart will
respawn it, or
[via D-Bus] execute the Restart() method on the instance
This is actually where D-Bus really benefits. Upstart's model is much
more complex and flexible than sysvinit's, so you need to be able to be
quite expressive across IPC.
There's already native D-Bus bindings in just about every language you
can care to think of, so that's a huge amount of coding you don't need
to do.
For example, that might look in Python:
import dbus
bus = dbus.SystemBus()
upstart = bus.get_object("com.ubuntu.Upstart",
"/com/ubuntu/Upstart")
try:
job = upstart.GetJobByName("my_job")
instance = upstart.GetInstanceByName("")
except:
# No such job, or not running
return
# Note this bit may change
try:
pid = instance.Get("pid")["main"]
except KeyError:
# Being started, stopped or restarted
return
# Muck around with pid as you see fit
if os.path.isfile("/tmp/%d" % pid):
return
# Oh dear, it's broken
instance.Restart()
Scott
--
Have you ever, ever felt like this?
Had strange things happen? Are you going round the twist?
signature.asc
Description: This is a digitally signed message part
-- upstart-devel mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/upstart-devel
