SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Where do I find the script invoked by script/server

    I've installed thin on my machine, but I want it to start up instead of Webrick when I type

    script/server

    at the console

    Any idea where to find it?

    I know this can be done, because once I install mongrel script/server invokes it instead of Webrick

  2. #2
    SitePoint Enthusiast AllTom's Avatar
    Join Date
    Feb 2008
    Location
    Wherever danger lies...
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't know, but I hunted it down. script/server basically just requires "commands/server" so I hunted that down: rails/railties/lib/commands/server.rb (which I have in vendor/ because I froze Rails; otherwise it's in your gem directory).

    That file just fumbles around, blindly requiring the fcgi and mongrel libraries. Then it checks command-line arguments, but if none were given, just uses the first of mongrel, lighttpd, and webrick which seem to be installed. Then it just requires the file in the servers/ subdirectory corresponding to the server that should load.

    It looks like you could just make a rails/railties/lib/commands/servers/thin.rb with a single line `thin start` (or be fancier if you want). Then you could run "script/server thin". If you fiddled with the server.rb you could make it the default, but I don't know of a way to do that which wouldn't be overridden the next time you update Rails.
    There are some things you shouldn't try to code at home.

  3. #3
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had just been screwing around with those files before you wrote.
    Depending on the version of rails you're running the file resides in
    C:\ruby\lib\ruby\gems\1.8\gems\rails-2.0.2\lib\commands

    I've edited it so it calls a thin.rb

    located in

    C:\ruby\lib\ruby\gems\1.8\gems\rails-2.0.2\lib\commands\servers

    but it doesn't work

    All I have in there is

    system("thin start")

  4. #4
    SitePoint Enthusiast AllTom's Avatar
    Join Date
    Feb 2008
    Location
    Wherever danger lies...
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What was your edit? Did you modify the line in server.rb that says

    Code Ruby:
    when "lighttpd", "mongrel", "webrick"

    to include "thin"? Or something else?
    There are some things you shouldn't try to code at home.

  5. #5
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes I did ... in fact here is my modified server.rb

    Code:
    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
      # Mongrel not available
    end
    
    server = case ARGV.first
      when "lighttpd", "mongrel", "webrick", "thin"
        ARGV.shift
      else
        if defined?(Mongrel)
          "mongrel"
        elsif defined?(Thin)
          "thin"
        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 "thin"
        puts "=> Booting Thin (use 'script/server webrick' to force WEBrick)"
      when "mongrel"
        puts "=> Booting Mongrel (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}"

  6. #6
    SitePoint Enthusiast AllTom's Avatar
    Join Date
    Feb 2008
    Location
    Wherever danger lies...
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And you're sure it's the server.rb that's getting used? I tried the same mod and it worked. Check that ./script/about shows the Rails version you expect; check that there's no Rails frozen in vendor.
    There are some things you shouldn't try to code at home.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •