diff options
author | Joshua Peek <josh@joshpeek.com> | 2008-05-05 10:22:29 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-05-05 10:22:29 -0500 |
commit | 3cffe92ff066c2b35eef409547db93652c5cccfc (patch) | |
tree | f714643a4043d9fb73b39ec2a114d18f5deeffdd /activesupport/lib/active_support | |
parent | d75525b045b9f27ed108912a6dbdbad5ab775045 (diff) | |
download | rails-3cffe92ff066c2b35eef409547db93652c5cccfc.tar.gz rails-3cffe92ff066c2b35eef409547db93652c5cccfc.tar.bz2 rails-3cffe92ff066c2b35eef409547db93652c5cccfc.zip |
Added Ruby 1.8 implementation of Process.daemon
Diffstat (limited to 'activesupport/lib/active_support')
3 files changed, 28 insertions, 10 deletions
diff --git a/activesupport/lib/active_support/core_ext/kernel/daemonizing.rb b/activesupport/lib/active_support/core_ext/kernel/daemonizing.rb index 0e78819fdf..ed9d1f9bf2 100644 --- a/activesupport/lib/active_support/core_ext/kernel/daemonizing.rb +++ b/activesupport/lib/active_support/core_ext/kernel/daemonizing.rb @@ -2,14 +2,6 @@ module Kernel # Turns the current script into a daemon process that detaches from the console. # It can be shut down with a TERM signal. def daemonize - exit if fork # Parent exits, child continues. - Process.setsid # Become session leader. - exit if fork # Zap session leader. See [1]. - Dir.chdir "/" # Release old working directory. - File.umask 0000 # Ensure sensible umask. Adjust as needed. - STDIN.reopen "/dev/null" # Free file descriptors and - STDOUT.reopen "/dev/null", "a" # point them somewhere sensible. - STDERR.reopen STDOUT # STDOUT/ERR should better go to a logfile. - trap("TERM") { exit } + Process.daemon end -end
\ No newline at end of file +end diff --git a/activesupport/lib/active_support/core_ext/process.rb b/activesupport/lib/active_support/core_ext/process.rb new file mode 100644 index 0000000000..0b0bc6dc69 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/process.rb @@ -0,0 +1 @@ +require 'active_support/core_ext/process/daemon' diff --git a/activesupport/lib/active_support/core_ext/process/daemon.rb b/activesupport/lib/active_support/core_ext/process/daemon.rb new file mode 100644 index 0000000000..95ad5f8a5d --- /dev/null +++ b/activesupport/lib/active_support/core_ext/process/daemon.rb @@ -0,0 +1,25 @@ +if RUBY_VERSION < "1.9" + module Process + def self.daemon(nochdir = nil, noclose = nil) + exit if fork # Parent exits, child continues. + Process.setsid # Become session leader. + exit if fork # Zap session leader. See [1]. + + unless nochdir + Dir.chdir "/" # Release old working directory. + end + + File.umask 0000 # Ensure sensible umask. Adjust as needed. + + unless noclose + STDIN.reopen "/dev/null" # Free file descriptors and + STDOUT.reopen "/dev/null", "a" # point them somewhere sensible. + STDERR.reopen '/dev/null', 'a' + end + + trap("TERM") { exit } + + return 0 + end + end +end |