/srv/irclogs.ubuntu.com/2012/11/27/#upstart.txt

fission6what do you mean00:00
SpamapSwe, the unix loving people of the world :)00:00
fission6ok ill email them with my final script (maybe) once i get something i like going00:00
fission6let me review whats been mentioned here and get back to you SpamapS for a review if thats ok00:00
fission6that cool SpamapS 00:06
jamescarrheya16:05
jamescarrI have an upstart script that originally used respawn. I fixed it to not use respawn but it always respawns16:06
jamescarreven when stopping the service through upstart16:06
SpamapSjamescarr: stopping a job would never lead to a respawn.16:19
SpamapSjamescarr: respawn only happens if the program exits with a non-normal exit code/signal (which, by default, there is only one normal exit, 0)16:19
SpamapSjamescarr: do you have stuff from syslog?16:19
jamescarrSpamapS: well, originally I had respawn in my upstart script, then I realized the service it was starting starts as a daemon, causing it to respawn every second16:20
jamescarrSpamapS: I fixed the upstart script by removing the respawn and changing the service config, but it keeps going16:20
jamescarrno matter how many times I tell it to stop :(16:20
jamescarrsyslog is just filling up with "Nov 27 10:21:20 ultipro-api init: ultipro-api-service main process ended, respawning" every minute16:21
SpamapSjamescarr: if its a daemon, you just use expect fork, or expect daemon, and then it won't respawn like that16:21
jamescarrI set that16:22
jamescarrit keep going16:22
SpamapSperhaps it forks more than twice?16:22
SpamapSjamescarr: and the program has no "--nodaemonize" mode?16:22
jamescarryeah16:23
jamescarrshould I just reboot!?16:24
SpamapSjamescarr: in that case, you might be better off starting the program in pre-start, and recording a pidfile, then stopping it in post-stop16:24
jamescarrSpamapS: how can I just outright stop it for now?16:24
jamescarrit won't stop coming back16:24
SpamapSjamescarr: stop jobname16:25
SpamapSjamescarr: that will not respawn.. it changes the intended state to 'stop'16:25
SpamapSwhich exits any respawn code16:26
jamescarrSpamapS: I've don this tons of times16:26
jamescarrsudo initctl stop jobname16:26
jamescarrit just gives me... 16:26
jamescarr"ultipro-api-service start/running, process 734 "16:26
SpamapS*stop* says that?16:29
SpamapSjamescarr: thats very unusual16:29
jamescarrI should mention I accidentally copy and pasted the start script into the pre-stop script the first time16:29
jamescarrI fixed it, but it keeps doing this 16:29
SpamapSjamescarr: its possible that is causing issues...16:30
SpamapSjamescarr: especially if that script calls 'start'16:30
jamescarryeah, I meant to replace it with stop but I screwed up16:30
jamescarrI since fixed it, but the results seem to be from the first upstart script16:31
SpamapSjodh: ^^ another use case for a "please forget about this job" command16:31
SpamapSslangasek: ^^16:31
SpamapSjamescarr: yeah, the new conf file isn't loaded until the 1st instance stops16:31
jamescarroh man16:32
jamescarranyway to stop the first one?16:32
SpamapSjamescarr: this might require a reboot unfortunately16:32
stgraberjodh, xnox: signal sender=:1.9 -> dest=(null destination) serial=3 path=/com/ubuntu/Upstart; interface=com.ubuntu.Upstart0_6; member=Restarted16:34
stgraberended up being a tiny bit more tricky than I had expected as the code needs to be added much later than jodh first though as we need to wait until upstart is done reconnecting to DBus16:35
stgraberas a result, the signal is emitted whenever upstart restarts, not only for successful stateful re-execs, but I think that makes sense as the Instance Init don't really care whether it was succesful or not, they need to restart regardless16:36
stgrabernow to figure out how to write tests for that stuff :)16:38
mattiazahi all! I have a question about writing/debugging multiple dependencies in an upstart script17:21
mattiazaI see that this has been discussed long ago: https://lists.ubuntu.com/archives/upstart-devel/2010-April/001252.html17:21
mattiazabut at the moment, my job won't start or stop as expected by following the same pattern17:22
SpamapSmattiaza: its important to start with the right frame of mind. Upstart is not dependency based, it is event based.17:22
SpamapSmattiaza: what start on and stop on do you have now?17:23
mattiazaI understand (but only very vaguely). starts and stops of other services generate events, and then these trigger start/stop on conditions. but how are events stored or cached when combining them?17:24
SpamapSthey're not stored or cached17:24
SpamapSthe event blocks until all consumers of the event change state17:25
SpamapSmattiaza: its a very "now" thing, so if nothing needs to change, the event is gone.17:26
mattiazaaha.17:26
mattiazaat the moment, my conditions are:17:26
mattiazastart on (started postgresql and started rabbitmq-server)17:26
mattiazastop on (stopping postgresql or stopping rabbitmq-server)17:26
mattiazawhat I'm trying to achieve is: my service needs postgresql and rabbitmq-server. therefore it should start automatically once both have been brought up, and it should stop when either of them goes away17:27
mattiazait would be nice if it also worked not only at system startup time, but also when I restart postgresql for example - but this is more of a nice-to-have17:29
SpamapSmattiaza: ok, first, you're doing it wrong. :)17:31
SpamapSmattiaza: those are network services17:31
SpamapSmattiaza: so your app just has to deal with them not being up sometimes.17:31
SpamapSmattiaza: if they were on another server, you couldn't control the boot order17:32
SpamapSmattiaza: you're better off having your service retry and/or degrade until postgres and rabbit are available.17:33
SpamapSmattiaza: and then just 'start on runlevel [2345]'17:33
SpamapSand 'stop on runlevel [^2345]'17:33
mattiazaI'll test it a bit...17:33
SpamapSmattiaza: do you understand why though?17:33
SpamapSmattiaza: upstart *can* express this. But it takes 2 jobs, one to keep track of the state of pgsql and rabbit, and another to run your service17:34
mattiazaif I ever wanted to move postgres or rabbitmq to another server, then sure, it would be useful if it retried connections17:34
mattiaza"my service" is django-celery worker, I'm investigating if it handles broken connections or not17:34
SpamapSmattiaza: s/if I ever wanted to /when I am forced to /17:34
mattiazatested it with various configuration of the services running or not.17:42
mattiazacelery is mostly reasonable: if rabbitmq is down, it retries connections. if postgresql is down, it runs tasks, but their results cannot be written and they are simply discarded forever.17:44
mattiazauwsgi django app itself errors when postgresql is down (obviously), but hangs forever if rabbitmq is down and it can't queue up new tasks.17:45
mattiazaso at the moment, by starting celery on network-runlevels, it would technically run - but it would silently eat all tasks if rabbitmq comes up before postgresql17:46
mattiazai'd say that at the moment, linking the start on and stop on conditions to postgresql only makes most sense17:47
mattiazaI don't expect to move the server to another machine in the next 6 months, and for now it appears to be the most reliable configuration17:47
SpamapSmattiaza: that honestly sounds like you have a very broken queue runner17:51
SpamapSmattiaza: you're saying, if pgsql goes down, all of your queued work is lost17:51
SpamapSand thats ok?17:51
mattiazaappears that way!17:52
SpamapSawesome17:52
mattiazanot sure if there are ways to make sure the queued jobs get persisted and retried if they fail17:52
SpamapSmattiaza: you probably shouldn't be consuming the messages until the work is done.17:53
mattiaza(and if they are persisted in pgsql, then it's still down :)17:53
SpamapSanother option is to put them back in the queue yourself17:53
SpamapStry: write to db except: unrecoverable db error; resubmit17:54
mattiazaI would expect this to be possible, as many other people are also using rabbitmq+celery as the standard django background task queue17:55
mattiazahave to see if there are configuration options I missed17:55
SpamapSIts totally possible.17:56
SpamapSJust.. not actually helpful. :)17:56
SpamapSmattiaza: here's another thought. You could just have your thing start on started postgresql and stop on stopping postgresql18:08
mattiazayep, that seems to be the most reliable method for now, and would not require complex celery hacking. reading documentation on how to add event emitting to postgresql old init scripts now18:09
mattiazamy old start on command would never have worked anyway, as apparently neither postgresql and rabbitmq-server emit any events :)18:10
JanCyou can make them emit events if you want...18:16
mattiazapostgresql old-style startup scripts look daunting.. might give it a try, but don't want to mess them up too much18:23
mattiazaI have another idea though18:23
mattiazahttp://manpages.ubuntu.com/manpages/precise/en/man8/upstart-socket-bridge.8.html seems to be a way to see events on sockets - is there a way to listen for events on "socket on port X started listening" ?18:24
mattiazathen I could have an event when postgresql really is ready to accept connections18:24
SpamapSmattiaza: socket activation is not what you want in this case18:49
mattiazacool, got it working :)19:10
mattiazaadded some initctl emit lines to postgresql scripts19:10
mattiazanow the celery service is started and stopped together with it19:10
mattiazanot the ideal solution, but it should reduce the potential for queued tasks being consumed but failing19:11
SpamapSmattiaza: seems like something the celery people would have dealt with.. this is a pretty common pattern (read a job, do some work, record the result). Usually in AMQP there is a way to make messages only disappear on "ACK"19:14
mattiazayep, I'll investigate that tomorrow19:14
mattiazaI'm still overwhelmed by the complexity of rabbitmq + celery workers + task result storage in database (the recommended production setup), and how all these interact together19:16
SpamapSmattiaza: given that you have 1 server.. it does seem.. overkill19:21
mattiazayes - it also only needs to scale to an amazing 5 requests per hour :)19:22
SpamapSmattiaza: *l o l*19:31
SpamapStotally worth this much time19:31
mattiazaheading home now, thanks for your help!19:37
cheezithas anyone run upstart 1.5 with 11.10?20:06
cheezitnm that didn't work 2 well20:17

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