/srv/irclogs.ubuntu.com/2014/06/28/#upstart.txt

shamiltonspecifically I have two jobs, one is instanced on $INTERFACE, the other is a task which starts on (started network-interface and local-filesystems) and just starts an instance of the first job00:00
shamiltonis this a reasonable approach?00:00
shamiltonmy guess is the second one may need to be instanced as well, so that it can maintain state for each network-interface in the case that local-filesystems has not yet fired00:02
shamiltonsimplified it to a single job, seems to work if the interface comes up before local-filesystems, presumably because then the state exists for that interface, but if the interface comes up after, I guess the instance is created and it never sees the local-filesystems event00:15
xnoxshamilton: hey00:30
xnoxshamilton: local-filesystems event is only emitted once, thus all subsequent tasks (which trigger on network-interface) are "stuck" waiting on local-filesystems to be emitted again, which will never happen.00:30
xnoxshamilton: you can have "start on network-interface" and it will be started on each interface (one at a time, or multiple if you also use instance in the task)00:31
xnoxshamilton: but, on debian/ubuntu systems it's best to use if up & if down scripts anyway. As they are more closely related to network configuration / deconfiguration00:32
shamiltonokay, but my daemon actually does require local-filesystems -- should I just poll for it in my pre-start script?00:32
xnoxshamilton: if it is a daemon, it's not a task.00:32
xnoxshamilton: why not make it "start on runlevel [2345]" ?00:32
shamiltonyeah, previously I had a separate task which was spawning the daemon due to some other mapping logic I require, but I've since removed it to try to get something simple working00:33
shamiltonI need an instance per network interface00:33
shamiltonso forget about everything above, current situation is I have a single job which starts an instance on (started network-interface and local-filesystems)00:34
shamiltonbut it doesn't start if the network interface comes up after local-filesystems00:35
xnoxshamilton: you will ever have one of those. Since "local-filesystem" is one time event (which fires only once) then it waits for e.g. one network interface to fire, after which local-filesystem event is retired.00:35
xnoxshamilton: and during a lifecycle of a single boot local-filesystem is never repeaded.00:36
shamiltonmy understanding is that each job remembers that local-filesystems has already fired, so I'm thinking if I could "touch" the jobs for the interfaces which I know will come up in the future, I could get it working, though it's a bit hacky00:36
xnoxshamilton: no, nothing remembers anything. That would state preservations, there is no state.00:37
xnoxshamilton: write a simple job which does this:00:37
xnoxstart on A and B00:37
xnoxstop on C00:38
xnox$ initctl emit A00:38
xnox$ initctl emit B00:38
xnox$ status test job00:38
xnoxstart/running00:38
xnox$ initctl emit C00:38
xnox$ status test-job00:38
xnoxstop/waiting00:38
xnox$ initctl emit B00:38
xnox$ status test-job00:38
xnoxstop/waiting00:38
xnox..... waiting for event A to be emitted again.00:39
shamiltondoes it not remember that A has fired, so that it can start for real when you emit B?00:39
xnoxso you can have "instance INTERFACE \ task \ start on network-interface"00:39
xnoxshamilton: no, it does not remember, because upstart is event driven, not state driven.00:39
xnoxshamilton: it's widely documented and explained in multiple times in the cookbook.00:40
shamiltonhttp://upstart.ubuntu.com/wiki/JobEventExpressions "When an event occurs, each node in the tree is checked, and the value changed if the event matches. Each parent node is then updated to the new value."00:40
shamiltonmy interpretation of this is that it maintains state00:40
xnoxshamilton: please see cookbook. http://upstart.ubuntu.com/cookbook/#restarting-jobs-with-complex-conditions00:40
xnoxshamilton: there are other sections as well about it.00:40
xnoxshamilton: and just read through http://upstart.ubuntu.com/cookbook/#restarting-jobs-with-complex-conditions it has examples of all common cases, including mutually exclusive tasks and those that need 1 to 1 mapping00:41
shamiltonso in your example above, you remove "initctl emit A", "initctl emit B" would no longer start the job, correct?00:42
shamiltonI don't see how it could be stateless if so00:42
xnoxit's implemented as follows00:43
xnoxevent fires, iterate across known waiting/blocked jobs and check the events it keys on.00:43
xnoxif any match, mark it as satisfied, free the event.00:43
xnoxif last condition is satisfied start the job.00:43
xnoxso for example:00:43
xnox$ initctl emit A00:44
xnox$ initctl emit B00:44
xnox$ initctl emit A00:44
xnox$ stop test-job00:44
xnox$ initctl emit B00:44
xnoxwill _not_ start the job. (as event A arrived whilst the job was running thus no conditions are tracked)00:44
shamiltonokay, got it, that's roughly how I understood it00:45
xnoxit's all to avoid deadlocks, circular dependencies and keep the core very simple 1-time event propagation.00:45
xnoxthere is no multi-pass.00:46
xnoxshamilton: but yeah, in your case you should "instance $INTERFACE \n start on network-interface" and in the pre-start block until all other things are satisfied (e.g. mountpoints mounted et.al.)00:47
shamiltonsuppose hypothetically I could touch all the instances I expect in advance at "startup", would it not then remember that local-filesystems has fired, and behave desirably?00:48
shamiltonignoring the restart thing, which isn't a problem00:48
shamiltonI guess at that point there isn't much reason to use instances00:50
xnoxshamilton: hm, no, and typically one uses instances only when you do not know ahead of time how many instances you will have.00:56
xnoxshamilton: e.g. for hot-plug type of things. If you do know all the interfaces you expect to have, then I'd store it in a config file somewhere and then have 1 arbitrator job which is "start on local-filesystems" and instance job without any start on conditions at all.00:57
xnoxthen arbitrator would do: script \n for i in $DESIRED_INSTANCES; do start --no-wait worker INTERFACE=$i; done \n end script00:58
xnoxshamilton: what is the actual thing you are running? and why does it have to be started on per network interface?00:58
xnoxshamilton: can it not just start one daemon that e.g. connects to network-manager over dbus to monitor networking events and act appropriately on them?00:59
shamiltonit's basically tcpdump, which I want running as early as possible, but I do need a separate instance per interface00:59
xnoxshamilton: right, true. why do you need local-filesystem them?00:59
xnoxshamilton: with recent enough upstart stdout & stderr is collected and stored into /var/log/upstart/job-instance.log01:00
xnoxshamilton: and that is done irrespective of filesystems (e.g. it's cached and flushed to disk, once disk becomes writable)01:00
xnoxshamilton: check $ man 5 init to see if you have "console log" (the default) available to you. 01:01
xnoxshamilton: .... and networks can be established in the initramfs /before/ upstart is run.01:01
shamiltonroot filesystem is RO, the RW disk doesn't come up until a bit later, the packet inspector needs RW to the filesystem01:02
shamiltonalso this is just my piece of the puzzle, unfortunately I'm not at liberty to make sweeping systemic changes01:03
shamiltonsome kind of process controller would be ideal, but in the interest of getting things working quickly, I'm trying to do it with usptart01:03
shamiltonand just polling for the filesystem in a pre-start should do the trick, though it feels suboptimal01:03
shamiltonhowever, I can leave a comment saying it was vetted by an upstart dev01:03
xnoxshamilton: what upstart version you are using?01:04
shamilton# /sbin/init --version01:04
shamiltoninit (upstart 1.5)01:04
shamiltonunfortunately01:04
shamiltonmight be able to drop in a newer one if it wouldn't break anything01:04
xnoxshamilton: and i'm not sure why packet inspector needs RW, if you can redirect output to just plain stdout upstart will collect it for you, from early boot even whilst filesystem is RO.01:04
xnoxshamilton: and i'm not sure what you mean "vetted by an upstart dev". I didn't veto anything =)01:05
shamiltoninspection engine has a local database, so unfortunately it's not as simple as stdio buffering01:06
shamiltonagain not my call01:06
shamiltonokay, "discussed with someone who sounded like they knew what they were doing"01:07
xnoxshamilton: well, you can get away without a pre-start01:07
shamiltonoh?01:08
xnoxshamilton: so have your thing start on network-interface - aka worker. And have another job which is called "check-conditions" which is also an instance "start on starting working" which would block until file systems are writable et.al. Not really that different, but you'd be able to optimise those checks to short-circuit them after it succeded the first time.01:09
xnoxwith "start on starting foo" you can pre-empt and block foo from starting until this other job completes.01:09
xnoxshamilton: again this is also described in the cookbook. Do please read the cookbook's common examples, to see if there is inspiration to organise your jobs.01:10
xnoxhttp://upstart.ubuntu.com/cookbook/01:10
xnox11 COokbook and Best Practises01:11
shamiltonso I have a task which is start on starting tpcdump, it blocks until the filesystem is available, correct? not quite sure what you mean by short circuit the tests01:17
xnoxshamilton: yeah. Short cirtuit - e.g. cache the result, at the end touch /var/run/life-is-good, and that filesystem check can start with: if  [ ! -e /var/run/life-is-good ]; then block until filesystem is mounted; fi exit 001:22
shamiltonk, that's what I thought you meant, but the filesystem test is also a -e, so in this case I don't win much01:23
shamiltonthink the pre-start script is the simplest approach01:23
shamiltonguessing there's no chance for future statefulness01:24
xnoxshamilton: we did plan to introduce state tracking. E.g. "while mounted MOUNTPOINT='/' and running webserverd" stanza and then monitor and start/stop when state is correct/incorrect.01:25
xnoxshamilton: but that was very vague plans. Currently in the pipeline are cgroups support & non-blocking process spawning (speed up)01:25
xnoxshamilton: nobody is working to design nor implement statefulness at the moment.01:26
shamiltonthanks for your help. I'm not completely satisfied with the end result, as I was really hoping it could be completely event driven (sans polling,) but at least I can put it to bed01:29

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!