/srv/irclogs.ubuntu.com/2011/02/24/#upstart.txt

=== Getty826 is now known as Getty
=== mbiebl_ is now known as mbiebl
micheilIs there a document somewhere describing how upstart issues SIGTERM and SIGKILL, I can recall reading something about it, but I can't remember where11:43
micheilI'm basically wanting to be able to send a signal to my process to kill it, but allowing me time to shut down the process properly.12:08
ionDo whatever shutdown mechanics you need in pre-stop.14:21
micheilhmm, can I send a signal to my program in pre-stop?14:24
micheil(my program is a webserver, and there's information that I need to make sure is persisted prior to killing it)14:24
ionsure14:24
ionDo whatever you need.14:25
micheilusing kill -s SIGNAL, right?14:25
ionyes14:25
micheiland then have my program listen for that signal?14:25
micheilcan I get the PID for the process that upstart created?14:26
micheil(eg, $PID, like the other variables upstart provides me)14:26
micheil(I haven't actually been able to find a list of variables available within upstart scripts)14:29
ionAre you sure just letting Upstart send TERM and using something like “kill timeout 120” to give it time before sending KILL isn’t enough?14:42
ionThe environment variables are listed in init(5).14:43
ionpre-stop script14:43
ion  PID=14:43
ion  eval "$(14:43
ion    status | \14:43
ion    sed -nre 's|^.* stop/pre-stop, process ([0-9]+)$|PID=\1;|p'14:43
ion  )"14:43
ion  [ -n "$PID" ]14:43
ion  # Do stuff with "$PID"14:43
ionend script14:43
micheilhmm.. okay.14:45
micheilso, if I just give my process ample time to shutdown, then first it'll recieve SIGTERM, then there'll be X timeout before SIGKILL is sent14:46
ionyes14:48
micheilokay, I think I get what you mean.14:48
micheilhmm, kill timeout seems not to always function correctly..16:21
micheilit seems to not always space them out16:26
micheilactually, it was working, just that my program didn't flush before I exited from within.16:52
adam_ghi, are there any script sections that will execute upon starting and already started job? 18:55
adam_gie, im using an upstart job to start a variable number of instances of another job. there is a default number, but it can also be passed to the upstart job as NUM_INSTANCES.  18:56
adam_gif the upstart job never enters the started state, i can just start it again with a new NUM_INSTANCES, and the pre-start script will start up or shutdown instances accordingly18:57
adam_gwith a post-stop script, the job actually enters and stays in started state, and i can no longer modify the NUM_INSTANCES without stopping/starting18:58
Keybukthe started event will pass the "name" of the instance as $INSTANCE19:11
Keybukso you get as many:19:11
Keybuk  started JOB=$jobname INSTANCE=$instancename19:11
Keybukas there are instances19:11
Keybukis that what you mean?19:11
adam_gnot exactly19:12
adam_give got a "launcher" job that i start like: start launcher NUM_INSTANCE=519:14
Keybukok19:14
Keybukand that runs start <somethingelse> INSTANCE=$i ?19:14
Keybukor somesuch thing?19:14
adam_gin the pre-start, yeah19:14
adam_gideally id like to be able to do 'stop launcher' and it will tear down all the jobs it has launched19:14
adam_gwhich works19:14
adam_gbut id also like to later be able to do: start launcher NUM_INSTANCE=10 to launch an additional 519:15
adam_gits more for convienence than anything, i could certainly just do it manually or via some script elsewhere19:15
Keybukright19:15
Keybukso you're going to need somewhere to store state19:15
Keybukyour launcher will need to use /var/run to record how many instances it has running19:16
Keybukyou might want a second job "on started <thing>" to verify that they are running19:16
Keybukand then your stop will iterate that /var/run file to shut them down19:16
Keybuklikewise your start will check that file to see how many more it needs to start19:16
adam_gright now im just querying initctl list to find out how many are running19:16
Keybukyeah, you could do that too19:17
adam_gthe starting and stopping isn't an issue19:17
adam_gand actually, i can start the job again with a different NUM_INSTANCES and sync the number of jobs running accordingly19:17
adam_gmy issue is that, once the launcher job is in the started state, i can't just start it again with a new NUM_INSTANCES since its already running19:18
Keybukright19:18
Keybukbecause you've used pre-start19:18
Keybukit's "running"19:18
Keybukthe alternative would be to use "task" and "script"19:18
Keybukbut then "stop launcher" won't work19:19
Keybukanother option for you:19:19
Keybukto adjust the number of instances use "restart job NUM_INSTANCES=10"19:19
Keybukand have the post-stop check whether the new num instances is not the old, and if so, you know you're being restarted with a new target19:19
adam_gthat will require current instances to be stopped, though?19:20
Keybukno, you could do some magic in your post-stop to prevent that19:22
Keybukafter all, it's your code stopping the current instances19:22
adam_gthat sounds like it might do the job19:23
adam_gwhile i have you, are there any plans to implement some form of scripted status operation?19:24
Keybukhow do you mean?19:24
adam_gwell, as far as i can see.. status some-job just reports that its pid is running and returns accordingly? 19:26
Keybukyes19:26
Keybukyou're asking the init daemon what its understanding of the process's status is19:26
Keybukas far as init is concerned, a process is running or it isn't19:26
adam_gyeah19:26
Keybukwhat were you expecting instead?19:28
adam_gsomething similar to a sysv init script, where the status operation can be scripted to do any number of checks so long as its return codes conform to spec. the same of start and stop.. 19:29
Keybukbut that would mean Upstart would have to continually run those19:29
Keybukfor that kind of thing, you probably want something like monit19:30
Keybukthat can do things like connect to a server, make requests, etc. to determine whether the running process is stoned, etc.19:30
Keybukand if so, tell Upstart to take action to respawn it19:30
Keybuk(killing the stoned process in the process, obviously)19:30
adam_gright19:31
adam_gi guess im just used to abusing init.d scripts 19:31
Keybukyeah, Upstart takes a "everything that is running is ok" approach19:32
Keybukie. hands off sysadmin19:32
Keybukyou shouldn't need to login to 10,000 boxes every day and run "status" just to see whether the service is still ok19:33
Keybukthat's the init daemon's job19:33
Keybukso one thing I will be supporting in Upstart 2 is side-along jobs19:35
Keybukand temporal jobs19:35
Keybukso you'd be able to do things like:19:36
Keybuk  every hour19:36
Keybuk  while running19:36
Keybuk  script19:36
Keybuk    test_its_working || restart19:36
Keybuk  end script19:36
Keybuktype things19:36
adam_gnice. :)19:38
Keybukanother thing you could do would be define a custom command:19:41
Keybuk  on print-status19:41
Keybuk  script19:41
Keybuk    echo ...19:41
Keybuk  end script19:41
Keybukthen "yourjob print-status" would run that19:41
Keybukbut that wouldn't be automatic as a result of "status" (but /usr/sbin/service could, for example)19:41
Keybuksince "status" itself is supposed to be19:41
Keybuk (a) cheap19:41
Keybuk (b) safe19:41
JanCcustom commands sounds like a nice feature20:00

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