class RailsServer

Attributes

dir[RW]
env[RW]
verbose[RW]

Public Class Methods

new() click to toggle source
# File lib/rails-server.rb, line 4
def initialize
  @env = "production"
end

Public Instance Methods

run() click to toggle source

Tries to start a Rails server in the given directory.

# File lib/rails-server.rb, line 9
def run
  Dir.chdir(@dir) if @dir
  cmd = "rails server -e \"#{@env}\""
  
  if @verbose
    %x[#{cmd}]
  else
    require "php4r"
    Php4r.passthru(cmd)
  end
end
run_ensure() click to toggle source

Runs a Rails server if it is not running already.

# File lib/rails-server.rb, line 45
def run_ensure
  self.run unless self.running?
end
run_loop() click to toggle source

Tries to start a Rails server. Restarts if it crashes automatically with a small sleep.

# File lib/rails-server.rb, line 22
def run_loop
  loop do
    self.run
    sleep 0.5
  end
end
running?() click to toggle source

Returns true if the Rails server is running.

# File lib/rails-server.rb, line 30
def running?
  pid_path = "#{@dir}/tmp/pids/server.pid"
  return false unless File.exists?(pid_path)
  
  pid = File.read(pid_path).to_s.strip.to_i
  
  begin
    Process.getpgid(pid)
    return true
  rescue Errno::ESRCH
    return false
  end
end