diff options
Diffstat (limited to 'railties/lib/commands/process')
-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 |