diff options
author | zedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9> | 2006-02-12 03:37:38 +0000 |
---|---|---|
committer | zedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9> | 2006-02-12 03:37:38 +0000 |
commit | 67a0d9e93388093eb8fb05dd42655a90a832bc21 (patch) | |
tree | 741991a1fa25fb6ac0c72a0aa69ef3e898d67adc /bin | |
parent | 996d1046659b9d5991ce42f89bb5e9a0356f0cfd (diff) | |
download | unicorn-67a0d9e93388093eb8fb05dd42655a90a832bc21.tar.gz |
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@32 19e92222-5c0b-0410-8929-a290d50e31e9
Diffstat (limited to 'bin')
-rw-r--r-- | bin/mongrel_rails | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/bin/mongrel_rails b/bin/mongrel_rails index a184659..e94d855 100644 --- a/bin/mongrel_rails +++ b/bin/mongrel_rails @@ -83,6 +83,7 @@ class RailsHandler < Mongrel::HttpHandler end + class StartCommand < Mongrel::Command::Command def configure @@ -109,15 +110,16 @@ class StartCommand < Mongrel::Command::Command cwd = Dir.pwd if @daemon - STDERR.puts "Running as Daemon at #@address:#@port" + puts "Running as Daemon at #@address:#@port" Daemonize.daemonize(log_file=@log_file) open(File.join(cwd,@pid_file),"w") {|f| f.write(Process.pid) } # change back to the original starting directory Dir.chdir(cwd) else - STDERR.puts "Running at #@address:#@port" + puts "Running at #@address:#@port" end + ENV['RAILS_ENV'] = @environment require 'config/environment' h = Mongrel::HttpServer.new(@address, @port) @@ -127,8 +129,39 @@ class StartCommand < Mongrel::Command::Command begin h.acceptor.join rescue Interrupt - STDERR.puts "Interrupted." + puts "Interrupted." + end + end +end + + + +class StopCommand < Mongrel::Command::Command + + def configure + options [ + ["-d", "--daemonize", "Whether to run in the background or not", :@daemon, false], + ['-P', '--pid FILE', "Where to write the PID", :@pid_file, "log/mongrel.pid"] + ] + end + + def validate + valid_exists? @pid_file, "PID file #@pid_file does not exist. Not running?" + return @valid + end + + + def run + pid = open(@pid_file).read.to_i + print "Stopping Mongrel at PID #{pid}..." + begin + Process.kill("INT", pid) + rescue Errno::ESRCH + puts "Process does not exist. Not running." end + + File.unlink(@pid_file) + puts "Done." end end |