This is ./script/lighttpd:
1 2 #!/usr/local/bin/ruby 3 4 require 'optparse' 5 6 OPTIONS = { 7 :port => 8000, 8 :ip => "0.0.0.0", 9 :daemon => false, 10 :environment => "development", 11 :app_name => "myapp", 12 } 13 14 ARGV.options do |opts| 15 script_name = File.basename($0) 16 opts.banner = "Usage: ruby #{script_name} [options]" 17 18 opts.separator "" 19 20 opts.on("-p", "--port=port", Integer, 21 "Runs Rails on the specified port.", 22 "Default: 3000") { |OPTIONS[:port]| } 23 opts.on("-b", "--binding=ip", String, 24 "Binds Rails to the specified ip.", 25 "Default: 0.0.0.0") { |OPTIONS[:ip]| } 26 opts.on("-e", "--environment=name", String, 27 "Specifies the environment to run this server under (test/development/production).", 28 "Default: development") { |OPTIONS[:environment]| } 29 opts.on("-a", "--app-name=name", String, 30 "Specifies the application name.", 31 "Default: rails_app") { |OPTIONS[:environment]| } 32 opts.on("-d", "--daemon", 33 "Make lighttpd / Rails run as a Daemon (only works if fork is available -- meaning on *nix)." 34 ) { OPTIONS[:daemon] = true } 35 36 opts.separator "" 37 38 opts.on("-h", "--help", 39 "Show this help message.") { puts opts; exit } 40 41 opts.parse! 42 end 43 44 ENV["RAILS_ENV"] = OPTIONS[:environment] 45 RAILS_ROOT = File.dirname(__FILE__) + "/../" 46 LIGHTTPD_CONF_FILE = "/tmp/#{OPTIONS[:app_name]}_lighttpd.conf" 47 48 File.open("#{RAILS_ROOT}config/lighttpd.conf", "r") do |file| 49 conf = file.read 50 conf.gsub!(/PORT/, OPTIONS[:port].to_s) 51 conf.gsub!(/BINDING/, OPTIONS[:ip]) 52 conf.gsub!(/RAILS_ROOT/, File.expand_path(RAILS_ROOT)) 53 conf.gsub!(/APP_NAME/, OPTIONS[:app_name]) 54 File.open(LIGHTTPD_CONF_FILE, "w") { |output| output.write(conf) } 55 end 56 57 CMD = "lighttpd -f #{LIGHTTPD_CONF_FILE}" 58 CMD << " -D" unless OPTIONS[:daemon] 59 puts CMD 60 `#{CMD}`
And this is ./config/lighttpd.conf
1 2 server.port = PORT 3 server.bind = "BINDING" 4 5 server.pid-file = "/tmp/APP_NAME_lighttpd.pid" 6 #server.event-handler = "freebsd-kqueue" 7 8 server.modules = ( "mod_rewrite", "mod_redirect", "mod_access", "mod_fastcgi", "mod_accesslog" ) 9 10 server.document-root = "RAILS_ROOT/public/" 11 server.indexfiles = ( "dispatch.fcgi", "index.html" ) 12 accesslog.filename = "RAILS_ROOT/log/lighttpd_access.log" 13 server.errorlog = "RAILS_ROOT/log/lighttpd_error.log" 14 server.error-handler-404 = "/dispatch.fcgi" 15 16 17 #### fastcgi module 18 ## read fastcgi.txt for more info 19 fastcgi.server = ( 20 ".fcgi" => ( 21 "APP_NAME" => ( 22 "socket" => "/tmp/APP_NAME1.socket", 23 "bin-path" => "RAILS_ROOT/public/dispatch.fcgi", 24 "min-procs" => 1, 25 "max_procs" => 2 26 ) 27 ) 28 ) 29 30 # mimetype mapping 31 mimetype.assign = ( 32 ".rpm" => "application/x-rpm", 33 ".pdf" => "application/pdf", 34 ".sig" => "application/pgp-signature", 35 ".spl" => "application/futuresplash", 36 ".class" => "application/octet-stream", 37 ".ps" => "application/postscript", 38 ".torrent" => "application/x-bittorrent", 39 ".dvi" => "application/x-dvi", 40 ".gz" => "application/x-gzip", 41 ".pac" => "application/x-ns-proxy-autoconfig", 42 ".swf" => "application/x-shockwave-flash", 43 ".tar.gz" => "application/x-tgz", 44 ".tgz" => "application/x-tgz", 45 ".tar" => "application/x-tar", 46 ".zip" => "application/zip", 47 ".mp3" => "audio/mpeg", 48 ".m3u" => "audio/x-mpegurl", 49 ".wma" => "audio/x-ms-wma", 50 ".wax" => "audio/x-ms-wax", 51 ".ogg" => "audio/x-wav", 52 ".wav" => "audio/x-wav", 53 ".gif" => "image/gif", 54 ".jpg" => "image/jpeg", 55 ".jpeg" => "image/jpeg", 56 ".png" => "image/png", 57 ".xbm" => "image/x-xbitmap", 58 ".xpm" => "image/x-xpixmap", 59 ".xwd" => "image/x-xwindowdump", 60 ".css" => "text/css", 61 ".html" => "text/html", 62 ".htm" => "text/html", 63 ".js" => "text/javascript", 64 ".asc" => "text/plain", 65 ".c" => "text/plain", 66 ".conf" => "text/plain", 67 ".text" => "text/plain", 68 ".txt" => "text/plain", 69 ".dtd" => "text/xml", 70 ".xml" => "text/xml", 71 ".mpeg" => "video/mpeg", 72 ".mpg" => "video/mpeg", 73 ".mov" => "video/quicktime", 74 ".qt" => "video/quicktime", 75 ".avi" => "video/x-msvideo", 76 ".asf" => "video/x-ms-asf", 77 ".asx" => "video/x-ms-asf", 78 ".wmv" => "video/x-ms-wmv", 79 ".bz2" => "application/x-bzip", 80 ".tbz" => "application/x-bzip-compressed-tar", 81 ".tar.bz2" => "application/x-bzip-compressed-tar" 82 )
From:
#!/usr/local/bin/ruby
To:
#!/usr/bin/env ruby