aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-04-03 03:03:33 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-04-03 03:03:33 +0000
commitf966c279cfed64adefae7d220389b206e3abf3ca (patch)
tree785c166d925182b72bb8bb372c3e87546f5df8b3
parent0b167dd863c9d6795a3af1066afe16994a69ba16 (diff)
downloadrails-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
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/lib/commands/process/spawner.rb17
-rw-r--r--railties/lib/tasks/tmp.rake2
3 files changed, 18 insertions, 3 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index 02d003d789..4a26e968f1 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that spawner should daemonize if running in repeat mode [DHH]
+
* Added TAG option for rake rails:freeze:edge, so you can say rake rails:freeze:edge TAG=rel_1-1-0 to lock to the 1.1.0 release [DHH]
* Applied Prototype $() performance patches (#4465, #4477) and updated script.aculo.us [Sam Stephenson, Thomas Fuchs]
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
diff --git a/railties/lib/tasks/tmp.rake b/railties/lib/tasks/tmp.rake
index 643b67e6ec..6ba5b11450 100644
--- a/railties/lib/tasks/tmp.rake
+++ b/railties/lib/tasks/tmp.rake
@@ -22,7 +22,7 @@ namespace :tmp do
end
namespace :sockets do
- desc "Clears all ruby_sess.* files in tmp/sessions"
+ desc "Clears all files in tmp/sockets"
task :clear do
FileUtils.rm(Dir['tmp/sockets/[^.]*'])
end