/srv/irclogs.ubuntu.com/2009/11/10/#upstart.txt

=== robbiew is now known as robbiew_
olycan anyone tell me what happens when you do stop jobname ? ie what events are sent 12:05
olycurrent my job starts but does not stop so guessing it need to handle specific events12:06
olyis there a way to debug upstart scripts i am running stop scriptname and its locking the terminal 13:11
olyi can press ctrl + c to cancel but how can i find why it never stops its probably my program but i want to modify it to work correctly ?13:12
sadmacoly: locking the terminal is rare. Are none of the other vts working?14:18
olysorry vts ? i am new to upstart14:21
sadmacoly: other virtual terminals14:21
sadmacoly: ctrl+alt+f(2-6)14:22
olyyeah its not locking like that it just does not return to the prompt14:22
sadmacoly: ok, open another terminal14:22
olyyep14:22
sadmacoly: initctl list should give you something to go on14:23
sadmacoly: hopefully you'll get a pid from there. Then you can attach gdb to it and go nuts14:23
olyusm start/killed, process 22445 thats what it says 14:24
olyand its still sat at the prompt in the other terminal trying to start14:24
olythere any examples around for a python daemon script 14:25
olyas my program is a python web server basically 14:26
sadmacoly: start/killed means it was planning on coming back up...14:30
sadmacoly: try kill -9 2244514:30
olysays theres no such process14:31
olywhich i have just confirmed with ps -A | grep 2244514:32
sadmacoly: ok, that's a problem...14:34
sadmacKeybuk: any ideas? ^^14:34
olyi guess its something i have done i have been trying things with the scripts to get it working 14:35
sadmacoly: does your job have pre-stop/post-stop scripts?14:35
olynope at least not now14:36
JanColy: http://www.python.org/dev/peps/pep-3143/ might be the best place for info about writing a unix daemon in python14:36
olyokay i have a lot of that code, is there anything on the upstart side for a program like that ?14:37
olyor can some one recommend me a good exmple that should work with that sort of program14:37
olyonce i know the upstart script is correct i can start checking my code 14:38
olyat the moment prestart echo does not even print14:38
olyguessing thats to do with the usm start/killed message14:38
olyis there any way to clear that ?14:38
JanChttp://pypi.python.org/pypi/python-daemon/ --> a library implementing correct daemon behaviour14:39
sadmacoly: if the task is dead and gone then upstart should be moving along14:41
olythose links are great think i used them to write it originally 14:43
olycan i reset upstart so it rechecks some how ?14:43
sadmacoly: try doing stop usm again14:43
sadmacugh. I need to get the code in front of me...14:44
olyusm stop/killed, process 2244514:44
olynow says already stopped14:44
olyperhaps it just takes a very long time to stop14:45
sadmacoly: it should be stop/waiting14:48
sadmacthe process is gone, but the state machine isn't progressing14:48
=== robbiew_ is now known as robbiew
sadmacand I forget what's supposed to happen in the Killed state so I don't know what to look for14:48
sadmacoly: check ps for <defunct> entries14:49
olynone related only ones are for chromium14:49
Keybukusually means that upstart has the wrong pid for the process14:50
Keybukie. expect fork when you meant expect daemon14:50
sadmacKeybuk: but it got to the running state. It didn't hang until he stopped it14:50
Keybukwas the pid right when it was in the running state?14:51
olyunknown and cant restart now 14:53
olyactually will just check that 14:53
olyyeah because its not cleared from upstart it never starts now14:54
sadmacupstart should really deal with these kinds of crap situations better, though I think proc connector will make most of that irrelevant14:54
olythanks for the help, useful info anyway14:57
Keybukalso check that the ppid of your daemon is actually 114:58
Keybuksometimes you end up watching a pid that has a different parent14:58
Keybukif ppid != 1, then upstart will never know it died14:58
Keybuksometimes Upstart follows the wrong fork, for example:14:58
Keybuk  expect fork14:58
Keybuk  script14:58
Keybuk    OPTS=$(cat /etc/default/options)14:58
Keybuk    exec my-daemon $OPTS14:58
Keybuk  end script14:58
Keybukin that case, upstart ends up with the PID of "cat"14:59
Keybukand since cat is a child of the shell, the shell gets the SIGCHLD not upstart14:59
Keybukso it fails14:59
sadmacits kind of astonishing how many ways this thing can break15:00
olyyeah well i guess i should have used ecpect daemon instead of fork from a comment further up 15:00
olycurrently my daemon is not running and nothing with the pid upstart has is running15:01
Keybukdaemon means "forks twice"15:02
Keybuknot once15:02
sadmacunfortunately posix doesn't seem to offer a version of kill that lets you load the arguments, so you can't send a manual CLD and get it going again15:03
olyhum could this be an issue my program has child daemons which are still running15:03
sadmacoly: no, upstart likely lost those15:04
olyi did not think upstart would care about those 15:04
sadmacit won't15:05
olykilled them anyway 15:05
olyalso can upstart handle my app if i dont start it as a daemon ie so that it would lock the terminal 15:06
olyas i can do this as a test by passing a prameter to the program15:07
sadmacoly: it could work15:07
sadmacoly: actually no, upstart would grab the initial process and fall over immediately15:08
olyokay15:08
olywell thanks for the help will try again a bit later i think15:11
olyif anyone happens to think of a way to clear upstarts current list other than rebooting let me know :)15:29
sadmacoly: kill -HUP 1, but that will make it forget /everything/ its managing15:30
olyokay that will do for now 15:31
olyat least while testing15:31
olyreboot each time would be more of a problem 15:31
sadmacexploiting bugs against bugs. isn't life grand?15:31
olylol, thats a bug is it :p15:31
olythink upstart needs a new option to force remove a process from its list by id15:32
sadmacoly: kill -HUP re-executes init. Technically this should have no noticeable effect.15:32
sadmacoly: maybe. It'd be better if it just managed services better (and it will.)15:32
olyyeah that would be better, but some times it nice to have a fall back option in place15:36
Keybukoly: Upstart should never lose the process16:30
KeybukI'd rather spend time fixing those bugs16:30
Keybukotherwise some idiot will come up with something that deliberately tells upstart to lose pids because of some other problem, etc.16:30
olyfair enough16:31
olybut it seems if i for example writes bad code i coudl always break it even if its not intentional16:32
olyunless it keeps following the path of my programs forking 16:32
Keybukright, that's the correct fix ;)16:33
olyah okay :p16:33
sadmacoly: eventually upstart will track everything your program forks off until one of them calls setsid.16:33
sadmacoly: this has just taken some kernel infrastructure (now in place).16:33
olyaha that would be good 16:33
olywhat would happen if you branched of seperate programs from it ?16:34
sadmacoly: they would call setsid()16:34
sadmacoly: that's just good unix practice16:34
olymy program launches itself then two sub process as different userts which it communicates with using ipc16:34
olyaha fair enough16:34
Keybukoly: ah16:42
Keybukbut in that case, you want upstart to know about all three pids16:43
Keybukyou might even want it to, if one of the pids dies, to deliberately send SIGTERM to the other two so that the process can be respawned16:43
olymaybe, although the main program currently manages the other processes so thats not really important16:46
Keybukah, but if it segfaults ...16:46
olyi guess, but for now i would just be happy to stop and start the main program with upstart :)16:47
sadmacKeybuk: to an extent thats useful. In reality to do that right the daemon would have to tell upstart which pids are what and what they mean. If an apache worker dies we ignore it. If the apache master dies we need to kill the workers.16:48
olymight as well create it for modern linux system as it requires a lot of modern software to function :p16:48
Keybuksadmac: sure16:48
sadmacKeybuk: I'm guessing libupstart will return for some of this. A lot of apps will want to give little hints to upstart and won't want to deal with the whole apparatus of their native dbus API to do it.16:49
sadmacKeybuk: (naturally libupstart would be a wrapper around a few nih_dbus calls, not the old protocl)16:50
Keybukthat kind of thing, yes16:51
JanCI don't know the exact way apache works, but if apache master dies, won't you want the workers to finish the current request first (or does it need the master for that)?16:52
KeybukJanC: that's more like ssh ;)16:52
Keybukbetter question, would you want to restart the master while the workers are still there?16:53
olyi know i would certainly want my child processes to finsh 16:53
olyas they have a queue of commands to pass through16:53
Keybukthere are enough interesting scenarios here that knowing about "workers" is a good idea16:54
olymy program is not that intrested in the child processes as long as they are running, because it just writes commands to a text file and the children act on them 16:55
olyso they can carry on running after the parent has finished in fact if they did not the system would probably be a lot more unpredictable16:55
olyif any of this info is of any use :)16:56
sadmacoly: you're using a text file as a command spool?16:56
olyyeah basically 16:56
sadmacoly: ...upstart aside you may want to re-examine your programming techniques16:57
olyit queue up the commands because some can take a lot of time so they must not block the original program 16:57
olywhy is there a better way than ipc type method16:57
olythis was the only way i could find as all 3 program run as different users so communication between them was a pain 16:58
Keybuknothing wrong with that style16:58
Keybukit's just using the filesystem as shared memory16:58
Keybuktried, tested and true UNIX way of doing things, that16:58
sadmacKeybuk: when we have...shared memory16:58
Keybuksadmac: which is, in Linux, implemented as a filesystem16:58
Keybukin which you create files16:59
Keybukthat you use as spools16:59
sadmacor for that matter, pipes and unshared memory to spool from16:59
Keybukpipes are two-way only16:59
Keybukoly said he has two workers and a master16:59
Keybukso fifos don't work16:59
olythe master works as root which breaks of a web server into a restricted use account, and send info back to the program in the root account 17:00
olythats the type of thing i needed17:00
sadmacKeybuk: there is a way. It involves some descriptor passing (easier to do with threads but very possible with processes).17:00
Keybuksure17:00
sadmacI was starting to write a web server that did this.17:00
Keybukbut why not just use a file? :p17:00
sadmacoly: are you using mmap?17:01
olynope not come across mmap17:02
sadmacoly: ok you should at least be mmaping the file.17:02
olyokay whats that do then in quick terms :p17:03
olyi will research at some point17:03
sadmacoly: It lets you access the file as though it were ram17:05
olysounds intresting17:05
olyprobably would have saved me a load of work writting a parse by sounds of it :p17:06
JanColy: http://docs.python.org/library/mmap.html17:06
JanC;)17:06
olyhum, i can think of other uses for that in my program as well 17:08
oly:)17:08
olythanks for that 17:08
Keybukugh17:12
Keybukmmap is going to hurt them17:12
Keybukmy hobby: finding programs that "cleverly" mmap() files into memory, and truncating the files under them :p17:13
=== robbiew is now known as robbiew_
=== robbiew_ is now known as robbiew
=== robbiew is now known as robbiew_
=== sadmac__ is now known as sadmac_home

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