mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
New console that works with the latest mongrel. Uses mongrel_rails and only works on Unix.
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@492 19e92222-5c0b-0410-8929-a290d50e31e9
This commit is contained in:
parent
c5bd2b62f6
commit
fd316c7948
3 changed files with 61 additions and 28 deletions
|
@ -15,7 +15,7 @@ setup_rdoc ['README', 'LICENSE', 'COPYING', 'lib/**/*.rb', 'doc/**/*.rdoc']
|
|||
desc "Does a full compile, test run"
|
||||
task :default => [:test, :package]
|
||||
|
||||
version="0.1"
|
||||
version="0.2"
|
||||
name="mongrel_console"
|
||||
|
||||
setup_gem(name, version) do |spec|
|
||||
|
|
|
@ -10,39 +10,74 @@ require 'mongrel/rails'
|
|||
require 'config/environment'
|
||||
require 'dispatcher'
|
||||
require 'mongrel/debug'
|
||||
require 'net/http'
|
||||
|
||||
$mongrel = RailsConfigurator.new :host => "localhost", :port => 3000, :environment => "development", :docroot => "public"
|
||||
class MongrelConsoleRunner
|
||||
|
||||
def self.mongrel
|
||||
return $mongrel
|
||||
end
|
||||
def initialize
|
||||
@port = 3000
|
||||
@env = "development"
|
||||
end
|
||||
|
||||
def tail(file="log/#{ENV['RAILS_ENV']}.log")
|
||||
STDERR.puts "Tailing #{file}. CTRL-C to stop it."
|
||||
def tail(file="log/#{@env}.log")
|
||||
STDERR.puts "Tailing #{file}. CTRL-C to stop it."
|
||||
|
||||
cursor = File.size(file)
|
||||
last_checked = Time.now
|
||||
tail_thread = Thread.new do
|
||||
File.open(file, 'r') do |f|
|
||||
loop do
|
||||
if f.mtime > last_checked
|
||||
f.seek cursor
|
||||
last_checked = f.mtime
|
||||
contents = f.read
|
||||
cursor += contents.length
|
||||
print contents
|
||||
cursor = File.size(file)
|
||||
last_checked = Time.now
|
||||
tail_thread = Thread.new do
|
||||
File.open(file, 'r') do |f|
|
||||
loop do
|
||||
if f.mtime > last_checked
|
||||
f.seek cursor
|
||||
last_checked = f.mtime
|
||||
contents = f.read
|
||||
cursor += contents.length
|
||||
print contents
|
||||
end
|
||||
sleep 1
|
||||
end
|
||||
sleep 1
|
||||
end
|
||||
end
|
||||
|
||||
trap("INT") { tail_thread.kill }
|
||||
tail_thread.join
|
||||
nil
|
||||
end
|
||||
|
||||
def start(port=@port, env=@env)
|
||||
`mongrel_rails start #{port} #{env} -d`
|
||||
end
|
||||
|
||||
def stop
|
||||
`mongrel_rails stop`
|
||||
end
|
||||
|
||||
def restart(port=@port, env=@env)
|
||||
stop
|
||||
start(port, env)
|
||||
end
|
||||
|
||||
def status
|
||||
if File.exist? "log/mongrel.pid"
|
||||
pid = open("log/mongrel.pid") {|f| f.read.to_i }
|
||||
puts "Running on port #@port in env #@env with PID #{pid}"
|
||||
else
|
||||
puts "Mongrel not running."
|
||||
end
|
||||
end
|
||||
|
||||
trap("INT") { tail_thread.kill }
|
||||
tail_thread.join
|
||||
nil
|
||||
def get(url="/")
|
||||
Net::HTTP.get("localhost", url, @port)
|
||||
end
|
||||
end
|
||||
|
||||
puts "Starting console. Mongrel Commands: start, stop, reload, restart, status, trace, tail"
|
||||
|
||||
$mongrel = MongrelConsoleRunner.new
|
||||
puts "Starting console. mongrel.[start | stop | restart | status | tail | get]"
|
||||
$mongrel.status
|
||||
|
||||
def self.mongrel
|
||||
$mongrel
|
||||
end
|
||||
|
||||
IRB.start(__FILE__)
|
||||
|
||||
|
|
|
@ -2,14 +2,13 @@ require 'rubygems'
|
|||
require 'gem_plugin'
|
||||
require 'mongrel'
|
||||
|
||||
|
||||
class Console < GemPlugin::Plugin "/commands"
|
||||
include Mongrel::Command::Base
|
||||
|
||||
def configure
|
||||
options [
|
||||
['-c', '--chdir DIR', "Change to directory before running", :@dir, "."]
|
||||
]
|
||||
['-c', '--chdir DIR', "Change to directory before running", :@dir, "."]
|
||||
]
|
||||
end
|
||||
|
||||
def validate
|
||||
|
@ -26,4 +25,3 @@ class Console < GemPlugin::Plugin "/commands"
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue