Changeset 1426 for trunk/locker


Ignore:
Timestamp:
Jan 18, 2010, 2:24:22 AM (12 years ago)
Author:
mitchb
Message:
Deploy enhancements to Ruby on Rails autoinstaller
This pulls in changes which provide an easy knob for users to put
their apps into production mode (which was available in earlier versions
of RoR) and cause code changes to be picked up by the fcgi automatically
without having to kill processes on all our servers (code contributed
by Greg Brockman).
(Merge of r1297:1411 from branches/locker-dev to trunk)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/locker/deploy/bin/rails

    r1298 r1426  
    9090
    9191tie my @railsenv, 'Tie::File', 'config/environment.rb';
     92unshift @railsenv, "# ENV['RAILS_ENV'] ||= 'production'";
     93unshift @railsenv, "# Uncomment below to put Rails into production mode";
     94unshift @railsenv, "";
    9295unshift @railsenv, "ENV['RAILS_RELATIVE_URL_ROOT'] = \"/$addrend\"";
    9396untie @railsenv;
     
    111114untie @railswelcome;
    112115
     116tie my @railsfcgi, 'Tie::File', 'public/dispatch.fcgi';
     117for (@railsfcgi) {
     118    s/^[^#]*RailsFCGIHandler/## Commented out by scripts.mit.edu autoinstaller\n## RailsFCGIHandler/;
     119}
     120untie @railsfcgi;
     121open RAILSFCGI, ">>public/dispatch.fcgi";
     122print RAILSFCGI <<EOF;
     123
     124## Added by scripts.mit.edu autoinstaller to reload when app code changes
     125Thread.abort_on_exception = true
     126
     127t1 = Thread.new do
     128   RailsFCGIHandler.process!
     129end
     130
     131t2 = Thread.new do
     132   # List of directories to watch for changes before reload
     133   Thread.current[:watched_dirs] = ['app', 'config', 'db', 'lib', 'public']
     134   # Sample filter: /(\.rb|\.erb)\$/.  Default filter: watch all files
     135   Thread.current[:watched_extensions] = //
     136   # Iterations since last reload
     137   Thread.current[:iterations] = 0
     138
     139   def modified(file)
     140     begin
     141       mtime = File.stat(file).mtime
     142     rescue
     143       false
     144     else
     145       if Thread.current[:iterations] == 0
     146         Thread.current[:modifications][file] = mtime
     147       end
     148       Thread.current[:modifications][file] != mtime
     149     end
     150   end
     151
     152   # Don't symlink yourself into a loop.  Please.  Things will still work
     153   # (Linux limits your symlink depth) but you will be sad
     154   def modified_dir(dir)
     155     Dir.new(dir).each do |file|
     156       absfile = File.join(dir, file)
     157       if FileTest.directory? absfile
     158         next if file == '.' or file == '..'
     159         return true if modified_dir(absfile)
     160       else
     161         return true if Thread.current[:watched_extensions] =~ absfile &&
     162           modified(absfile)
     163       end
     164     end
     165     false
     166   end
     167
     168   def reload
     169     Thread.current[:modifications] = {}
     170     Thread.current[:iterations] = 0
     171     RailsFCGIHandler.reload!
     172   end
     173
     174   Thread.current[:modifications] = {}
     175   # Wait until the modify time changes, then reload.
     176   while true
     177     reload if Thread.current[:watched_dirs].inject(false) {|z, dir| z || modified_dir(File.join(File.dirname(__FILE__), '..', dir))}
     178     Thread.current[:iterations] += 1
     179     sleep 1
     180   end
     181end
     182
     183t1.join
     184t2.join
     185## End of scripts.mit.edu autoinstaller additions
     186EOF
     187
    113188print "Your application is located in:\n";
    114189print "  /mit/$USER/web_scripts/$addrend/\n";
Note: See TracChangeset for help on using the changeset viewer.