From 71318dab0d78199ce74092b5b9d3d736291cc6aa Mon Sep 17 00:00:00 2001 From: Bob Klosinski Date: Wed, 25 Jun 2008 16:40:00 -0500 Subject: [PATCH] added thin support --- railties/lib/commands/server.rb | 14 ++++++++++++-- railties/lib/commands/servers/thin.rb | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 railties/lib/commands/servers/thin.rb diff --git a/railties/lib/commands/server.rb b/railties/lib/commands/server.rb index 40ffdd1..7306c24 100644 --- a/railties/lib/commands/server.rb +++ b/railties/lib/commands/server.rb @@ -13,11 +13,19 @@ 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" + when "lighttpd", "mongrel", "new_mongrel", "webrick", "thin" ARGV.shift else - if defined?(Mongrel) + if defined?(Thin) + "thin" + elsif defined?(Mongrel) "mongrel" elsif RUBY_PLATFORM !~ /(:?mswin|mingw)/ && !silence_stderr { `lighttpd -version` }.blank? && defined?(FCGI) "lighttpd" @@ -33,6 +41,8 @@ case server 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)) } diff --git a/railties/lib/commands/servers/thin.rb b/railties/lib/commands/servers/thin.rb new file mode 100644 index 0000000..833469c --- /dev/null +++ b/railties/lib/commands/servers/thin.rb @@ -0,0 +1,25 @@ +require 'rbconfig' +require 'commands/servers/base' +require 'thin' + + +options = ARGV.clone +options.insert(0,'start') unless Thin::Runner.commands.include?(options[0]) + +thin = Thin::Runner.new(options) + +puts "=> Rails #{Rails.version} application starting on http://#{thin.options[:address]}:#{thin.options[:port]}" +puts "=> Ctrl-C to shutdown server" + +log = Pathname.new("#{File.expand_path(RAILS_ROOT)}/log/#{RAILS_ENV}.log").cleanpath +open(log, (File::WRONLY | File::APPEND | File::CREAT)) unless File.exist? log +tail_thread = tail(log) +trap(:INT) { exit } + +begin + thin.run! +ensure + tail_thread.kill if tail_thread + puts 'Exiting' +end + -- 1.5.5.4