Class: MongrelConsoleRunner
- Inherits:
-
Object
- Object
- MongrelConsoleRunner
- Defined in:
- lib/mongrel_console/console.rb
Instance Method Summary collapse
- #get(url = "/") ⇒ Object
-
#initialize ⇒ MongrelConsoleRunner
constructor
A new instance of MongrelConsoleRunner.
- #restart(port = @port, env = @env) ⇒ Object
- #start(port = @port, env = @env) ⇒ Object
- #status ⇒ Object
- #stop ⇒ Object
- #tail(file = "log/#{@env}.log") ⇒ Object
Constructor Details
#initialize ⇒ MongrelConsoleRunner
Returns a new instance of MongrelConsoleRunner.
17 18 19 20 |
# File 'lib/mongrel_console/console.rb', line 17 def initialize @port = 3000 @env = "development" end |
Instance Method Details
#get(url = "/") ⇒ Object
69 70 71 |
# File 'lib/mongrel_console/console.rb', line 69 def get(url="/") Net::HTTP.get("localhost", url, @port) end |
#restart(port = @port, env = @env) ⇒ Object
55 56 57 58 |
# File 'lib/mongrel_console/console.rb', line 55 def restart(port=@port, env=@env) stop start(port, env) end |
#start(port = @port, env = @env) ⇒ Object
47 48 49 |
# File 'lib/mongrel_console/console.rb', line 47 def start(port=@port, env=@env) `mongrel_rails start #{port} #{env} -d` end |
#status ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/mongrel_console/console.rb', line 60 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 |
#stop ⇒ Object
51 52 53 |
# File 'lib/mongrel_console/console.rb', line 51 def stop `mongrel_rails stop` end |
#tail(file = "log/#{@env}.log") ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mongrel_console/console.rb', line 22 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 end sleep 1 end end end trap("INT") { tail_thread.kill } tail_thread.join nil end |