aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/commands/server.rb
blob: 7306c248fb3445647205561668125535678b523c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'active_support'
require 'fileutils'

begin
  require_library_or_gem 'fcgi'
rescue Exception
  # FCGI not available
end

begin
  require_library_or_gem 'mongrel'
rescue Exception
  # Mongrel not available
end

begin
  require_library_or_gem 'thin'
rescue Exception
  # Thin not available
end

server = case ARGV.first
  when "lighttpd", "mongrel", "new_mongrel", "webrick", "thin"
    ARGV.shift
  else
    if defined?(Thin)
      "thin"
    elsif defined?(Mongrel)
      "mongrel"
    elsif RUBY_PLATFORM !~ /(:?mswin|mingw)/ && !silence_stderr { `lighttpd -version` }.blank? && defined?(FCGI)
      "lighttpd"
    else
      "webrick"
    end
end

case server
  when "webrick"
    puts "=> Booting WEBrick..."
  when "lighttpd"
    puts "=> Booting lighttpd (use 'script/server webrick' to force WEBrick)"
  when "mongrel", "new_mongrel"
    puts "=> Booting Mongrel (use 'script/server webrick' to force WEBrick)"
  when "thin"
    puts "=> Booting Thin (use 'script/server webrick' to force WEBrick)"
end

%w(cache pids sessions sockets).each { |dir_to_make| FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make)) }
require "commands/servers/#{server}"