From: "ara.t.howard" Date: 2007-08-19T06:03:34+09:00 Subject: Re: Slave not removing slave_proc_* files On Aug 18, 2007, at 12:54 PM, Jos Backus wrote: > Hi Ara, how do. >> >> what is this code supposed to do exactly? > > Mongrel::Runner.new.run(args) will start running relative to the > parent, > meaning that (since we are talking about the swiftiplied Mongrel > here) it will > connect to the swiftiply proxy and handle any requests sent by it. > The parent > isn't interested in making any method calls to the slaves; the > slaves are > meant to run forever. does mongrel fork to accomplish that? if not why not simply threads << Thread.new{ Mongrel::Runner.new.run(args) } > > So my guess that I am using Slave wrong appears correct. The above > explains > why the sockets remain. Since Slave.object returns a thread I > figured I could > just join them to block the parent. > you could *if* mongrel returned an object. the fact that i never returns leaves slave half baked... > My idea is to have a simple way to host a bunch of Rails apps/ > multiple > instances of the same Rails app. So I am trying to start N > mongrel_rails > processes managed by swiftiply_mongrel_rails which in turn will be > managed by > daemontools. To accomplish this, I added the change in the post below > mentioned to mongrel_rails.rb so that rather than using backticks I > can just > call this Mongrel::Runner.run method (maybe that is the wrong > approach and I > should just use backticks/Kernel.system()). > > Slave seemed like an easy way to manage the children and avoid > zombies. Is > there a correct way of doing this with Slave? Or is it the wrong > tool for the > job? In that case I'll use fork/exec, Process.waitall and a SIGTERM > handler in > the parent which kills the children, etc. to get the job done. > i think the LifeLine class of slave is exactly what you need and that you can re-use it. basically the idea is this socket = Socket.pair cid = fork if cid stuff else Thread.new{ socket.read rescue exit } stuff end in summary, the child reads from a pipe to the parent. if the read ever returns the parent has died - so exit. this is the 'zombie' preventer of slave.rb. if you look at slave.rb and grep for LifeLine and @lifeline you'll see the usage. summary is: lifeline = LifeLine.new cid = fork unless cid # child @lifeline.catch @lifeline.cling else @lifeline.throw end and the poor man's version: cfp:~ > cat a.rb r, w = IO.pipe cid = fork unless cid ### child w.close Thread.new{ begin r.read ensure STDERR.puts 'parent died... exiting!' Kernel.exit end } sleep and 'pretend some processing is going on...' else r.close sleep 2 and 'pretend the parent exited' end cfp:~ > ruby a.rb parent died... exiting! > There are no references to SystemExit in swiftiply-0.6.1: > > # pwd > /usr/lib/ruby/gems/1.8/gems/swiftiply-0.6.1 > # grep -r SystemExit . > # > right. but there *should* be *if* blanket Exceptions are rescued. > Thanks for your help, Ara. always good to have testers. er, i mean users ;-) a @ http://drawohara.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama