aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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