[00:31] If I have an Upstart job start on event1 or (event2 and event3), I assumed it would run once upon event1, and again upon event2 and event3 [00:31] That doesn't seem to be the case [00:31] Can anyone explain why? [00:32] It only seems to run once [00:32] But if I have a job start on event1, and another job start on (event2 and event3), both jobs run [00:37] Redoubt: well, a job only starts once, unless you define it as a task or use upstart's instances [00:37] Oh my apologies-- it is a task [00:38] hmm, odd, my understanding of tasks was that they'd re-trigger every time one of the conditions would match... /me tests [00:39] That's what I thought too. I can give you my specific task if you like [00:40] http://paste.ubuntu.com/1393270/ [00:41] that simple example seems to show that upstart behaves as you'd expect... [00:44] Well this is fortunate. I'm working on that bluetooth upstart job (bug 1073669) which you're involved in [00:46] can you pastebin what you've got currently? [00:53] Well, here are my test scripts: http://paste.ubuntu.com/1393294/ [00:54] Because when I test them like you did (via initctl), they do seem to work as expected [00:54] But when I reboot, I only get one print from kyle-all.conf, and the event that triggers it is only local-filesystems [00:55] All the others print as well, but kyle-all.conf only prints once instead of the three times I expected [00:58] hmm, so the problem seems to be that it's expecting the local-filesystems to be re-emited too which it won't [00:58] testing some alternatives here [00:59] Oh interesting, so I have a fundamental misunderstanding, I guess. I sort of thought of events as... states, I guess [00:59] Something that was persistent [00:59] That doesn't actually make sense though, so... :) [01:00] upstart basically tracks event state per job to know when the start condition matches, but as soon as it matches it looses that state, or so it looks like anyway :) [01:01] That makes perfect sense [01:01] But interferes with all my plans, darnit [01:02] Hmm... it would be nice if it analyzed start conditions a little more and was smarter with that [01:03] The only way around this that I can think of is three separate scripts. Yuck [01:04] I would probably do four and make one an instance [01:06] well, you could keep rfkill-restore as it's and add a new rfkill-restore-interface which would roughly be [01:06] start on net-device-added or bluetooth-device-added [01:06] task [01:06] exec initctl start --no-wait rfkill-restore [01:08] the INTERFACE environment variable should then be sent all the way to the rfkill-restore job that can then change behaviour slightly when it's defined [01:09] Well, what about local-filesystems? [01:10] that'd still be the start condition of the rfkill-restore.conf job, just not of the -interface one [01:11] Would exec initctl start --no-wait rfkill-restore fail if local-filesystems hadn't happened? [01:12] hmm, no, it'd run the code anyway but would exit 0 immediately because of the first if statement in rfkill-restore.conf [01:13] If not, this two-script combo is the same as just changing rfkill-restore starts to local-filesystems or net-device-added or bluetooth-device-added, right? [01:13] so that wouldn't be a problem as such a case would mean that the main rfkill-restore call didn't happen yet and that the interface will be rfkilled a bit later [01:13] hmm, good point, and I guess doing that change + adding the needed tweaks to the shell script would do the trick [01:14] no need for a separate job [01:14] Okay, I like that. I really appreciate your help man, I've made a couple forum posts about this and no one seems to have any clue [01:15] That saving states until start condition met thing... I'm not sure the docs explicitly mention that. Not sure I ever would have learned it :) [01:15] hehe, np and thanks for the work on that bug. I've been quite busy with other things lately, one of which being upstart development, so it's good to have you help with this one :) [01:16] Oh my pleasure! [01:17] yeah, the state saving is a bit odd, it makes sense when you think of it, but it can surprise you :) I believe Scott (original upstart author) covered that in some blogpost a few years ago, or maybe it was a session at UDS, can't recall... anyway, may be something we should better cover in the cookbook. [01:19] Redoubt: if you want to poke something when network connections change, just use /etc/network/if-up.d [01:20] Redoubt: upstart is a bit low level for what you're intending [01:21] Redoubt: also if you do need to do state tracking, you can use the 'wait-for-state' job added in Ubuntu 11.04 [01:21] stgraber: Yeah, if you think of it, it would be handy to mention that in there somewhere. [01:22] SpamapS: Huh, wait-for-state is a new one for me, thank you for the reference! [01:23] SpamapS: wait-for-state only works for jobs though, not for events right? (it waits for a job to get into the WAIT_FOR state) [01:24] stgraber: indeed.. the idea though, is that you use the job to track state.. and then you just call wait-for-state with that job when you want to block on a state [01:24] SpamapS: Redoubt is helping me with a limitation of my rfkill-restore job I introduced in 12.10 where some devices you can rfkill show up after the rfkill-restore job is done. The only way to reliably cover this case is to trigger the restore job when network or bluetooth devices show up. [01:25] SpamapS: initially I thought I added the local-filesystems requirement of rfkill-restore because I actually needed local-filesystems, but I don't really as the job itself is checking for the paths it needs and exiting if they're not there. [01:26] SpamapS: so the simple fix for our problem is to change from "start on local-filesystems" to "start on local-filesystems or net-device-added or bluetooth-device-added" which will guarantee the job to be triggered once per boot + once per device [01:26] SpamapS: with some of the per-device call potentially being no-ops if the filesystem isn't there yet, but in such case, the rfkill-restore job will be called a bit later anyway and will take care of any leftovers [01:26] stgraber: Right, so it sounds like you just need a single task, with start on net-device-added or bluetooth-device-added , and an instance value that will be unique enough to run them at the right time [01:26] stgraber: that won't actually guarantee that it will be run once per device [01:27] SpamapS: as it's a task, we don't even need to use instances [01:27] stgraber: thats not true at all [01:28] stgraber: the only thing task does is guarantee that it will block until it reaches stopped again [01:28] stgraber: it does not serialize events. If the state is already 'start/running' .. the next event in the or is ignored [01:28] SpamapS: So you think instances are a better way to go? [01:29] SpamapS: it won't be start/running because the task exits in a few miliseconds [01:29] I think instances is the only way to go if you need to run it once per event [01:29] stgraber: >< cross your fingers? ;) [01:31] thats actually again where wait-for-state works, because you can wait for stopped on a task, but start it. That way all of the waiters will block until it has been run once [01:31] SpamapS: well, the way the script is designed, we don't need the value of INTERFACE, whenever it triggers, it'll restore the rfkill value of any interface it hasn't restored yet. So if we have multiple devices showing up at the same time and we end up only triggering the job once, that's fine as it'll cover all of them anyway [01:32] start wait-for-state WAITER=$UPSTART_JOB WAIT_STATE=stopped GOAL_STATE=start WAIT_FOR=rfkill-restore [01:32] assuming rfkill-restore is a task [01:33] it's [01:33] stgraber: sounds like a very tight race.. [01:34] [dev1-added][rfkill-restore starts and handles dev1][dev2-added][upstart acks that rfkill-restore is done and returns to stop/waiting] [01:34] seems like there's a very tiny window for dev2 to not be handled [01:36] An instance would then require a helper script, correct? [01:36] helper job, rather [01:36] Two jobs: One instance, one job to run the instance [01:36] Well, the helper is wait-for-state [01:37] So in order to use wait-for-state the job must be an instance? [01:37] but yes, there will be two jobs, one which lists the events, and runs the wait-for-state command for each instance of itself, and then the actual rfkill-restore [01:37] Redoubt: no, its just in this case, it makes more sense that way as it closes the race, even if the race is tiny [01:38] Of you have a job that lists the events and runs wait-for-state, doesn't that provide a window for the race to occur as well? [01:39] SpamapS: I'd actually have to check, but I vaguely remember the udev events being blocking on the udev side, which is that until the initctl done by udev returns, no other uevent can be emitted [01:40] hmm, upstart-events marks them as signal, so I guess not [01:40] http://paste.ubuntu.com/1393368/ [01:40] ah no, I'm being confused with some other weird udev rules we have somewhere else that doesn't use the bridge [01:40] WHATEVER_DEVICE_ADDED_RELIABLY_EXPORTS would be INTERFACE [01:41] stgraber: so udev will queue up the events until the waited for event is handled? [01:41] because that means you can just handle with or's [01:43] SpamapS: nope, as I said, I got confused with some other hacks I had to look at recently where something indirectly does an "initctl emit" from a udev hook, which in this case indeed blocks everything on udev's side. But that's not the case for those event emitted by upstart-udev-bridge. [01:45] SpamapS: so your solution is fine, as much as I dislike introducing an extra job to cover that. [01:48] stgraber: its a bug in upstart not to have this built in [01:49] stgraber: In fact we talked about just changing or's to work this way, but we'd have to call that upstart 2.0 or something.. because it would likely break some things [01:49] SpamapS: That would be handy! [01:50] Yeah, it would [01:50] yeah, or just add another keyword "or2" or whatever, not sure what'd be the most confusing for the users :) [01:50] well, its actually not or that is broken, per se [01:50] its blocking in general [01:50] it just doesn't get done if the goal does not change [01:52] what should happen is, on a blocking event emission, we should look for any start on's or stop ons that match, and then flip only the ones that need changing, but block if there are other events already being waited on for any that don't change [01:53] Of course, another one would be to finally do the "state rewrite" that keybuk intended, which would introduce a 'while' keyword and allow you to do 'while bluetooth-device is running' === jMCg_ is now known as jMCg [15:19] yay, my prctl branch builds and appears to work! [15:24] stgraber 25187 0.0 0.0 41988 1928 pts/4 S+ 10:22 0:00 | \_ /home/stgraber/data/code/upstart/init --session --confdir=~/.init/ [15:24] stgraber 25201 0.0 0.0 4328 360 ? S 10:24 0:00 | \_ /bin/sleep 2000 [15:24] neat! [15:25] and as init is now the parent, I can even stop that job (in the past it'd just hang as it wouldn't receive the SIGCHILD) [17:02] stgraber: *nice*