El Sábado, 12 de Diciembre de 2009, David Masover escribió: > On Saturday 12 December 2009 03:53:06 am Iñaki Baz Castillo wrote: > > Well, usually daemons are coded to deelte the pidfile upon receipt of a > > SIGINT signal (or some others). But if the daemon is killed with "kill > > -9 PID" then it terminates inmediately without deleting the piddile. > > True. I tried (and failed) to find an example of this working. However, a > separate process can watch your process and clean up after it however it > dies. I think this is the principle behind letting init handle it -- take > "upstart". I should take a deep look to "upstart". Until now I'm just used to usual Linux init scripts. But since Debian will adopt upstart it's good time to learn it :) > > In the case of a crash or segmentfault the daemon wouldn't delete the > > pidfile again. > > If the crash raises an exception, you can catch that. Yes, I catch all the exceptions, I meant segfaults that can occur when using Ruby C extensions (or when a Ruby bug occurs). > Segmentation faults > trigger SIGSEGV, which you can trap. Ops, I didn't know it at all. Really interesting. > I suspect you'd have a chance to at > least fire that unlink call with any death except a 'kill -9'. Ok, so do you say that using "upstart" this problem could be solved as upstart itself could manage it when detects a service crash? > > To summarize this is possible in these cases: > > > > a) Hardcoding the ruby location (avoiding using "env"). > > Not user-friendly. > > However, if you distribute your app as a gem, this problem actually goes > away. Here's the top of gems/rake-0.8.7/bin/rake: > > #!/usr/bin/env ruby > > #-- > # Copyright (c) 2003, 2004, 2005, 2006, 2007 Jim Weirich > ... > > Here's what it actually installs into your PATH: > > #!/usr/bin/ruby1.9.1 > # > # This file was generated by RubyGems. > So, that gives you the best of both worlds -- it's actually somewhat like > one of the crazier solutions I suggested. Great. However I'm not sure if my program would fit well as a gem. It's not library or utility but a whole http server (for XCAP protocol). This is, it will have conf files into /etc directory and so. I've never seen a gem that installs a server by itself and contains files in /etc. Also, I need a Debian init/upstart script so a gem is not fully valid for me. Thanks a lot for your help. -- Iñaki Baz Castillo <ibc / aliax.net>