From: Joel VanderWerf Date: 2009-02-20T14:25:28+09:00 Subject: Re: a little daemon daemonizes, but hangs the logout Nobuyoshi Nakada wrote: > Hi, > > At Thu, 19 Feb 2009 23:25:20 +0900, > Brian Candler wrote in [ruby-talk:328745]: >> And there is this one from rackup (part of the rack package) >> >> if daemonize >> if RUBY_VERSION < "1.9" > > Assuming it's possible to check a feature by version number is > an evil habitat. You can just do it by > > unless defined?(Process.daemon) > > or, define your own Process.daemon. > > module Process > unless defined?(daemon) > def self.daemon(nochdir=nil, noclose=nil) > exit! if fork > Process.setsid > unless nochdir > Dir.chdir "/" > end > unless noclose > STDIN.reopen "/dev/null" > STDOUT.reopen "/dev/null", "w" > STDERR.reopen STDOUT > end > end > end > end It doesn't need to fork twice? Also the File.umask 0000 line differs from Brian's version (and others I've seen). I've never understood why the umask is needed, and in fact recently took it out of some daemons because it was causing dirs to get ceated as world writable. Why would a daemon want that? -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407