Changeset 2149 for branches/locker-dev


Ignore:
Timestamp:
Mar 24, 2012, 8:40:26 PM (12 years ago)
Author:
ezyang
Message:
Make Rails autoinstaller work with Rails 3:

- Rewrite the dispatcher we generate to work with Rack and rewrite
  paths appropriately
- Explicitly take a dependency on the 'fcgi' gem in the generated app's Gemfile
- Update invocation of 'rails' to new app generation syntax and semantics

Patch contributed by Adam Glasgall <glasgall@mit.edu>
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/locker-dev/locker/deploy/bin/rails

    r2124 r2149  
    55use onserver;
    66use Tie::File;
     7use Cwd;
    78
    89setup();
     
    3839my $prod_db = make_db("production");
    3940
    40 system qw{rails new . -D -d mysql };
     41my $cwd = getcwd;
     42system("rails", "new", $cwd ,"-d", "mysql");
     43my $appdir = `basename $cwd`;
     44chomp $appdir;
     45my $appclass = ucfirst $appdir;
    4146
    4247open PUBLIC_HTACCESS, ">public/.htaccess";
     
    120125untie @railsfcgi;
    121126open RAILSFCGI, ">>public/dispatch.fcgi";
     127print RAILSFCGI "#!/usr/bin/ruby\n";
    122128print RAILSFCGI <<EOF;
     129require File.join(File.dirname(__FILE__), '../config/environment')       
     130require 'rack'
    123131
    124132## Added by scripts.mit.edu autoinstaller to reload when app code changes
    125133Thread.abort_on_exception = true
    126134
     135class Rack::PathInfoRewriter
     136  def initialize(app)
     137    \@app = app
     138  end
     139
     140  def call(env)
     141    env["SCRIPT_NAME"] = ""
     142    parts = env['REQUEST_URI'].split('?')
     143    env['PATH_INFO'] = parts[0]
     144    env['QUERY_STRING'] = parts[1].to_s
     145    \@app.call(env)
     146  end
     147end
     148
     149
    127150t1 = Thread.new do
    128    RailsFCGIHandler.process!
     151  dispatch_logger = Logger.new(File.join(Rails.root,'log/dispatcher.log'))
     152
     153  begin
     154    Rack::Handler::FastCGI.run Rack::PathInfoRewriter.new(Rack::URLMap.new("/$appdir" => ${appclass}::Application))
     155  rescue => e
     156   dispatch_logger.error(e)
     157   raise e
     158  end
    129159end
    130 
    131160t2 = Thread.new do
    132161   # List of directories to watch for changes before reload.
     
    195224## End of scripts.mit.edu autoinstaller additions
    196225EOF
     226chmod 0755,'public/dispatch.fcgi';
     227
     228# have to explicitly take a dependency on fcgi
     229open GEMFILE, ">>Gemfile";
     230print GEMFILE "gem 'fcgi'\n";
     231close GEMFILE;
    197232
    198233print "Your application is located in:\n";
Note: See TracChangeset for help on using the changeset viewer.