Skip to content
Browse files

new preflight repo

  • Loading branch information...
0 parents commit a3fd023985282fda592f84474357ca6a58470c90 Steve Conover committed Oct 3, 2011
Showing with 1,887 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 .rvmrc
  3. +1 −0 .wrong
  4. +6 −0 Gemfile
  5. +21 −0 Gemfile.lock
  6. +25 −0 README.markdown
  7. +149 −0 bin/preflight
  8. BIN gems/bundler-1.0.18.gem
  9. BIN gems/jruby-openssl-0.7.4.gem
  10. +70 −0 spec/basics_spec.rb
  11. +66 −0 spec/bundler_spec.rb
  12. +3 −0 spec/sample_projects/has_gems_via_bundler/Gemfile
  13. +11 −0 spec/sample_projects/has_gems_via_bundler/Gemfile.lock
  14. +14 −0 spec/sample_projects/has_gems_via_bundler/Rakefile
  15. +2 −0 spec/sample_projects/has_gems_via_bundler/config/preflight.yml
  16. 0 spec/sample_projects/has_gems_via_bundler/true}
  17. BIN spec/sample_projects/has_gems_via_bundler/vendor/cache/spruz-0.2.13.gem
  18. +29 −0 spec/sample_projects/no_dependencies/Rakefile
  19. +2 −0 spec/sample_projects/no_dependencies/config/preflight.yml
  20. +3 −0 spec/sample_projects/webapp/Gemfile
  21. +88 −0 spec/sample_projects/webapp/Gemfile.lock
  22. +5 −0 spec/sample_projects/webapp/app/controllers/application_controller.rb
  23. +4 −0 spec/sample_projects/webapp/config.ru
  24. +46 −0 spec/sample_projects/webapp/config/application.rb
  25. +6 −0 spec/sample_projects/webapp/config/boot.rb
  26. +5 −0 spec/sample_projects/webapp/config/environment.rb
  27. +25 −0 spec/sample_projects/webapp/config/environments/development.rb
  28. +35 −0 spec/sample_projects/webapp/config/environments/test.rb
  29. +7 −0 spec/sample_projects/webapp/config/initializers/secret_token.rb
  30. +5 −0 spec/sample_projects/webapp/config/preflight.yml
  31. +60 −0 spec/sample_projects/webapp/config/routes.rb
  32. +36 −0 spec/sample_projects/webapp/log/development.log
  33. +239 −0 spec/sample_projects/webapp/public/index.html
  34. +6 −0 spec/sample_projects/webapp/script/rails
  35. +45 −0 spec/spec_helper.rb
  36. +1 −0 spec/suite.rb
  37. +48 −0 spec/web_spec.rb
  38. +687 −0 web/jetty-init.erb
  39. +88 −0 web/jetty.xml
  40. +47 −0 web/web.xml.erb
1 .gitignore
@@ -0,0 +1 @@
+spec/local_mirror
1 .rvmrc
@@ -0,0 +1 @@
+rvm use ree-1.8.7@package --create
1 .wrong
@@ -0,0 +1 @@
+color
6 Gemfile
@@ -0,0 +1,6 @@
+source 'https://rubygems.org'
+
+group :test do
+ gem "rspec"
+ gem "open4"
+end
21 Gemfile.lock
@@ -0,0 +1,21 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ diff-lcs (1.1.3)
+ open4 (1.1.0)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.4)
+ rspec-expectations (2.6.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.6.0)
+
+PLATFORMS
+ java
+ ruby
+
+DEPENDENCIES
+ open4
+ rspec
25 README.markdown
@@ -0,0 +1,25 @@
+Preflight prepares your (j)ruby project for jvm deployment.
+
+1. Create config/preflight.yml in your project
+
+Example config/preflight.yml:
+
+ jruby: "http://mirrors.squareup.com/distfiles/jruby-complete-1.6.4.jar"
+ jetty: "http://mirrors.squareup.com/distfiles/jetty-hightide-7.4.5.v20110725.zip"
+ jruby-rack: "http://mirrors.squareup.com/distfiles/jruby-rack-1.0.10.jar"
+ app_user: finance
+ app_root: /usr/local/finance/finance
+
+2. Running:
+
+ <one day soon there will be a gem install>
+
+ preflight <your project directory>
+
+
+Of note, you'll now have:
+
+* a bin directory, with scripts that run ruby and rake, using jruby and with the gems defined in your project.
+* a vendor/jetty directory, containing everything necessary to run your app using jetty.
+ * You can try your app out by cd'ing into vendor/jetty and running RAILS_ENV=development java -jar start.jar
+ * vendor/jetty/jetty-init is an init script that starts your project. You should symlink /etc/init.d/<appuser>-jetty to this file, and then point monit at /etc/init.d/<appuser>-jetty
149 bin/preflight
@@ -0,0 +1,149 @@
+#!/usr/bin/ruby
+
+require "yaml"
+require "erb"
+require "fileutils"
+include FileUtils
+
+def halt(message)
+ $stderr.puts message
+ exit 1
+end
+
+def x!(cmd)
+ puts cmd if ENV['VERBOSE']
+ system(cmd) || halt("'#{cmd}' failed.")
+end
+
+
+halt("usage: preflight <project_path>") unless ARGV.length==1 && File.directory?(ARGV[0])
+
+@path_to_project = ARGV.shift
+@created = []
+
+config_file = File.join(@path_to_project, "config/preflight.yml")
+halt("#{config_file} not found") unless File.exists?(config_file)
+@preflight_config = YAML.load(ERB.new(File.read(config_file)).result)
+
+unless @preflight_config['jruby']
+ halt(%{Your config/preflight.yml must at least contain a pointer to the desired jruby-complete jar.
+Ex:
+
+jruby: http://jruby.org.s3.amazonaws.com/downloads/1.6.4/jruby-complete-1.6.4.jar
+jetty: http://dist.codehaus.org/jetty/jetty-hightide-7.4.5/jetty-hightide-7.4.5.v20110725.zip
+ })
+end
+
+script_start_time = Time.now
+
+@jruby_jar_file = "vendor/jruby.jar"
+@preflight_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
+
+@gem_home = File.expand_path(File.join(@preflight_config['app_root'], "/vendor/bundler_gem"))
+@gem_path = @gem_home + ":file:" + File.expand_path(File.join(@preflight_config['app_root'], @jruby_jar_file)) + "!/META-INF/jruby.home/lib/ruby/gems/1.8"
+
+def jruby!(cmd)
+ x! "cd #{@path_to_project} && java -client -jar #{@jruby_jar_file} #{cmd}"
+end
+
+def download(url, local_file)
+ x! "curl --silent --show-error -o #{local_file} #{url}"
+end
+
+def unzip(file, directory, pattern)
+ x! "unzip -qq #{file} #{pattern} -d #{directory}"
+end
+
+def install_bundler_gem
+ unless File.exists?("#{@path_to_project}/vendor/bundler_gem")
+ jruby! " -S gem install #{@preflight_dir}/gems/bundler-1.0.18.gem -i vendor/bundler_gem --no-rdoc --no-ri"
+ end
+ @created << "#{@path_to_project}/vendor/bundler_gem"
+end
+
+def bundle_install
+ install_bundler_gem
+ jruby! " -e 'require \"rubygems\"; require \"bundler\"; require \"bundler/cli\"; cli=Bundler::CLI.new; cli.options={:deployment=>true}; cli.install'"
+ @created << "#{@path_to_project}/vendor/bundle"
+end
+
+def write_script(script_path, contents)
+ File.open(script_path, "w+") { |f| f << contents }
+ chmod 0700, script_path
+ @created << script_path
+end
+
+def create_ruby_script(ruby_script_path)
+ write_script ruby_script_path, \
+%{#!/bin/bash
+
+cd $(dirname $0)/..
+GEM_HOME="#{@gem_home}" GEM_PATH="#{@gem_path}" java -client -jar #{@jruby_jar_file} $*
+}
+end
+
+def create_rake_script(ruby_script_path)
+ write_script ruby_script_path, \
+%{#!/bin/bash
+
+$(dirname $0)/ruby -S rake $* --trace
+}
+end
+
+def install_jetty(vendor_dir)
+ jetty_dir = File.join(vendor_dir, "jetty")
+ Dir["#{vendor_dir}/jett*"].to_a.each{|f|rm_rf(f)}
+ download @preflight_config['jetty'], File.join(vendor_dir, "jetty.zip")
+ unzip File.join(vendor_dir, "jetty.zip"), vendor_dir, '*/start.jar */lib/jetty*.jar */lib/servl*.jar'
+ rm File.join(vendor_dir, "jetty.zip")
+ mv Dir["#{vendor_dir}/jetty*"].to_a.first, jetty_dir
+ Dir[File.join(jetty_dir, "**/async-rest*")].each{|d|rm_rf(d)}
+ jetty_dir
+end
+
+def install_jruby_rack_jar(vendor_dir)
+ download @preflight_config['jruby-rack'], File.join(vendor_dir, "jruby-rack.jar")
+end
+
+def copy_jetty_xml(jetty_dir)
+ mkdir_p File.join(jetty_dir, "etc")
+ cp File.join(@preflight_dir, "web/jetty.xml"), File.join(jetty_dir, "etc")
+end
+
+def create_web_inf_subdirectory
+ mkdir_p File.join(@path_to_project, "WEB-INF")
+ web_xml_contents = ERB.new(File.read(File.join(@preflight_dir, "web/web.xml.erb"))).result(binding)
+ File.open(File.join(@path_to_project, "WEB-INF/web.xml"), "w+"){|f|f<<web_xml_contents}
+end
+
+def write_jetty_init_script(jetty_dir)
+ jetty_init_contents = ERB.new(File.read(File.join(@preflight_dir, "web/jetty-init.erb"))).result(binding)
+ write_script(File.join(jetty_dir, "jetty-init"), jetty_init_contents)
+end
+
+ruby_script_path = File.join(@path_to_project, "bin/ruby")
+rake_script_path = File.join(@path_to_project, "bin/rake")
+bin_dir = File.join(@path_to_project, "bin")
+vendor_dir = File.join(@path_to_project, "vendor")
+
+mkdir_p File.join(@path_to_project, "bin")
+mkdir_p File.join(@path_to_project, "vendor")
+download @preflight_config['jruby'], File.join(@path_to_project, @jruby_jar_file)
+create_ruby_script ruby_script_path
+create_rake_script rake_script_path
+bundle_install if File.exists?(File.join(@path_to_project, "Gemfile.lock"))
+if @preflight_config['jetty']
+ jetty_dir = install_jetty(vendor_dir)
+ install_jruby_rack_jar vendor_dir #raise if jar not found
+ copy_jetty_xml jetty_dir
+ write_jetty_init_script jetty_dir #raise if app_user isn't specified in config
+
+ create_web_inf_subdirectory
+end
+
+elapsed_seconds = (Time.now - script_start_time).to_i
+
+puts %{Created:
+ #{@created.join("\n ")}
+Time: #{elapsed_seconds} s
+}
BIN gems/bundler-1.0.18.gem
Binary file not shown.
BIN gems/jruby-openssl-0.7.4.gem
Binary file not shown.
70 spec/basics_spec.rb
@@ -0,0 +1,70 @@
+require "spec_helper"
+
+describe "preflight - basics" do
+ before(:all) do
+ reset
+ @result = x!("bin/preflight spec/sample_projects/no_dependencies")
+ end
+ after(:all) do
+ reset
+ end
+
+ it "will put the jruby jar under vendor" do
+ @result[:stderr].should == ""
+ @result[:exitstatus].should == 0
+ File.exists?("spec/sample_projects/no_dependencies/vendor/jruby.jar").should == true
+ end
+
+ it "creates a rake script" do
+ @result[:stdout].should include("spec/sample_projects/no_dependencies/bin/rake\n")
+ File.exists?("spec/sample_projects/no_dependencies/bin/rake").should == true
+ end
+
+ describe "creates a ruby script that" do
+ it "allows you to execute using the jruby jar." do
+ rake_result = x("spec/sample_projects/no_dependencies/bin/ruby -S rake project_info")
+ rake_result[:stderr].should == ""
+ rake_result[:stdout].should include("Hi, I'm the no_dependencies project")
+ rake_result[:exitstatus].should == 0
+ end
+ end
+
+ describe "makes a rake script that" do
+ it %{ - runs from any directory (properly cd's)
+ - the ruby used is indeed jruby
+ - allows you to execute several tasks in a row
+ - shows the trace of a rake failure
+ - nails the GEM_PATH to within the jar so we don't go 'accidentally' loading gems and such from another ruby env, the result of which is insanity.
+
+ Asserting all this in one test to optimize for test running time.} do
+ absolute_script_path = File.expand_path("spec/sample_projects/no_dependencies/bin/rake project_info another_task load_path gem_path boom")
+ rake_result = x("cd /tmp && #{absolute_script_path} project_info")
+
+ rake_result[:stdout].should include("PWD=#{File.expand_path("spec/sample_projects/no_dependencies")}")
+ rake_result[:stdout].should include("Hi, I'm the no_dependencies project")
+ rake_result[:stdout].should include("RUBY_PLATFORM=java")
+ rake_result[:stdout].should include("jruby.jar!/META-INF")
+ rake_result[:stdout].should include("You ran another task")
+
+ rake_result[:stderr].should include("BOOM")
+ rake_result[:stderr].should include("xxx")
+ rake_result[:stderr].should include("yyy")
+ rake_result[:stderr].should include("zzz")
+ rake_result[:exitstatus].should == 1
+
+ load_path_elements = rake_result[:stdout].split("\n").select{|line|line =~ /^LP--/}
+ load_path_elements.length >= 3
+ load_path_elements.each do |element|
+ element = element.sub("LP-- ", "")
+ (element =~ /META-INF\/jruby\.home/ || element =~ /^\.$/).should >= 0
+ end
+
+ gem_path_elements = rake_result[:stdout].split("\n").select{|line|line =~ /^GP--/}
+ gem_path_elements.length >= 2
+ gem_path_elements.each do |element|
+ element = element.sub("GP-- ", "")
+ (element =~ /META-INF\/jruby\.home/ || element =~ /vendor\/bundler_gem/).should >= 0
+ end
+ end
+ end
+end
66 spec/bundler_spec.rb
@@ -0,0 +1,66 @@
+require "spec_helper"
+
+describe "preflight - bundler and gems" do
+
+ before(:all) do
+ reset
+ rm_rf("spec/sample_projects/has_gems_via_bundler/vendor/bundle")
+ rm_rf("spec/sample_projects/has_gems_via_bundler/vendor/bundler_gem")
+ x!("bin/preflight spec/sample_projects/has_gems_via_bundler")
+ end
+
+ after(:all) do
+ rm_rf("spec/sample_projects/has_gems_via_bundler/vendor/bundle")
+ rm_rf("spec/sample_projects/has_gems_via_bundler/vendor/bundler_gem")
+ end
+
+ describe "presence of the library" do
+ it "installed bundler into vendor/bundler_gem." do
+ files = Dir["spec/sample_projects/has_gems_via_bundler/vendor/bundler_gem/**/*.rb"].to_a.map{|f|File.basename(f)}
+ files.should include("bundler.rb")
+ files.should include("dsl.rb")
+ end
+
+ it "is not accidentally using bundler from another ruby environment." do
+ rake_result = x("spec/sample_projects/has_gems_via_bundler/bin/rake load_path_with_bundler")
+ load_path_elements = rake_result[:stdout].split("\n").select{|line|line =~ /^--/}
+ load_path_elements.length.should >= 3
+ load_path_elements.each do |element|
+ element = element.sub("-- ", "")
+ (element =~ /META-INF\/jruby\.home/ || element =~ /vendor\/bundler_gem/ || element =~ /^\.$/).should >= 0
+ end
+ end
+
+ it "can be used from a script fed to jruby." do
+ rake_result = x(%{echo 'require \\"rubygems\\"; require \\"bundler\\"; puts Bundler::VERSION' | spec/sample_projects/has_gems_via_bundler/bin/ruby})
+ rake_result[:stderr].should == ""
+ rake_result[:stdout].should include("1.0.18")
+ rake_result[:exitstatus].should == 0
+ end
+ end
+
+ describe "gem installation" do
+ it "installs gems into vendor/bundle" do
+ files = Dir["spec/sample_projects/has_gems_via_bundler/vendor/bundle/**/*.rb"].to_a.map{|f|File.basename(f)}
+ files.should include("bijection.rb")
+ files.should include("spruz.rb")
+ files.length.should > 20
+ end
+
+ it "installed gems are available via normal require" do
+ rake_result = x("cd spec/sample_projects/has_gems_via_bundler && " +
+ %{echo 'require \\"rubygems\\"; require \\"bundler/setup\\"; require \\"spruz/bijection\\"; puts Spruz::Bijection.name' | bin/ruby})
+ rake_result[:stderr].should == ""
+ rake_result[:stdout].should == "Spruz::Bijection\n"
+ rake_result[:exitstatus].should == 0
+ end
+
+ it "installed gems are available via Bundler.require" do
+ rake_result = x("cd spec/sample_projects/has_gems_via_bundler && " +
+ %{echo 'require \\"rubygems\\"; require \\"bundler\\"; Bundler.require; puts Spruz::Bijection.name' | bin/ruby})
+ rake_result[:stderr].should == ""
+ rake_result[:stdout].should == "Spruz::Bijection\n"
+ rake_result[:exitstatus].should == 0
+ end
+ end
+end
3 spec/sample_projects/has_gems_via_bundler/Gemfile
@@ -0,0 +1,3 @@
+source 'http://rubygems.org'
+
+gem "spruz"
11 spec/sample_projects/has_gems_via_bundler/Gemfile.lock
@@ -0,0 +1,11 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ spruz (0.2.13)
+
+PLATFORMS
+ java
+ ruby
+
+DEPENDENCIES
+ spruz
14 spec/sample_projects/has_gems_via_bundler/Rakefile
@@ -0,0 +1,14 @@
+task :load_path do
+ puts $LOAD_PATH.join("\n")
+end
+
+task :load_path_with_rubygems do
+ require "rubygems"
+ puts $LOAD_PATH.join("\n")
+end
+
+task :load_path_with_bundler do
+ require "rubygems"
+ require "bundler"
+ $LOAD_PATH.each{|path|puts "-- #{path}"}
+end
2 spec/sample_projects/has_gems_via_bundler/config/preflight.yml
@@ -0,0 +1,2 @@
+jruby: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-complete-1.6.4.jar"
+app_root: <%= File.expand_path('spec/sample_projects/has_gems_via_bundler') %>
0 spec/sample_projects/has_gems_via_bundler/true}
No changes.
BIN spec/sample_projects/has_gems_via_bundler/vendor/cache/spruz-0.2.13.gem
Binary file not shown.
29 spec/sample_projects/no_dependencies/Rakefile
@@ -0,0 +1,29 @@
+task :project_info do
+ require "fileutils"
+
+ puts "Hi, I'm the no_dependencies project"
+ puts "RUBY_PLATFORM=#{RUBY_PLATFORM}"
+ puts "LOAD_PATH=#{$LOAD_PATH.join("\n")}"
+ puts "PWD=#{FileUtils.pwd}"
+end
+
+task :another_task do
+ puts "You ran another task"
+end
+
+def zzz; yyy end
+def yyy; xxx end
+def xxx; raise "BOOM" end
+
+task :boom do
+ zzz
+end
+
+task :load_path do
+ $LOAD_PATH.each{|path|puts "LP-- #{path}"}
+end
+
+task :gem_path do
+ require "rubygems"
+ Gem.path.each{|path|puts "GP-- #{path}"}
+end
2 spec/sample_projects/no_dependencies/config/preflight.yml
@@ -0,0 +1,2 @@
+jruby: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-complete-1.6.4.jar"
+app_root: <%= File.expand_path('spec/sample_projects/no_dependencies') %>
3 spec/sample_projects/webapp/Gemfile
@@ -0,0 +1,3 @@
+source 'http://rubygems.org'
+
+gem "rails"
88 spec/sample_projects/webapp/Gemfile.lock
@@ -0,0 +1,88 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (3.1.0)
+ actionpack (= 3.1.0)
+ mail (~> 2.3.0)
+ actionpack (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ i18n (~> 0.6)
+ rack (~> 1.3.2)
+ rack-cache (~> 1.0.3)
+ rack-mount (~> 0.8.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.0.0)
+ activemodel (3.1.0)
+ activesupport (= 3.1.0)
+ bcrypt-ruby (~> 3.0.0)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activerecord (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
+ arel (~> 2.2.1)
+ tzinfo (~> 0.3.29)
+ activeresource (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
+ activesupport (3.1.0)
+ multi_json (~> 1.0)
+ arel (2.2.1)
+ bcrypt-ruby (3.0.1)
+ builder (3.0.0)
+ erubis (2.7.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ mail (2.3.0)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ multi_json (1.0.3)
+ polyglot (0.3.2)
+ rack (1.3.4)
+ rack-cache (1.0.3)
+ rack (>= 0.4)
+ rack-mount (0.8.3)
+ rack (>= 1.0.0)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.1.0)
+ actionmailer (= 3.1.0)
+ actionpack (= 3.1.0)
+ activerecord (= 3.1.0)
+ activeresource (= 3.1.0)
+ activesupport (= 3.1.0)
+ bundler (~> 1.0)
+ railties (= 3.1.0)
+ railties (3.1.0)
+ actionpack (= 3.1.0)
+ activesupport (= 3.1.0)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2)
+ rdoc (3.9.4)
+ sprockets (2.0.1)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.30)
+
+PLATFORMS
+ java
+ ruby
+
+DEPENDENCIES
+ rails
5 spec/sample_projects/webapp/app/controllers/application_controller.rb
@@ -0,0 +1,5 @@
+class ApplicationController < ActionController::Base
+ def hello
+ render :text => "Hello World<br/>LOAD_PATH:#{$LOAD_PATH}<br/>Gem.path:#{Gem.path}"
+ end
+end
4 spec/sample_projects/webapp/config.ru
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Foo::Application
46 spec/sample_projects/webapp/config/application.rb
@@ -0,0 +1,46 @@
+require File.expand_path('../boot', __FILE__)
+
+# require “active_record/railtie”
+require "action_controller/railtie"
+require "action_mailer/railtie"
+require "active_resource/railtie"
+require "rails/test_unit/railtie"
+
+# If you have a Gemfile, require the gems listed there, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(:default, Rails.env) if defined?(Bundler)
+
+module Foo
+ class Application < Rails::Application
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Custom directories with classes and modules you want to be autoloadable.
+ # config.autoload_paths += %W(#{config.root}/extras)
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named.
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Activate observers that should always be running.
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
+ # config.time_zone = 'Central Time (US & Canada)'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+ # config.i18n.default_locale = :de
+
+ # JavaScript files you want as :defaults (application.js is always included).
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
+
+ # Configure the default encoding used in templates for Ruby 1.9.
+ config.encoding = "utf-8"
+
+ # Configure sensitive parameters which will be filtered from the log file.
+ config.filter_parameters += [:password]
+ end
+end
6 spec/sample_projects/webapp/config/boot.rb
@@ -0,0 +1,6 @@
+require 'rubygems'
+
+# Set up gems listed in the Gemfile.
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+
+require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
5 spec/sample_projects/webapp/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Foo::Application.initialize!
25 spec/sample_projects/webapp/config/environments/development.rb
@@ -0,0 +1,25 @@
+Foo::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the webserver when you make code changes.
+ config.cache_classes = false
+
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Don't care if the mailer can't send
+ config.action_mailer.raise_delivery_errors = false
+
+ # Print deprecation notices to the Rails logger
+ config.active_support.deprecation = :log
+
+ # Only use best-standards-support built into browsers
+ config.action_dispatch.best_standards_support = :builtin
+end
+
35 spec/sample_projects/webapp/config/environments/test.rb
@@ -0,0 +1,35 @@
+Foo::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+ config.cache_classes = true
+
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Raise exceptions instead of rendering exception templates
+ config.action_dispatch.show_exceptions = false
+
+ # Disable request forgery protection in test environment
+ config.action_controller.allow_forgery_protection = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
+ # like if you have constraints or database-specific column types
+ # config.active_record.schema_format = :sql
+
+ # Print deprecation notices to the stderr
+ config.active_support.deprecation = :stderr
+end
7 spec/sample_projects/webapp/config/initializers/secret_token.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# Your secret key for verifying the integrity of signed cookies.
+# If you change this key, all old signed cookies will become invalid!
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+Foo::Application.config.secret_token = '9197ec11ccabc88f4e58933d89215efb83096cfc750bca8411096d7cbbb4f4049aa691c8887289391b0ad084d91d5507ebeef78f9d205d3c2532ad31d30c2d68'
5 spec/sample_projects/webapp/config/preflight.yml
@@ -0,0 +1,5 @@
+jruby: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-complete-1.6.4.jar"
+jetty: "file://<%= File.expand_path('spec/local_mirror') %>/jetty-hightide-7.4.5.v20110725.zip"
+jruby-rack: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-rack-1.0.10.jar"
+app_user: finance
+app_root: <%= File.expand_path('spec/sample_projects/webapp') %>
60 spec/sample_projects/webapp/config/routes.rb
@@ -0,0 +1,60 @@
+Foo::Application.routes.draw do
+ match 'hello' => 'application#hello'
+
+ # The priority is based upon order of creation:
+ # first created -> highest priority.
+
+ # Sample of regular route:
+ # match 'products/:id' => 'catalog#view'
+ # Keep in mind you can assign values other than :controller and :action
+
+ # Sample of named route:
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
+ # This route can be invoked with purchase_url(:id => product.id)
+
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
+ # resources :products
+
+ # Sample resource route with options:
+ # resources :products do
+ # member do
+ # get 'short'
+ # post 'toggle'
+ # end
+ #
+ # collection do
+ # get 'sold'
+ # end
+ # end
+
+ # Sample resource route with sub-resources:
+ # resources :products do
+ # resources :comments, :sales
+ # resource :seller
+ # end
+
+ # Sample resource route with more complex sub-resources
+ # resources :products do
+ # resources :comments
+ # resources :sales do
+ # get 'recent', :on => :collection
+ # end
+ # end
+
+ # Sample resource route within a namespace:
+ # namespace :admin do
+ # # Directs /admin/products/* to Admin::ProductsController
+ # # (app/controllers/admin/products_controller.rb)
+ # resources :products
+ # end
+
+ # You can have the root of your site routed with "root"
+ # just remember to delete public/index.html.
+ # root :to => "welcome#index"
+
+ # See how all your routes lay out with "rake routes"
+
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
+ # Note: This route will make all actions in every controller accessible via GET requests.
+ # match ':controller(/:action(/:id(.:format)))'
+end
36 spec/sample_projects/webapp/log/development.log
@@ -0,0 +1,36 @@
+DEPRECATION WARNING: config.action_view.debug_rjs will be removed in 3.1, from 3.1 onwards you will need to install prototype-rails to continue to use RJS templates . (called from service at /Users/steve/.rvm/rubies/jruby-1.6.3/lib/ruby/1.8/webrick/httpserver.rb:104)
+
+
+Started GET "/hello" for 127.0.0.1 at Sun Oct 02 20:07:39 -0700 2011
+
+ArgumentError (A secret is required to generate an integrity hash for cookie session data. Use config.secret_token = "some secret phrase of at least 30 characters"in config/initializers/secret_token.rb):
+
+
+Rendered /Users/steve/.rvm/gems/jruby-1.6.3@finance/gems/actionpack-3.0.9/lib/action_dispatch/middleware/templates/rescues/_trace.erb (5.0ms)
+Rendered /Users/steve/.rvm/gems/jruby-1.6.3@finance/gems/actionpack-3.0.9/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (18.0ms)
+Rendered /Users/steve/.rvm/gems/jruby-1.6.3@finance/gems/actionpack-3.0.9/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (43.0ms)
+
+
+Started GET "/favicon.ico" for 127.0.0.1 at Sun Oct 02 20:07:40 -0700 2011
+
+ArgumentError (A secret is required to generate an integrity hash for cookie session data. Use config.secret_token = "some secret phrase of at least 30 characters"in config/initializers/secret_token.rb):
+
+
+Rendered /Users/steve/.rvm/gems/jruby-1.6.3@finance/gems/actionpack-3.0.9/lib/action_dispatch/middleware/templates/rescues/_trace.erb (20.0ms)
+Rendered /Users/steve/.rvm/gems/jruby-1.6.3@finance/gems/actionpack-3.0.9/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (8.0ms)
+Rendered /Users/steve/.rvm/gems/jruby-1.6.3@finance/gems/actionpack-3.0.9/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (40.0ms)
+DEPRECATION WARNING: config.action_view.debug_rjs will be removed in 3.1, from 3.1 onwards you will need to install prototype-rails to continue to use RJS templates . (called from service at /Users/steve/.rvm/rubies/jruby-1.6.3/lib/ruby/1.8/webrick/httpserver.rb:104)
+
+
+Started GET "/hello" for 127.0.0.1 at Sun Oct 02 20:24:56 -0700 2011
+ Processing by ApplicationController#hello as HTML
+Rendered text template (0.0ms)
+Completed 200 OK in 16ms (Views: 15.0ms)
+
+
+Started GET "/favicon.ico" for 127.0.0.1 at Sun Oct 02 20:24:57 -0700 2011
+
+ActionController::RoutingError (No route matches "/favicon.ico"):
+
+
+Rendered /Users/steve/.rvm/gems/jruby-1.6.3@finance/gems/actionpack-3.0.9/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (7.0ms)
239 spec/sample_projects/webapp/public/index.html
@@ -0,0 +1,239 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Ruby on Rails: Welcome aboard</title>
+ <style type="text/css" media="screen">
+ body {
+ margin: 0;
+ margin-bottom: 25px;
+ padding: 0;
+ background-color: #f0f0f0;
+ font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
+ font-size: 13px;
+ color: #333;
+ }
+
+ h1 {
+ font-size: 28px;
+ color: #000;
+ }
+
+ a {color: #03c}
+ a:hover {
+ background-color: #03c;
+ color: white;
+ text-decoration: none;
+ }
+
+
+ #page {
+ background-color: #f0f0f0;
+ width: 750px;
+ margin: 0;
+ margin-left: auto;
+ margin-right: auto;
+ }
+
+ #content {
+ float: left;
+ background-color: white;
+ border: 3px solid #aaa;
+ border-top: none;
+ padding: 25px;
+ width: 500px;
+ }
+
+ #sidebar {
+ float: right;
+ width: 175px;
+ }
+
+ #footer {
+ clear: both;
+ }
+
+
+ #header, #about, #getting-started {
+ padding-left: 75px;
+ padding-right: 30px;
+ }
+
+
+ #header {
+ background-image: url("images/rails.png");
+ background-repeat: no-repeat;
+ background-position: top left;
+ height: 64px;
+ }
+ #header h1, #header h2 {margin: 0}
+ #header h2 {
+ color: #888;
+ font-weight: normal;
+ font-size: 16px;
+ }
+
+
+ #about h3 {
+ margin: 0;
+ margin-bottom: 10px;
+ font-size: 14px;
+ }
+
+ #about-content {
+ background-color: #ffd;
+ border: 1px solid #fc0;
+ margin-left: -55px;
+ margin-right: -10px;
+ }
+ #about-content table {
+ margin-top: 10px;
+ margin-bottom: 10px;
+ font-size: 11px;
+ border-collapse: collapse;
+ }
+ #about-content td {
+ padding: 10px;
+ padding-top: 3px;
+ padding-bottom: 3px;
+ }
+ #about-content td.name {color: #555}
+ #about-content td.value {color: #000}
+
+ #about-content ul {
+ padding: 0;
+ list-style-type: none;
+ }
+
+ #about-content.failure {
+ background-color: #fcc;
+ border: 1px solid #f00;
+ }
+ #about-content.failure p {
+ margin: 0;
+ padding: 10px;
+ }
+
+
+ #getting-started {
+ border-top: 1px solid #ccc;
+ margin-top: 25px;
+ padding-top: 15px;
+ }
+ #getting-started h1 {
+ margin: 0;
+ font-size: 20px;
+ }
+ #getting-started h2 {
+ margin: 0;
+ font-size: 14px;
+ font-weight: normal;
+ color: #333;
+ margin-bottom: 25px;
+ }
+ #getting-started ol {
+ margin-left: 0;
+ padding-left: 0;
+ }
+ #getting-started li {
+ font-size: 18px;
+ color: #888;
+ margin-bottom: 25px;
+ }
+ #getting-started li h2 {
+ margin: 0;
+ font-weight: normal;
+ font-size: 18px;
+ color: #333;
+ }
+ #getting-started li p {
+ color: #555;
+ font-size: 13px;
+ }
+
+
+ #sidebar ul {
+ margin-left: 0;
+ padding-left: 0;
+ }
+ #sidebar ul h3 {
+ margin-top: 25px;
+ font-size: 16px;
+ padding-bottom: 10px;
+ border-bottom: 1px solid #ccc;
+ }
+ #sidebar li {
+ list-style-type: none;
+ }
+ #sidebar ul.links li {
+ margin-bottom: 5px;
+ }
+
+ </style>
+ <script type="text/javascript">
+ function about() {
+ info = document.getElementById('about-content');
+ if (window.XMLHttpRequest)
+ { xhr = new XMLHttpRequest(); }
+ else
+ { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
+ xhr.open("GET","rails/info/properties",false);
+ xhr.send("");
+ info.innerHTML = xhr.responseText;
+ info.style.display = 'block'
+ }
+ </script>
+ </head>
+ <body>
+ <div id="page">
+ <div id="sidebar">
+ <ul id="sidebar-items">
+ <li>
+ <h3>Browse the documentation</h3>
+ <ul class="links">
+ <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
+ <li><a href="http://stdlib.rubyonrails.org/">Ruby standard library</a></li>
+ <li><a href="http://corelib.rubyonrails.org/">Ruby core</a></li>
+ <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
+ </ul>
+ </li>
+ </ul>
+ </div>
+
+ <div id="content">
+ <div id="header">
+ <h1>Welcome aboard</h1>
+ <h2>You&rsquo;re riding Ruby on Rails!</h2>
+ </div>
+
+ <div id="about">
+ <h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
+ <div id="about-content" style="display: none"></div>
+ </div>
+
+ <div id="getting-started">
+ <h1>Getting started</h1>
+ <h2>Here&rsquo;s how to get rolling:</h2>
+
+ <ol>
+ <li>
+ <h2>Use <code>rails generate</code> to create your models and controllers</h2>
+ <p>To see all available options, run it without parameters.</p>
+ </li>
+
+ <li>
+ <h2>Set up a default route and remove or rename this file</h2>
+ <p>Routes are set up in config/routes.rb.</p>
+ </li>
+
+ <li>
+ <h2>Create your database</h2>
+ <p>Run <code>rake db:migrate</code> to create your database. If you're not using SQLite (the default), edit <code>config/database.yml</code> with your username and password.</p>
+ </li>
+ </ol>
+ </div>
+ </div>
+
+ <div id="footer">&nbsp;</div>
+ </div>
+ </body>
+</html>
6 spec/sample_projects/webapp/script/rails
@@ -0,0 +1,6 @@
+#!/usr/bin/env jruby
+# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
+
+APP_PATH = File.expand_path('../../config/application', __FILE__)
+require File.expand_path('../../config/boot', __FILE__)
+require 'rails/commands'
45 spec/spec_helper.rb
@@ -0,0 +1,45 @@
+require "fileutils"
+require "open4"
+require "net/http"
+
+include FileUtils
+
+
+def x(cmd)
+ stdout = StringIO.new
+ stderr = StringIO.new
+ result = Open4::spawn("sh -c \"#{cmd}\"", 'raise' => false, 'quiet' => true, 'stdout' => stdout, 'stderr' => stderr)
+ exitstatus = result ? result.exitstatus : nil
+ {:exitstatus => exitstatus, :stdout => stdout.string, :stderr => stderr.string}
+end
+
+def x!(cmd)
+ result = x(cmd)
+ raise "#{cmd} failed: #{result[:stderr]}" unless result[:exitstatus] == 0
+ return result
+end
+
+unless File.directory?("spec/local_mirror")
+ mkdir_p "spec/local_mirror"
+ %w(jetty-hightide-7.4.5.v20110725.zip jruby-complete-1.6.4.jar jruby-rack-1.0.10.jar).each do |file|
+ x! "curl --silent --show-error -o spec/local_mirror/#{file} http://mirrors.squareup.com/distfiles/#{file}"
+ end
+end
+
+def reset
+ Dir["spec/sample_projects/*/vendor/bundle"].each{|d|FileUtils.rm_rf(d)}
+ Dir["spec/sample_projects/*/vendor/bundler_gem"].each{|d|FileUtils.rm_rf(d)}
+ Dir["spec/sample_projects/*/*.jar"].each{|f|FileUtils.rm(f)}
+ Dir["spec/sample_projects/*/.bundle"].each{|d|FileUtils.rm_rf(d)}
+ Dir["spec/sample_projects/*/bin"].each{|d|FileUtils.rm_rf(d)}
+ Dir["spec/sample_projects/*/vendor/jruby.jar"].each{|f|FileUtils.rm_f(f)}
+ Dir["spec/sample_projects/*/vendor/jruby-rack.jar"].each{|f|FileUtils.rm_f(f)}
+ Dir["spec/sample_projects/*/vendor/jetty"].each{|d|FileUtils.rm_rf(d)}
+ Dir["spec/sample_projects/*/WEB-INF"].each{|d|FileUtils.rm_rf(d)}
+end
+
+RSpec.configure do |config|
+ config.after(:all) do
+ reset
+ end
+end
1 spec/suite.rb
@@ -0,0 +1 @@
+Dir["spec/**/*_spec.rb"].each{|f|require f}
48 spec/web_spec.rb
@@ -0,0 +1,48 @@
+require "spec_helper"
+
+describe "preflight - web start" do
+ before(:all) do
+ reset
+ @result = x!("bin/preflight spec/sample_projects/webapp")
+ end
+
+ after(:all) do
+ reset
+ system("pkill -9 java")
+ end
+
+ it "will unzip jetty under vendor if jetty.xml is present" do
+ @result[:stderr].should == ""
+ @result[:exitstatus].should == 0
+ File.directory?("spec/sample_projects/webapp/vendor/jetty").should == true
+ File.directory?("spec/sample_projects/webapp/vendor/jetty/lib").should == true
+ File.exists?("spec/sample_projects/webapp/vendor/jetty/start.jar").should == true
+ end
+
+ it "places config files" do
+ File.exists?("spec/sample_projects/webapp/WEB-INF/web.xml").should == true
+ File.exists?("spec/sample_projects/webapp/vendor/jetty/etc/jetty.xml").should == true
+ File.exists?("spec/sample_projects/webapp/vendor/jetty/jetty-init").should == true
+ end
+
+ it "runs" do
+ run_app
+ Net::HTTP.get(URI.parse('http://localhost:8080/hello')).strip.should == "Hello World"
+ end
+
+ def run_app
+ Thread.new do
+ system("cd spec/sample_projects/webapp/vendor/jetty && RAILS_ENV=development java -jar start.jar") || raise("app start failed")
+ end
+ start_time = Time.now
+ loop do
+ begin
+ TCPSocket.open("localhost", 8080)
+ return
+ rescue Errno::ECONNREFUSED
+ raise "it's taking too long to start the server, something might be wrong" if Time.now - start_time > 60
+ sleep 0.1
+ end
+ end
+ end
+end
687 web/jetty-init.erb
@@ -0,0 +1,687 @@
+#!/bin/sh
+
+# chkconfig: 3 99 99
+# description: Finance Jetty 6 webserver
+# processname: finance-jetty
+
+THIS_DIR=$(dirname $0)
+WEB_ROOT=$THIS_DIR/../../
+
+JETTY_HOME=$THIS_DIR
+JETTY_RUN=$WEB_ROOT/log
+JETTY_PORT=8080
+JETTY_LOGS=$WEB_ROOT/log
+# Avoid unnecessary su call if we're already the app user
+test `whoami` != <%=@preflight_config['app_user']%> && JETTY_USER=<%=@preflight_config['app_user']%>
+
+
+
+
+
+# Startup script for jetty under *nix systems (it works under NT/cygwin too).
+
+# To get the service to restart correctly on reboot, uncomment below (3 lines):
+# ========================
+# chkconfig: 3 99 99
+# description: Jetty 6 webserver
+# processname: jetty
+# ========================
+
+# Configuration files
+#
+# /etc/default/jetty
+# If it exists, this is read at the start of script. It may perform any
+# sequence of shell commands, like setting relevant environment variables.
+#
+# $HOME/.jettyrc
+# If it exists, this is read at the start of script. It may perform any
+# sequence of shell commands, like setting relevant environment variables.
+#
+# /etc/jetty.conf
+# If found, and no configurations were given on the command line,
+# the file will be used as this script's configuration.
+# Each line in the file may contain:
+# - A comment denoted by the pound (#) sign as first non-blank character.
+# - The path to a regular file, which will be passed to jetty as a
+# config.xml file.
+# - The path to a directory. Each *.xml file in the directory will be
+# passed to jetty as a config.xml file.
+#
+# The files will be checked for existence before being passed to jetty.
+#
+# $JETTY_HOME/etc/jetty.xml
+# If found, used as this script's configuration file, but only if
+# /etc/jetty.conf was not present. See above.
+#
+# Configuration variables
+#
+# JAVA_HOME
+# Home of Java installation.
+#
+# JAVA
+# Command to invoke Java. If not set, $JAVA_HOME/bin/java will be
+# used.
+#
+# JAVA_OPTIONS
+# Extra options to pass to the JVM
+#
+# JETTY_HOME
+# Where Jetty is installed. If not set, the script will try go
+# guess it by first looking at the invocation path for the script,
+# and then by looking in standard locations as $HOME/opt/jetty
+# and /opt/jetty. The java system property "jetty.home" will be
+# set to this value for use by configure.xml files, f.e.:
+#
+# <Arg><SystemProperty name="jetty.home" default="."/>/webapps/jetty.war</Arg>
+#
+# JETTY_PORT
+# Override the default port for Jetty servers. If not set then the
+# default value in the xml configuration file will be used. The java
+# system property "jetty.port" will be set to this value for use in
+# configure.xml files. For example, the following idiom is widely
+# used in the demo config files to respect this property in Listener
+# configuration elements:
+#
+# <Set name="Port"><SystemProperty name="jetty.port" default="8080"/></Set>
+#
+# Note: that the config file could ignore this property simply by saying:
+#
+# <Set name="Port">8080</Set>
+#
+# JETTY_RUN
+# Where the jetty.pid file should be stored. It defaults to the
+# first available of /var/run, /usr/var/run, and /tmp if not set.
+#
+# JETTY_PID
+# The Jetty PID file, defaults to $JETTY_RUN/jetty.pid
+#
+# JETTY_ARGS
+# The default arguments to pass to jetty.
+#
+# JETTY_USER
+# if set, then used as a username to run the server as
+#
+# Set to 0 if you do not want to use start-stop-daemon (especially on SUSE boxes)
+START_STOP_DAEMON=1
+
+usage()
+{
+ echo "Usage: $0 {start|stop|run|restart|check|supervise} [ CONFIGS ... ] "
+ exit 1
+}
+
+[ $# -gt 0 ] || usage
+
+
+##################################################
+# Some utility functions
+##################################################
+findDirectory()
+{
+ OP=$1
+ shift
+ for L in $* ; do
+ [ $OP $L ] || continue
+ echo $L
+ break
+ done
+}
+
+running()
+{
+ [ -f $1 ] || return 1
+ PID=$(cat $1)
+ ps -p $PID >/dev/null 2>/dev/null || return 1
+ return 0
+}
+
+
+
+
+
+
+
+##################################################
+# Get the action & configs
+##################################################
+
+ACTION=$1
+shift
+ARGS="$*"
+CONFIGS=""
+NO_START=0
+
+##################################################
+# See if there's a default configuration file
+##################################################
+if [ -f /etc/default/jetty6 ] ; then
+ . /etc/default/jetty6
+elif [ -f /etc/default/jetty ] ; then
+ . /etc/default/jetty
+fi
+
+
+##################################################
+# See if there's a user-specific configuration file
+##################################################
+if [ -f $HOME/.jettyrc ] ; then
+ . $HOME/.jettyrc
+fi
+
+##################################################
+# Set tmp if not already set.
+##################################################
+
+if [ -z "$TMP" ]
+then
+ TMP=/tmp
+fi
+
+##################################################
+# Jetty's hallmark
+##################################################
+JETTY_INSTALL_TRACE_FILE="etc/jetty.xml"
+TMPJ=$TMP/j$$
+
+
+##################################################
+# Try to determine JETTY_HOME if not set
+##################################################
+if [ -z "$JETTY_HOME" ]
+then
+ JETTY_HOME_1=`dirname "$0"`
+ JETTY_HOME_1=`dirname "$JETTY_HOME_1"`
+ if [ -f "${JETTY_HOME_1}/${JETTY_INSTALL_TRACE_FILE}" ] ;
+ then
+ JETTY_HOME=${JETTY_HOME_1}
+ fi
+fi
+
+
+##################################################
+# if no JETTY_HOME, search likely locations.
+##################################################
+if [ "$JETTY_HOME" = "" ] ; then
+ STANDARD_LOCATIONS=" \
+ /usr/share \
+ /usr/share/java \
+ $HOME \
+ $HOME/src \
+ ${HOME}/opt/ \
+ /opt \
+ /java \
+ /usr/local \
+ /usr/local/share \
+ /usr/local/share/java \
+ /home \
+ "
+ JETTY_DIR_NAMES=" \
+ jetty-6 \
+ jetty6 \
+ jetty-6.* \
+ jetty \
+ Jetty-6 \
+ Jetty6 \
+ Jetty-6.* \
+ Jetty \
+ "
+
+ JETTY_HOME=
+ for L in $STANDARD_LOCATIONS
+ do
+ for N in $JETTY_DIR_NAMES
+ do
+ if [ -d $L/$N ] && [ -f "$L/${N}/${JETTY_INSTALL_TRACE_FILE}" ] ;
+ then
+ JETTY_HOME="$L/$N"
+ fi
+ done
+ [ ! -z "$JETTY_HOME" ] && break
+ done
+fi
+
+
+##################################################
+# No JETTY_HOME yet? We're out of luck!
+##################################################
+if [ -z "$JETTY_HOME" ] ; then
+ echo "** ERROR: JETTY_HOME not set, you need to set it or install in a standard location"
+ exit 1
+fi
+
+cd $JETTY_HOME
+JETTY_HOME=`pwd`
+
+
+#####################################################
+# Check that jetty is where we think it is
+#####################################################
+if [ ! -r $JETTY_HOME/$JETTY_INSTALL_TRACE_FILE ]
+then
+ echo "** ERROR: Oops! Jetty doesn't appear to be installed in $JETTY_HOME"
+ echo "** ERROR: $JETTY_HOME/$JETTY_INSTALL_TRACE_FILE is not readable!"
+ exit 1
+fi
+
+
+###########################################################
+# Get the list of config.xml files from the command line.
+###########################################################
+if [ ! -z "$ARGS" ]
+then
+ for A in $ARGS
+ do
+ if [ -f $A ]
+ then
+ CONF="$A"
+ elif [ -f $JETTY_HOME/etc/$A ]
+ then
+ CONF="$JETTY_HOME/etc/$A"
+ elif [ -f ${A}.xml ]
+ then
+ CONF="${A}.xml"
+ elif [ -f $JETTY_HOME/etc/${A}.xml ]
+ then
+ CONF="$JETTY_HOME/etc/${A}.xml"
+ else
+ echo "** ERROR: Cannot find configuration '$A' specified in the command line."
+ exit 1
+ fi
+ if [ ! -r $CONF ]
+ then
+ echo "** ERROR: Cannot read configuration '$A' specified in the command line."
+ exit 1
+ fi
+ CONFIGS="$CONFIGS $CONF"
+ done
+fi
+
+
+##################################################
+# Try to find this script's configuration file,
+# but only if no configurations were given on the
+# command line.
+##################################################
+if [ -z "$JETTY_CONF" ]
+then
+ if [ -f /etc/jetty.conf ]
+ then
+ JETTY_CONF=/etc/jetty.conf
+ elif [ -f "${JETTY_HOME}/etc/jetty.conf" ]
+ then
+ JETTY_CONF="${JETTY_HOME}/etc/jetty.conf"
+ fi
+fi
+
+##################################################
+# Read the configuration file if one exists
+##################################################
+CONFIG_LINES=
+if [ -z "$CONFIGS" ] && [ -f "$JETTY_CONF" ] && [ -r "$JETTY_CONF" ]
+then
+ CONFIG_LINES=`cat $JETTY_CONF | grep -v "^[:space:]*#" | tr "\n" " "`
+fi
+
+##################################################
+# Get the list of config.xml files from jetty.conf
+##################################################
+if [ ! -z "${CONFIG_LINES}" ]
+then
+ for CONF in ${CONFIG_LINES}
+ do
+ if [ ! -r "$CONF" ]
+ then
+ echo "** WARNING: Cannot read '$CONF' specified in '$JETTY_CONF'"
+ elif [ -f "$CONF" ]
+ then
+ # assume it's a configure.xml file
+ CONFIGS="$CONFIGS $CONF"
+ elif [ -d "$CONF" ]
+ then
+ # assume it's a directory with configure.xml files
+ # for example: /etc/jetty.d/
+ # sort the files before adding them to the list of CONFIGS
+ XML_FILES=`ls ${CONF}/*.xml | sort | tr "\n" " "`
+ for FILE in ${XML_FILES}
+ do
+ if [ -r "$FILE" ] && [ -f "$FILE" ]
+ then
+ CONFIGS="$CONFIGS $FILE"
+ else
+ echo "** WARNING: Cannot read '$FILE' specified in '$JETTY_CONF'"
+ fi
+ done
+ else
+ echo "** WARNING: Don''t know what to do with '$CONF' specified in '$JETTY_CONF'"
+ fi
+ done
+fi
+
+#####################################################
+# Run the standard server if there's nothing else to run
+#####################################################
+if [ -z "$CONFIGS" ]
+then
+ CONFIGS="${JETTY_HOME}/etc/jetty-logging.xml ${JETTY_HOME}/etc/jetty.xml"
+fi
+
+
+#####################################################
+# Find a location for the pid file
+#####################################################
+if [ -z "$JETTY_RUN" ]
+then
+ JETTY_RUN=`findDirectory -w /var/run /usr/var/run /tmp`
+fi
+
+#####################################################
+# Find a PID for the pid file
+#####################################################
+if [ -z "$JETTY_PID" ]
+then
+ JETTY_PID="$JETTY_RUN/jetty.pid"
+fi
+
+
+##################################################
+# Check for JAVA_HOME
+##################################################
+if [ -z "$JAVA_HOME" ]
+then
+ # If a java runtime is not defined, search the following
+ # directories for a JVM and sort by version. Use the highest
+ # version number.
+
+ # Java search path
+ JAVA_LOCATIONS="\
+ /usr/java \
+ /usr/bin \
+ /usr/local/bin \
+ /usr/local/java \
+ /usr/local/jdk \
+ /usr/local/jre \
+ /usr/lib/jvm \
+ /opt/java \
+ /opt/jdk \
+ /opt/jre \
+ "
+ JAVA_NAMES="java jdk jre"
+ for N in $JAVA_NAMES ; do
+ for L in $JAVA_LOCATIONS ; do
+ [ -d $L ] || continue
+ find $L -name "$N" ! -type d | grep -v threads | while read J ; do
+ [ -x $J ] || continue
+ VERSION=`eval $J -version 2>&1`
+ [ $? = 0 ] || continue
+ VERSION=`expr "$VERSION" : '.*"\(1.[0-9\.]*\)["_]'`
+ [ "$VERSION" = "" ] && continue
+ expr $VERSION \< 1.2 >/dev/null && continue
+ echo $VERSION:$J
+ done
+ done
+ done | sort | tail -1 > $TMPJ
+ JAVA=`cat $TMPJ | cut -d: -f2`
+ JVERSION=`cat $TMPJ | cut -d: -f1`
+
+ JAVA_HOME=`dirname $JAVA`
+ while [ ! -z "$JAVA_HOME" -a "$JAVA_HOME" != "/" -a ! -f "$JAVA_HOME/lib/tools.jar" ] ; do
+ JAVA_HOME=`dirname $JAVA_HOME`
+ done
+ [ "$JAVA_HOME" = "" ] && JAVA_HOME=
+
+ echo "Found JAVA=$JAVA in JAVA_HOME=$JAVA_HOME"
+fi
+
+
+##################################################
+# Determine which JVM of version >1.2
+# Try to use JAVA_HOME
+##################################################
+if [ "$JAVA" = "" -a "$JAVA_HOME" != "" ]
+then
+ if [ ! -z "$JAVACMD" ]
+ then
+ JAVA="$JAVACMD"
+ else
+ [ -x $JAVA_HOME/bin/jre -a ! -d $JAVA_HOME/bin/jre ] && JAVA=$JAVA_HOME/bin/jre
+ [ -x $JAVA_HOME/bin/java -a ! -d $JAVA_HOME/bin/java ] && JAVA=$JAVA_HOME/bin/java
+ fi
+fi
+
+if [ "$JAVA" = "" ]
+then
+ echo "Cannot find a JRE or JDK. Please set JAVA_HOME to a >=1.2 JRE" 2>&2
+ exit 1
+fi
+
+JAVA_VERSION=`expr "$($JAVA -version 2>&1 | head -1)" : '.*1\.\([0-9]\)'`
+
+#####################################################
+# See if JETTY_PORT is defined
+#####################################################
+if [ "$JETTY_PORT" != "" ]
+then
+ JAVA_OPTIONS="$JAVA_OPTIONS -Djetty.port=$JETTY_PORT"
+fi
+
+#####################################################
+# See if JETTY_LOGS is defined
+#####################################################
+if [ "$JETTY_LOGS" != "" ]
+then
+ JAVA_OPTIONS="$JAVA_OPTIONS -Djetty.logs=$JETTY_LOGS"
+fi
+
+#####################################################
+# Are we running on Windows? Could be, with Cygwin/NT.
+#####################################################
+case "`uname`" in
+CYGWIN*) PATH_SEPARATOR=";";;
+*) PATH_SEPARATOR=":";;
+esac
+
+
+#####################################################
+# Add jetty properties to Java VM options.
+#####################################################
+JAVA_OPTIONS="$JAVA_OPTIONS -Djetty.home=$JETTY_HOME -Djava.io.tmpdir=$TMP"
+
+[ -f $JETTY_HOME/etc/start.config ] && JAVA_OPTIONS="-DSTART=$JETTY_HOME/etc/start.config $JAVA_OPTIONS"
+
+#####################################################
+# This is how the Jetty server will be started
+#####################################################
+
+JETTY_START=$JETTY_HOME/start.jar
+[ ! -f $JETTY_START ] && JETTY_START=$JETTY_HOME/lib/start.jar
+
+RUN_ARGS="$JAVA_OPTIONS -jar $JETTY_START $JETTY_ARGS $CONFIGS"
+RUN_CMD="$JAVA $RUN_ARGS"
+
+#####################################################
+# Comment these out after you're happy with what
+# the script is doing.
+#####################################################
+#echo "JETTY_HOME = $JETTY_HOME"
+#echo "JETTY_CONF = $JETTY_CONF"
+#echo "JETTY_RUN = $JETTY_RUN"
+#echo "JETTY_PID = $JETTY_PID"
+#echo "JETTY_ARGS = $JETTY_ARGS"
+#echo "CONFIGS = $CONFIGS"
+#echo "JAVA_OPTIONS = $JAVA_OPTIONS"
+#echo "JAVA = $JAVA"
+
+
+##################################################
+# Do the action
+##################################################
+case "$ACTION" in
+ start)
+ echo -n "Starting Jetty: "
+
+ if [ "$NO_START" = "1" ]; then
+ echo "Not starting jetty - NO_START=1 in /etc/default/jetty6";
+ exit 0;
+ fi
+
+
+ if [ "$START_STOP_DAEMON" = "1" ] && type start-stop-daemon > /dev/null 2>&1
+ then
+ [ x$JETTY_USER = x ] && JETTY_USER=$(whoami)
+ [ $UID = 0 ] && CH_USER="-c $JETTY_USER"
+ if start-stop-daemon -S -p$JETTY_PID $CH_USER -d $JETTY_HOME -b -m -a $JAVA -- $RUN_ARGS
+ then
+ sleep 1
+ if running $JETTY_PID
+ then
+ echo OK
+ else
+ echo FAILED
+ fi
+ fi
+
+ else
+
+ if [ -f $JETTY_PID ]
+ then
+ if running $JETTY_PID
+ then
+ echo "Already Running!!"
+ exit 1
+ else
+ # dead pid file - remove
+ rm -f $JETTY_PID
+ fi
+ fi
+
+ if [ x$JETTY_USER != x ]
+ then
+ touch $JETTY_PID
+ chown $JETTY_USER $JETTY_PID
+ su - $JETTY_USER -c "
+ $RUN_CMD &
+ PID=\$!
+ disown \$PID
+ echo \$PID > $JETTY_PID"
+ else
+ $RUN_CMD &
+ PID=$!
+ disown $PID
+ echo $PID > $JETTY_PID
+ fi
+
+ echo "STARTED Jetty `date`"
+ fi
+
+ ;;
+
+ stop)
+ echo -n "Stopping Jetty: "
+ if [ "$START_STOP_DAEMON" = "1" ] && type start-stop-daemon > /dev/null 2>&1; then
+ start-stop-daemon -K -p $JETTY_PID -d $JETTY_HOME -a $JAVA -s HUP
+ sleep 1
+ if running $JETTY_PID
+ then
+ sleep 3
+ if running $JETTY_PID
+ then
+ sleep 30
+ if running $JETTY_PID
+ then
+ start-stop-daemon -K -p $JETTY_PID -d $JETTY_HOME -a $JAVA -s KILL
+ fi
+ fi
+ fi
+
+ rm -f $JETTY_PID
+ echo OK
+ else
+ PID=`cat $JETTY_PID 2>/dev/null`
+ TIMEOUT=30
+ while running $JETTY_PID && [ $TIMEOUT -gt 0 ]
+ do
+ kill $PID 2>/dev/null
+ sleep 1
+ let TIMEOUT=$TIMEOUT-1
+ done
+
+ [ $TIMEOUT -gt 0 ] || kill -9 $PID 2>/dev/null
+
+ rm -f $JETTY_PID
+ echo OK
+ fi
+ ;;
+
+ restart)
+ JETTY_SH=$0
+ if [ ! -f $JETTY_SH ]; then
+ if [ ! -f $JETTY_HOME/bin/jetty.sh ]; then
+ echo "$JETTY_HOME/bin/jetty.sh does not exist."
+ exit 1
+ fi
+ JETTY_SH=$JETTY_HOME/bin/jetty.sh
+ fi
+ $JETTY_SH stop $*
+ sleep 5
+ $JETTY_SH start $*
+ ;;
+
+ supervise)
+ #
+ # Under control of daemontools supervise monitor which
+ # handles restarts and shutdowns via the svc program.
+ #
+ exec $RUN_CMD
+ ;;
+
+ run|demo)
+ echo "Running Jetty: "
+
+ if [ -f $JETTY_PID ]
+ then
+ if running $JETTY_PID
+ then
+ echo "Already Running!!"
+ exit 1
+ else
+ # dead pid file - remove
+ rm -f $JETTY_PID
+ fi
+ fi
+
+ exec $RUN_CMD
+ ;;
+
+ check)
+ echo "Checking arguments to Jetty: "
+ echo "JETTY_HOME = $JETTY_HOME"
+ echo "JETTY_CONF = $JETTY_CONF"
+ echo "JETTY_RUN = $JETTY_RUN"
+ echo "JETTY_PID = $JETTY_PID"
+ echo "JETTY_PORT = $JETTY_PORT"
+ echo "JETTY_LOGS = $JETTY_LOGS"
+ echo "CONFIGS = $CONFIGS"
+ echo "JAVA_OPTIONS = $JAVA_OPTIONS"
+ echo "JAVA = $JAVA"
+ echo "CLASSPATH = $CLASSPATH"
+ echo "RUN_CMD = $RUN_CMD"
+ echo
+
+ if [ -f $JETTY_RUN/jetty.pid ]
+ then
+ echo "Jetty running pid="`cat $JETTY_RUN/jetty.pid`
+ exit 0
+ fi
+ exit 1
+ ;;
+
+*)
+ usage
+ ;;
+esac
+
+exit 0
+
+
+
+
88 web/jetty.xml
@@ -0,0 +1,88 @@
+<?xml version="1.0"?>
+<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
+
+<!-- =============================================================== -->
+<!-- Configure the Jetty Server -->
+<!-- -->
+<!-- Documentation of this file format can be found at: -->
+<!-- http://wiki.eclipse.org/Jetty/Reference/jetty.xml_syntax -->
+<!-- -->
+<!-- Additional configuration files are available in $JETTY_HOME/etc -->
+<!-- and can be mixed in. For example: -->
+<!-- java -jar start.jar etc/jetty-ssl.xml -->
+<!-- -->
+<!-- See start.ini file for the default configuraton files -->
+<!-- =============================================================== -->
+
+
+
+<Configure id="Server" class="org.eclipse.jetty.server.Server">
+
+ <Set name="ThreadPool">
+ <New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
+ <Set name="minThreads">10</Set>
+ <Set name="maxThreads">200</Set>
+ <Set name="detailedDump">false</Set>
+ </New>
+ </Set>
+
+ <Call name="addConnector">
+ <Arg>
+ <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
+ <Set name="host"><Property name="jetty.host" /></Set>
+ <Set name="port"><Property name="jetty.port" default="8080"/></Set>
+ <Set name="maxIdleTime">300000</Set>
+ <Set name="Acceptors">2</Set>
+ <Set name="statsOn">false</Set>
+ <Set name="confidentialPort">8443</Set>
+ <Set name="lowResourcesConnections">20000</Set>
+ <Set name="lowResourcesMaxIdleTime">5000</Set>
+ </New>
+ </Arg>
+ </Call>
+
+ <!-- set the rails.env java system property based on the RAILS_ENV environment variable -->
+ <!-- this is used by jruby-rack to set Rails.env -->
+ <Call class="java.lang.System" name="setProperty">
+ <Arg>rails.env</Arg>
+ <Arg>
+ <Call class="java.lang.System" name="getenv">
+ <Arg>RAILS_ENV</Arg>
+ </Call>
+ </Arg>
+ </Call>
+
+ <Set name="handler">
+ <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
+ <Set name="handlers">
+ <Array type="org.eclipse.jetty.server.Handler">
+ <Item>
+ <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
+ </Item>
+ <Item>
+ <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
+ </Item>
+ <Item>
+
+ <!-- Set up the webapp context for the rails root, which is ../../ from here -->
+ <New class="org.eclipse.jetty.webapp.WebAppContext">
+ <Arg><Ref id="Contexts"/></Arg>
+ <Arg>../../</Arg> <!-- "resource base" -->
+ <Arg>/</Arg> <!-- webapp root -->
+ <Set name="extraClasspath">../jruby.jar;../jruby-rack.jar</Set>
+ <!-- cp that makes ruby+rack work -->
+ </New>
+ </Item>
+ </Array>
+ </Set>
+ </New>
+ </Set>
+
+ <Set name="stopAtShutdown">true</Set>
+ <Set name="sendServerVersion">true</Set>
+ <Set name="sendDateHeader">true</Set>
+ <Set name="gracefulShutdown">1</Set>
+ <Set name="dumpAfterStart">false</Set>
+ <Set name="dumpBeforeStop">false</Set>
+
+</Configure>
47 web/web.xml.erb
@@ -0,0 +1,47 @@
+<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+<web-app>
+ <context-param>
+ <param-name>jruby.min.runtimes</param-name>
+ <param-value>1</param-value>
+ </context-param>
+
+ <context-param>
+ <param-name>jruby.max.runtimes</param-name>
+ <param-value>1</param-value>
+ </context-param>
+
+ <context-param>
+ <param-name>rails.root</param-name>
+ <param-value>.</param-value>
+ </context-param>
+
+ <context-param>
+ <param-name>public.root</param-name>
+ <param-value>public</param-value>
+ </context-param>
+
+ <context-param>
+ <param-name>gem.home</param-name>
+ <param-value><%= @gem_home %></param-value>
+ </context-param>
+
+ <context-param>
+ <param-name>gem.path</param-name>
+ <param-value><%= @gem_path %></param-value>
+ </context-param>
+
+ <filter>
+ <filter-name>RackFilter</filter-name>
+ <filter-class>org.jruby.rack.RackFilter</filter-class>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>RackFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
+ <listener>
+ <listener-class>org.jruby.rack.rails.RailsServletContextListener</listener-class>
+ </listener>
+</web-app>

0 comments on commit a3fd023

Please sign in to comment.
Something went wrong with that request. Please try again.