server 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/Users/dave/ruby1.8/bin/ruby
  2. require 'webrick'
  3. require 'optparse'
  4. OPTIONS = {
  5. :port => 3000,
  6. :ip => "0.0.0.0",
  7. :environment => "development",
  8. :server_root => File.expand_path(File.dirname(__FILE__) + "/../public/"),
  9. :server_type => WEBrick::SimpleServer
  10. }
  11. ARGV.options do |opts|
  12. script_name = File.basename($0)
  13. opts.banner = "Usage: ruby #{script_name} [options]"
  14. opts.separator ""
  15. opts.on("-p", "--port=port", Integer,
  16. "Runs Rails on the specified port.",
  17. "Default: 3000") { |OPTIONS[:port]| }
  18. opts.on("-b", "--binding=ip", String,
  19. "Binds Rails to the specified ip.",
  20. "Default: 0.0.0.0") { |OPTIONS[:ip]| }
  21. opts.on("-e", "--environment=name", String,
  22. "Specifies the environment to run this server under (test/development/production).",
  23. "Default: development") { |OPTIONS[:environment]| }
  24. opts.on("-d", "--daemon",
  25. "Make Rails run as a Daemon (only works if fork is available -- meaning on *nix)."
  26. ) { OPTIONS[:server_type] = WEBrick::Daemon }
  27. opts.separator ""
  28. opts.on("-h", "--help",
  29. "Show this help message.") { puts opts; exit }
  30. opts.parse!
  31. end
  32. ENV["RAILS_ENV"] = OPTIONS[:environment]
  33. require File.dirname(__FILE__) + "/../config/environment"
  34. require 'webrick_server'
  35. OPTIONS['working_directory'] = File.expand_path(RAILS_ROOT)
  36. puts "=> Rails application started on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
  37. DispatchServlet.dispatch(OPTIONS)