=== Getty826 is now known as Getty === mbiebl_ is now known as mbiebl [11:43] Is there a document somewhere describing how upstart issues SIGTERM and SIGKILL, I can recall reading something about it, but I can't remember where [12:08] I'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. [14:21] Do whatever shutdown mechanics you need in pre-stop. [14:24] hmm, can I send a signal to my program in pre-stop? [14:24] (my program is a webserver, and there's information that I need to make sure is persisted prior to killing it) [14:24] sure [14:25] Do whatever you need. [14:25] using kill -s SIGNAL, right? [14:25] yes [14:25] and then have my program listen for that signal? [14:26] can I get the PID for the process that upstart created? [14:26] (eg, $PID, like the other variables upstart provides me) [14:29] (I haven't actually been able to find a list of variables available within upstart scripts) [14:42] Are 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:43] The environment variables are listed in init(5). [14:43] pre-stop script [14:43] PID= [14:43] eval "$( [14:43] status | \ [14:43] sed -nre 's|^.* stop/pre-stop, process ([0-9]+)$|PID=\1;|p' [14:43] )" [14:43] [ -n "$PID" ] [14:43] # Do stuff with "$PID" [14:43] end script [14:45] hmm.. okay. [14:46] so, 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 sent [14:48] yes [14:48] okay, I think I get what you mean. [16:21] hmm, kill timeout seems not to always function correctly.. [16:26] it seems to not always space them out [16:52] actually, it was working, just that my program didn't flush before I exited from within. [18:55] hi, are there any script sections that will execute upon starting and already started job? [18:56] ie, 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:57] if 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 accordingly [18:58] with a post-stop script, the job actually enters and stays in started state, and i can no longer modify the NUM_INSTANCES without stopping/starting [19:11] the started event will pass the "name" of the instance as $INSTANCE [19:11] so you get as many: [19:11] started JOB=$jobname INSTANCE=$instancename [19:11] as there are instances [19:11] is that what you mean? [19:12] not exactly [19:14] ive got a "launcher" job that i start like: start launcher NUM_INSTANCE=5 [19:14] ok [19:14] and that runs start INSTANCE=$i ? [19:14] or somesuch thing? [19:14] in the pre-start, yeah [19:14] ideally id like to be able to do 'stop launcher' and it will tear down all the jobs it has launched [19:14] which works [19:15] but id also like to later be able to do: start launcher NUM_INSTANCE=10 to launch an additional 5 [19:15] its more for convienence than anything, i could certainly just do it manually or via some script elsewhere [19:15] right [19:15] so you're going to need somewhere to store state [19:16] your launcher will need to use /var/run to record how many instances it has running [19:16] you might want a second job "on started " to verify that they are running [19:16] and then your stop will iterate that /var/run file to shut them down [19:16] likewise your start will check that file to see how many more it needs to start [19:16] right now im just querying initctl list to find out how many are running [19:17] yeah, you could do that too [19:17] the starting and stopping isn't an issue [19:17] and actually, i can start the job again with a different NUM_INSTANCES and sync the number of jobs running accordingly [19:18] my 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 running [19:18] right [19:18] because you've used pre-start [19:18] it's "running" [19:18] the alternative would be to use "task" and "script" [19:19] but then "stop launcher" won't work [19:19] another option for you: [19:19] to adjust the number of instances use "restart job NUM_INSTANCES=10" [19:19] and 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 target [19:20] that will require current instances to be stopped, though? [19:22] no, you could do some magic in your post-stop to prevent that [19:22] after all, it's your code stopping the current instances [19:23] that sounds like it might do the job [19:24] while i have you, are there any plans to implement some form of scripted status operation? [19:24] how do you mean? [19:26] well, as far as i can see.. status some-job just reports that its pid is running and returns accordingly? [19:26] yes [19:26] you're asking the init daemon what its understanding of the process's status is [19:26] as far as init is concerned, a process is running or it isn't [19:26] yeah [19:28] what were you expecting instead? [19:29] something 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] but that would mean Upstart would have to continually run those [19:30] for that kind of thing, you probably want something like monit [19:30] that can do things like connect to a server, make requests, etc. to determine whether the running process is stoned, etc. [19:30] and if so, tell Upstart to take action to respawn it [19:30] (killing the stoned process in the process, obviously) [19:31] right [19:31] i guess im just used to abusing init.d scripts [19:32] yeah, Upstart takes a "everything that is running is ok" approach [19:32] ie. hands off sysadmin [19:33] you shouldn't need to login to 10,000 boxes every day and run "status" just to see whether the service is still ok [19:33] that's the init daemon's job [19:35] so one thing I will be supporting in Upstart 2 is side-along jobs [19:35] and temporal jobs [19:36] so you'd be able to do things like: [19:36] every hour [19:36] while running [19:36] script [19:36] test_its_working || restart [19:36] end script [19:36] type things [19:38] nice. :) [19:41] another thing you could do would be define a custom command: [19:41] on print-status [19:41] script [19:41] echo ... [19:41] end script [19:41] then "yourjob print-status" would run that [19:41] but that wouldn't be automatic as a result of "status" (but /usr/sbin/service could, for example) [19:41] since "status" itself is supposed to be [19:41] (a) cheap [19:41] (b) safe [20:00] custom commands sounds like a nice feature