diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-04-03 03:03:33 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-04-03 03:03:33 +0000 |
commit | f966c279cfed64adefae7d220389b206e3abf3ca (patch) | |
tree | 785c166d925182b72bb8bb372c3e87546f5df8b3 /railties/lib/commands/process/spawner.rb | |
parent | 0b167dd863c9d6795a3af1066afe16994a69ba16 (diff) | |
download | rails-f966c279cfed64adefae7d220389b206e3abf3ca.tar.gz rails-f966c279cfed64adefae7d220389b206e3abf3ca.tar.bz2 rails-f966c279cfed64adefae7d220389b206e3abf3ca.zip |
Fixed that spawner should daemonize if running in repeat mode [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4135 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib/commands/process/spawner.rb')
-rw-r--r-- | railties/lib/commands/process/spawner.rb | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/railties/lib/commands/process/spawner.rb b/railties/lib/commands/process/spawner.rb index 47259979d6..c72a3dc489 100644 --- a/railties/lib/commands/process/spawner.rb +++ b/railties/lib/commands/process/spawner.rb @@ -1,6 +1,17 @@ require 'optparse' require 'socket' +def daemonize #:nodoc: + 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. +end + def spawn(port) print "Checking if something is already running on port #{port}..." begin @@ -71,10 +82,12 @@ end ENV["RAILS_ENV"] = OPTIONS[:environment] if OPTIONS[:repeat] + daemonize + trap("TERM") { exit } + loop do spawn_all - puts "Sleeping for #{OPTIONS[:repeat]} seconds" - sleep OPTIONS[:repeat] + sleep(OPTIONS[:repeat]) end else spawn_all |