mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added Ruby 1.8 implementation of Process.daemon
This commit is contained in:
parent
d75525b045
commit
3cffe92ff0
4 changed files with 30 additions and 10 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Added Ruby 1.8 implementation of Process.daemon
|
||||
|
||||
* Duration #since and #ago with no argument (e.g., 5.days.ago) return TimeWithZone when config.time_zone is set. Introducing Time.current, which returns Time.zone.now if config.time_zone is set, otherwise just returns Time.now [Geoff Buesing]
|
||||
|
||||
* Time#since behaves correctly when passed a Duration. Closes #11527 [kemiller]
|
||||
|
|
|
@ -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
|
||||
end
|
||||
|
|
1
activesupport/lib/active_support/core_ext/process.rb
Normal file
1
activesupport/lib/active_support/core_ext/process.rb
Normal file
|
@ -0,0 +1 @@
|
|||
require 'active_support/core_ext/process/daemon'
|
25
activesupport/lib/active_support/core_ext/process/daemon.rb
Normal file
25
activesupport/lib/active_support/core_ext/process/daemon.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue