Sha256: bd9f83778169538c498fcb235bfc7d7107bc63f79d1ddd25876a0f01c1d64df4

Contents?: true

Size: 1.83 KB

Versions: 15

Compression:

Stored size: 1.83 KB

Contents

require 'rbconfig'
require 'commands/servers/base'

unless defined?(Mongrel)
  puts "PROBLEM: Mongrel is not available on your system (or not in your path)"
  exit 1
end

require 'optparse'

OPTIONS = {
  :port        => 3000,
  :ip          => "0.0.0.0",
  :environment => (ENV['RAILS_ENV'] || "development").dup,
  :detach      => false
}

ARGV.clone.options do |opts|
  opts.on("-p", "--port=port", Integer, "Runs Rails on the specified port.", "Default: 3000") { |v| OPTIONS[:port] = v }
  opts.on("-b", "--binding=ip", String, "Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| OPTIONS[:ip] = v }
  opts.on("-d", "--daemon", "Make server run as a Daemon.") { OPTIONS[:detach] = true }
  opts.on("-e", "--environment=name", String,
          "Specifies the environment to run this server under (test/development/production).",
          "Default: development") { |v| OPTIONS[:environment] = v }

  opts.separator ""

  opts.on("-h", "--help", "Show this help message.") { puts opts; exit }

  opts.parse!
end

puts "=> Rails application starting on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"

parameters = [ 
  "start", 
  "-p", OPTIONS[:port].to_s, 
  "-a", OPTIONS[:ip].to_s, 
  "-e", OPTIONS[:environment],
  "-P", "#{RAILS_ROOT}/tmp/pids/mongrel.pid"
]

if OPTIONS[:detach]
  `mongrel_rails #{parameters.join(" ")} -d`
else
  ENV["RAILS_ENV"] = OPTIONS[:environment]
  RAILS_ENV.replace(OPTIONS[:environment]) if defined?(RAILS_ENV)

  require 'initializer'
  Rails::Initializer.run(:initialize_logger)

  puts "=> Call with -d to detach"
  puts "=> Ctrl-C to shutdown server"
  tail_thread = tail(Pathname.new("#{File.expand_path(RAILS_ROOT)}/log/#{RAILS_ENV}.log").cleanpath)

  trap(:INT) { exit }

  begin
    silence_warnings { ARGV = parameters }
    load("mongrel_rails")
  ensure
    tail_thread.kill if tail_thread
    puts 'Exiting'
  end
end

Version data entries

15 entries across 15 versions & 4 rubygems

Version Path
authorails-1.0.0 lib/commands/servers/mongrel.rb
radiant-0.6.1 vendor/rails/railties/lib/commands/servers/mongrel.rb
radiant-0.6.0 vendor/rails/railties/lib/commands/servers/mongrel.rb
radiant-0.6.3 vendor/rails/railties/lib/commands/servers/mongrel.rb
radiant-0.6.2 vendor/rails/railties/lib/commands/servers/mongrel.rb
radiant-0.6.4 vendor/rails/railties/lib/commands/servers/mongrel.rb
rails-1.2.0 lib/commands/servers/mongrel.rb
rails-1.2.1 lib/commands/servers/mongrel.rb
rails-1.2.4 lib/commands/servers/mongrel.rb
rails-1.2.5 lib/commands/servers/mongrel.rb
rails-1.2.2 lib/commands/servers/mongrel.rb
rails-1.2.3 lib/commands/servers/mongrel.rb
rails-1.2.6 lib/commands/servers/mongrel.rb
rq-3.4.0 rails/vendor/rails/railties/lib/commands/servers/mongrel.rb
rq-3.3.0 rails/vendor/rails/railties/lib/commands/servers/mongrel.rb