harker 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +31 -0
- data/Manifest.txt +66 -0
- data/README.rdoc +101 -0
- data/Rakefile +20 -0
- data/bin/harker +19 -0
- data/lib/harker.rb +116 -0
- data/lib/harker/gemify.rb +44 -0
- data/lib/harker/rails_configuration.rb +36 -0
- data/lib/harker/server.rb +125 -0
- data/lib/harker/templates/bin.erb +5 -0
- data/lib/harker/templates/hoe.erb +9 -0
- data/lib/harker/templates/lib.erb +2 -0
- data/test/sample/Manifest.txt +53 -0
- data/test/sample/README.rdoc +46 -0
- data/test/sample/Rakefile +14 -0
- data/test/sample/app/controllers/application_controller.rb +10 -0
- data/test/sample/app/controllers/harks_controller.rb +6 -0
- data/test/sample/app/helpers/application_helper.rb +3 -0
- data/test/sample/app/helpers/harks_helper.rb +2 -0
- data/test/sample/app/models/hark.rb +2 -0
- data/test/sample/bin/sample_rails +5 -0
- data/test/sample/config/boot.rb +110 -0
- data/test/sample/config/database.yml +22 -0
- data/test/sample/config/environment.rb +41 -0
- data/test/sample/config/environments/development.rb +17 -0
- data/test/sample/config/environments/production.rb +28 -0
- data/test/sample/config/environments/test.rb +28 -0
- data/test/sample/config/initializers/backtrace_silencers.rb +7 -0
- data/test/sample/config/initializers/inflections.rb +10 -0
- data/test/sample/config/initializers/mime_types.rb +5 -0
- data/test/sample/config/initializers/new_rails_defaults.rb +19 -0
- data/test/sample/config/initializers/session_store.rb +15 -0
- data/test/sample/config/locales/en.yml +5 -0
- data/test/sample/config/routes.rb +45 -0
- data/test/sample/db/migrate/20090326050232_create_harks.rb +12 -0
- data/test/sample/lib/sample_rails.rb +2 -0
- data/test/sample/public/404.html +30 -0
- data/test/sample/public/422.html +30 -0
- data/test/sample/public/500.html +30 -0
- data/test/sample/public/favicon.ico +0 -0
- data/test/sample/public/images/rails.png +0 -0
- data/test/sample/public/index.html +275 -0
- data/test/sample/public/javascripts/application.js +2 -0
- data/test/sample/public/javascripts/controls.js +963 -0
- data/test/sample/public/javascripts/dragdrop.js +973 -0
- data/test/sample/public/javascripts/effects.js +1128 -0
- data/test/sample/public/javascripts/prototype.js +4320 -0
- data/test/sample/public/robots.txt +5 -0
- data/test/sample/script/about +4 -0
- data/test/sample/script/console +3 -0
- data/test/sample/script/dbconsole +3 -0
- data/test/sample/script/destroy +3 -0
- data/test/sample/script/generate +3 -0
- data/test/sample/script/performance/benchmarker +3 -0
- data/test/sample/script/performance/profiler +3 -0
- data/test/sample/script/plugin +3 -0
- data/test/sample/script/runner +3 -0
- data/test/sample/script/server +3 -0
- data/test/sample/test/fixtures/harks.yml +7 -0
- data/test/sample/test/functional/harks_controller_test.rb +8 -0
- data/test/sample/test/performance/browsing_test.rb +9 -0
- data/test/sample/test/test_helper.rb +38 -0
- data/test/sample/test/unit/hark_test.rb +8 -0
- data/test/sample/test/unit/helpers/harks_helper_test.rb +4 -0
- data/test/test_gemify.sh +18 -0
- data/test/test_harker.rb +81 -0
- metadata +163 -0
data/History.txt
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
=== 0.5.3 / 2009-04-21
|
2
|
+
|
3
|
+
* Load app extensions on a per-instance basis.
|
4
|
+
* Depend on hoe so Rails' test task isn't interfered with.
|
5
|
+
|
6
|
+
=== 0.5.2 / 2009-03-31
|
7
|
+
|
8
|
+
* Remove Hoe test task if supported.
|
9
|
+
|
10
|
+
=== 0.5.1 / 2009-03-30
|
11
|
+
|
12
|
+
* Fixed a problem with the Usage message.
|
13
|
+
|
14
|
+
=== 0.5.0 / 2009-03-30
|
15
|
+
|
16
|
+
* Use gem's config/database.yml for a base.
|
17
|
+
* Gemifying existing apps works now.
|
18
|
+
* Accept arguments for script/server when starting app.
|
19
|
+
|
20
|
+
=== 0.0.3 / 2009-03-26
|
21
|
+
|
22
|
+
* A release!
|
23
|
+
* First pass at automating gemification of Rails apps with bin/harker.
|
24
|
+
* Swapped order of Harker.launch args; now action then instance dir.
|
25
|
+
* Apps don't need config/environment.rb tweaks to use harker.
|
26
|
+
* Got some docs; yay.
|
27
|
+
|
28
|
+
=== 0.0.1 / 2009-03-25
|
29
|
+
|
30
|
+
* Birthday!
|
31
|
+
|
data/Manifest.txt
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.rdoc
|
4
|
+
Rakefile
|
5
|
+
bin/harker
|
6
|
+
lib/harker.rb
|
7
|
+
lib/harker/gemify.rb
|
8
|
+
lib/harker/rails_configuration.rb
|
9
|
+
lib/harker/server.rb
|
10
|
+
lib/harker/templates/bin.erb
|
11
|
+
lib/harker/templates/hoe.erb
|
12
|
+
lib/harker/templates/lib.erb
|
13
|
+
test/sample/Manifest.txt
|
14
|
+
test/sample/README.rdoc
|
15
|
+
test/sample/Rakefile
|
16
|
+
test/sample/app/controllers/application_controller.rb
|
17
|
+
test/sample/app/controllers/harks_controller.rb
|
18
|
+
test/sample/app/helpers/application_helper.rb
|
19
|
+
test/sample/app/helpers/harks_helper.rb
|
20
|
+
test/sample/app/models/hark.rb
|
21
|
+
test/sample/bin/sample_rails
|
22
|
+
test/sample/config/boot.rb
|
23
|
+
test/sample/config/database.yml
|
24
|
+
test/sample/config/environment.rb
|
25
|
+
test/sample/config/environments/development.rb
|
26
|
+
test/sample/config/environments/production.rb
|
27
|
+
test/sample/config/environments/test.rb
|
28
|
+
test/sample/config/initializers/backtrace_silencers.rb
|
29
|
+
test/sample/config/initializers/inflections.rb
|
30
|
+
test/sample/config/initializers/mime_types.rb
|
31
|
+
test/sample/config/initializers/new_rails_defaults.rb
|
32
|
+
test/sample/config/initializers/session_store.rb
|
33
|
+
test/sample/config/locales/en.yml
|
34
|
+
test/sample/config/routes.rb
|
35
|
+
test/sample/db/migrate/20090326050232_create_harks.rb
|
36
|
+
test/sample/lib/sample_rails.rb
|
37
|
+
test/sample/public/404.html
|
38
|
+
test/sample/public/422.html
|
39
|
+
test/sample/public/500.html
|
40
|
+
test/sample/public/favicon.ico
|
41
|
+
test/sample/public/images/rails.png
|
42
|
+
test/sample/public/index.html
|
43
|
+
test/sample/public/javascripts/application.js
|
44
|
+
test/sample/public/javascripts/controls.js
|
45
|
+
test/sample/public/javascripts/dragdrop.js
|
46
|
+
test/sample/public/javascripts/effects.js
|
47
|
+
test/sample/public/javascripts/prototype.js
|
48
|
+
test/sample/public/robots.txt
|
49
|
+
test/sample/script/about
|
50
|
+
test/sample/script/console
|
51
|
+
test/sample/script/dbconsole
|
52
|
+
test/sample/script/destroy
|
53
|
+
test/sample/script/generate
|
54
|
+
test/sample/script/performance/benchmarker
|
55
|
+
test/sample/script/performance/profiler
|
56
|
+
test/sample/script/plugin
|
57
|
+
test/sample/script/runner
|
58
|
+
test/sample/script/server
|
59
|
+
test/sample/test/fixtures/harks.yml
|
60
|
+
test/sample/test/functional/harks_controller_test.rb
|
61
|
+
test/sample/test/performance/browsing_test.rb
|
62
|
+
test/sample/test/test_helper.rb
|
63
|
+
test/sample/test/unit/hark_test.rb
|
64
|
+
test/sample/test/unit/helpers/harks_helper_test.rb
|
65
|
+
test/test_gemify.sh
|
66
|
+
test/test_harker.rb
|
data/README.rdoc
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
= Harker
|
2
|
+
|
3
|
+
http://github.com/technomancy/harker
|
4
|
+
|
5
|
+
== Description
|
6
|
+
|
7
|
+
Harker means Rails deployments via RubyGems--because a package manager
|
8
|
+
is a terrible thing to waste.
|
9
|
+
|
10
|
+
== Motivation
|
11
|
+
|
12
|
+
This will mean you can use the same infrastructure you already rely on
|
13
|
+
for your dependencies to manage your application itself. It means
|
14
|
+
never having to keep a checkout of your app just for deployment. It
|
15
|
+
also becomes very easy to see what versions are installed on a given
|
16
|
+
box and run multiple instances (of the same or different versions) at
|
17
|
+
the same time on different ports.
|
18
|
+
|
19
|
+
Your app code will live in your gem home, but all the files specific
|
20
|
+
to a given instance will live in an instance directory.
|
21
|
+
|
22
|
+
In short: you've already got a package manager. Why are you handling
|
23
|
+
installation of your deployed apps with a one-off tool?
|
24
|
+
|
25
|
+
== Setup
|
26
|
+
|
27
|
+
Your Rails app will need to be modified a bit to become a gem and work
|
28
|
+
with Harker. But don't worry, these modifications will improve your
|
29
|
+
app and make it more awesome. Running "harker /path/to/rails/app" will
|
30
|
+
attempt to turn it into a gem that uses Hoe. You may need to perform a
|
31
|
+
bit of tweaking in order to get it to build cleanly since every app is
|
32
|
+
different--see the one in test/sample/ for an example of how this
|
33
|
+
works. In particular, be sure Manifest.txt does not include any files
|
34
|
+
that shouldn't go in the gem, such as pid or log files.
|
35
|
+
|
36
|
+
You don't have to use Hoe if you want to turn your app into a gem
|
37
|
+
manually or using another library, but it helps.
|
38
|
+
|
39
|
+
== Usage
|
40
|
+
|
41
|
+
Once your app is a gem, install it locally with "rake install_gem",
|
42
|
+
and you should be able to use the bin wrapper to generate a new
|
43
|
+
instance:
|
44
|
+
|
45
|
+
$ your_app init ~/apps/your_app_3001
|
46
|
+
|
47
|
+
Then edit ~/apps/your_app_3001/database.yml with your database
|
48
|
+
settings. At that point you should be able to bring up your database:
|
49
|
+
|
50
|
+
$ your_app migrate ~/apps/your_app_3001
|
51
|
+
|
52
|
+
Test it out by dropping into the console:
|
53
|
+
|
54
|
+
$ your_app console ~/apps/your_app_3001
|
55
|
+
|
56
|
+
Then you can start and stop your application server via Rack:
|
57
|
+
|
58
|
+
$ your_app start ~/apps/your_app_3001 --daemon --port=3001
|
59
|
+
$ your_app stop ~/apps/your_app_3001
|
60
|
+
|
61
|
+
The start command takes all the same arguments as script/server. To
|
62
|
+
configure it in a way that doesn't require command-line arguments,
|
63
|
+
create a config.ru file in your instance directory, and Rails will
|
64
|
+
pick that up with Rack.
|
65
|
+
|
66
|
+
If you omit the second argument, it defaults to the current directory.
|
67
|
+
|
68
|
+
For deployment, simply publish your gem to a gem server (public or
|
69
|
+
private), install it on the target server, and launch it via the bin
|
70
|
+
wrapper as shown above.
|
71
|
+
|
72
|
+
== Extensions
|
73
|
+
|
74
|
+
Sometimes it becomes necessary to hot-patch a deployed app. Instead of
|
75
|
+
editing the code inside your gem home, (which is Fraught with Peril)
|
76
|
+
you can place .rb files inside your instance directory's extensions/
|
77
|
+
directory. These will be loaded immediately after the application is
|
78
|
+
required.
|
79
|
+
|
80
|
+
== Requirements
|
81
|
+
|
82
|
+
* rails (at least 2.3.2)
|
83
|
+
* a Rails app to use it with
|
84
|
+
* rubygems
|
85
|
+
* hoe (technically optional)
|
86
|
+
|
87
|
+
== Install
|
88
|
+
|
89
|
+
* sudo gem install technomancy-harker --source=http://gems.github.com --source=http://gems.rubyforge.org
|
90
|
+
|
91
|
+
== Todo
|
92
|
+
|
93
|
+
* rake tasks for remotely installing gem
|
94
|
+
* make it easy to "rake release" to a private gem repo
|
95
|
+
* test, test, test. try it out with more rails apps!
|
96
|
+
|
97
|
+
== License
|
98
|
+
|
99
|
+
Copyright (c) 2009 Phil Hagelberg.
|
100
|
+
|
101
|
+
Licensed under the same terms as Ruby.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/harker.rb'
|
6
|
+
|
7
|
+
Hoe.new('harker', Harker::VERSION) do |p|
|
8
|
+
p.developer('Phil Hagelberg', 'technomancy@gmail.com')
|
9
|
+
p.rubyforge_name = "seattlerb"
|
10
|
+
p.readme_file = 'README.rdoc'
|
11
|
+
p.summary = "Harker: Rubygems-based deployment for Rails apps."
|
12
|
+
|
13
|
+
p.extra_deps << ["rails", "~> 2.3.2"]
|
14
|
+
p.extra_dev_deps << ["minitest", "~> 1.3.1"]
|
15
|
+
p.extra_dev_deps << ["sqlite3-ruby", "~> 1.2.4"]
|
16
|
+
# recommended:
|
17
|
+
# p.extra_dev_deps << ["mongrel", "~> 1.2.4"]
|
18
|
+
end
|
19
|
+
|
20
|
+
# vim: syntax=Ruby
|
data/bin/harker
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'harker/gemify'
|
4
|
+
|
5
|
+
begin
|
6
|
+
gem 'hoe'
|
7
|
+
rescue LoadError
|
8
|
+
abort 'Hoe not found. You can continue without hoe if you gemify
|
9
|
+
your app yourself; see Harker documentation for details.'
|
10
|
+
end
|
11
|
+
|
12
|
+
if ARGV.include?('-h') or ARGV.include?('--help') or ARGV.size > 1
|
13
|
+
puts "Usage: #{File.basename($0)} [RAILS_ROOT]"
|
14
|
+
puts
|
15
|
+
puts "Attempts to turn your Rails app into a gem for deployment with harker."
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
|
19
|
+
Harker.gemify(ARGV.shift || Dir.pwd)
|
data/lib/harker.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
# Harker lets you deploy Rails apps via RubyGems.
|
4
|
+
#
|
5
|
+
# These commands get invoked by the bin wrapper of the rails app gem
|
6
|
+
# rather than by Harker itself.
|
7
|
+
#
|
8
|
+
module Harker
|
9
|
+
VERSION = '0.5.3'
|
10
|
+
ACTIONS = %w(start stop restart init migrate console)
|
11
|
+
GEM_ROOT = Gem.loaded_specs[File.basename($0)].full_gem_path rescue '.'
|
12
|
+
|
13
|
+
module_function
|
14
|
+
|
15
|
+
# Dispatch based on user's command
|
16
|
+
def launch(name, args)
|
17
|
+
action = args.shift
|
18
|
+
|
19
|
+
unless ACTIONS.include?(action)
|
20
|
+
abort "Usage: #{name} (#{ACTIONS.join('|')}) [INSTANCE_DIR] [START_ARGS]
|
21
|
+
The start command takes the same arguments as script/server."
|
22
|
+
end
|
23
|
+
|
24
|
+
# We need to get rid of the first arg if it's the optional
|
25
|
+
# instance directory so script/server doesn't get confused.
|
26
|
+
@root = if File.directory? args.first.to_s or action == 'init'
|
27
|
+
File.expand_path args.shift
|
28
|
+
else
|
29
|
+
Dir.pwd
|
30
|
+
end
|
31
|
+
|
32
|
+
@name = name
|
33
|
+
|
34
|
+
unless action == 'init'
|
35
|
+
# 2.3.2 doesn't support tmp_dir config option; needs a monkeypatch.
|
36
|
+
require 'harker/rails_configuration'
|
37
|
+
require @name
|
38
|
+
Dir["#{@root}/extensions/*rb"].each { |f| load f }
|
39
|
+
end
|
40
|
+
|
41
|
+
self.send(action)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Start and optionally daemonize the application server
|
45
|
+
def start
|
46
|
+
# http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2350
|
47
|
+
# Submitted a patch to Rails, but this lets it work with 2.3.2
|
48
|
+
Rails::Rack::LogTailer::EnvironmentLog.replace(Rails.configuration.log_path)
|
49
|
+
|
50
|
+
abort "Can't start; pidfile exists at #{pidfile}." if File.exist? pidfile
|
51
|
+
require 'harker/server'
|
52
|
+
end
|
53
|
+
|
54
|
+
def stop
|
55
|
+
abort "No pid at #{pidfile}." unless File.exist?(pidfile)
|
56
|
+
Process.kill('TERM', File.read(pidfile).to_i)
|
57
|
+
end
|
58
|
+
|
59
|
+
def restart
|
60
|
+
stop
|
61
|
+
rescue SystemExit
|
62
|
+
start
|
63
|
+
end
|
64
|
+
|
65
|
+
# Initialize a new instance of your application
|
66
|
+
def init
|
67
|
+
%w(tmp log db extensions).each do |d|
|
68
|
+
FileUtils.mkdir_p(File.join(@root, d))
|
69
|
+
end
|
70
|
+
|
71
|
+
base_db_file = File.join(GEM_ROOT, 'config', 'database.yml')
|
72
|
+
|
73
|
+
File.open("#{@root}/database.yml", 'w') do |fp|
|
74
|
+
# Need to make sure any sqlite3 DB paths are absolute.
|
75
|
+
db_config = YAML.load_file(base_db_file)
|
76
|
+
db_config.each do |env, hash|
|
77
|
+
if hash['adapter'] =~ /sqlite3?/
|
78
|
+
hash['database'] = File.join(@root, hash['database'])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
fp.puts(db_config.to_yaml)
|
83
|
+
end
|
84
|
+
|
85
|
+
puts <<-END
|
86
|
+
Initialized #{@name} instance in #{@root}...
|
87
|
+
|
88
|
+
Configure your database by editing #{@root}/database.yml.
|
89
|
+
Optionally configure your web server via rack in #{@root}/config.ru.
|
90
|
+
|
91
|
+
Migrate your DB with: #{@name} migrate
|
92
|
+
Then launch with: #{@name} start --daemon
|
93
|
+
END
|
94
|
+
end
|
95
|
+
|
96
|
+
def migrate
|
97
|
+
puts "Migrating the #{RAILS_ENV} environment of #{@name}..."
|
98
|
+
ActiveRecord::Migrator.migrate(File.join(Rails.root, 'db', 'migrate'),
|
99
|
+
ENV["VERSION"] && ENV["VERSION"].to_i)
|
100
|
+
end
|
101
|
+
|
102
|
+
def console
|
103
|
+
require 'irb'
|
104
|
+
IRB.start
|
105
|
+
end
|
106
|
+
|
107
|
+
def configure(config)
|
108
|
+
config.database_configuration_file = File.join(@root, 'database.yml')
|
109
|
+
config.log_path = File.join(@root, 'log', "#{RAILS_ENV}.log")
|
110
|
+
config.tmp_dir = File.join(@root, 'tmp')
|
111
|
+
end
|
112
|
+
|
113
|
+
def pidfile
|
114
|
+
File.join(@root, 'tmp', 'pids', 'server.pid')
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'harker'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
module Harker
|
6
|
+
# Turn an existing Rails app into a gem.
|
7
|
+
def self.gemify(rails_root)
|
8
|
+
@project_name = File.basename(rails_root)
|
9
|
+
|
10
|
+
if File.exist?(rails_root + "/bin/#{@project_name}") or
|
11
|
+
File.exist?(rails_root + "/lib/#{@project_name}.rb")
|
12
|
+
abort "Can't write gem files without overwriting existing ones.
|
13
|
+
Try manually gemifying."
|
14
|
+
end
|
15
|
+
|
16
|
+
File.open(File.join(rails_root, '/Rakefile'), 'a') do |fp|
|
17
|
+
fp.puts template('hoe')
|
18
|
+
puts "Added hoe block to Rakefile."
|
19
|
+
end
|
20
|
+
|
21
|
+
FileUtils.mkdir_p(File.join(rails_root, '/bin'))
|
22
|
+
File.open(File.join(rails_root, "/bin/#{@project_name}"), 'w') do |fp|
|
23
|
+
fp.puts template('bin')
|
24
|
+
puts "Wrote bin launcher."
|
25
|
+
end
|
26
|
+
|
27
|
+
File.open(File.join(rails_root, "/lib/#{@project_name}.rb"), 'w') do |fp|
|
28
|
+
fp.puts template('lib')
|
29
|
+
puts "Wrote lib file."
|
30
|
+
end
|
31
|
+
|
32
|
+
# Submitted a patch to hoe to make it ignore log files by default,
|
33
|
+
# but folks should still give it a once-over manually anyway.
|
34
|
+
system "cd #{rails_root}; touch Manifest.txt; rake check_manifest | patch"
|
35
|
+
puts "Wrote Manifest.txt."
|
36
|
+
puts "Ensure the manifest doesn't contain files you don't want in the gem."
|
37
|
+
puts "Then try running rake install_gem."
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.template(name)
|
41
|
+
template_path = File.join File.dirname(__FILE__), 'templates', "#{name}.erb"
|
42
|
+
ERB.new(File.read(template_path)).result(binding)
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# This monkeypatches Rails to allow tmp_dir to be configured.
|
2
|
+
|
3
|
+
# It's been submitted upstream:
|
4
|
+
# http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2379
|
5
|
+
|
6
|
+
# We can remove the Configuration monkeypatch once the above patch is
|
7
|
+
# accepted if we don't care about supporting older versions.
|
8
|
+
|
9
|
+
gem 'rails'
|
10
|
+
require 'initializer'
|
11
|
+
|
12
|
+
class Rails::Configuration
|
13
|
+
attr_accessor :tmp_dir
|
14
|
+
|
15
|
+
def default_tmp_dir
|
16
|
+
File.join(root_path, 'tmp')
|
17
|
+
end
|
18
|
+
|
19
|
+
def default_cache_store
|
20
|
+
if File.exist? File.join(default_tmp_dir, 'cache')
|
21
|
+
[ :file_store, File.join(default_tmp_dir, 'cache') ]
|
22
|
+
else
|
23
|
+
:memory_store
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Rails::Initializer
|
29
|
+
def self.run(command = :process, configuration = Rails::Configuration.new)
|
30
|
+
yield configuration if block_given?
|
31
|
+
Harker.configure(configuration)
|
32
|
+
initializer = new configuration
|
33
|
+
initializer.send(command)
|
34
|
+
initializer
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# A patched copy of what Rails' script/server runs.
|
2
|
+
|
3
|
+
# These changes were submitted upstream to Rails:
|
4
|
+
# http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2379
|
5
|
+
|
6
|
+
# We can remove this file once that patch is accepted if we don't care
|
7
|
+
# about supporting older versions.
|
8
|
+
|
9
|
+
# Only two changes were made, noted below by comments beginning with "Harker"
|
10
|
+
|
11
|
+
require 'active_support'
|
12
|
+
require 'action_controller'
|
13
|
+
|
14
|
+
require 'fileutils'
|
15
|
+
require 'optparse'
|
16
|
+
|
17
|
+
begin
|
18
|
+
require_library_or_gem 'thin'
|
19
|
+
rescue Exception
|
20
|
+
# Thin not available
|
21
|
+
end
|
22
|
+
|
23
|
+
options = {
|
24
|
+
:Port => 3000,
|
25
|
+
:Host => "0.0.0.0",
|
26
|
+
:environment => (ENV['RAILS_ENV'] || "development").dup,
|
27
|
+
:config => RAILS_ROOT + "/config.ru",
|
28
|
+
:detach => false,
|
29
|
+
:debugger => false,
|
30
|
+
:path => nil
|
31
|
+
}
|
32
|
+
|
33
|
+
ARGV.clone.options do |opts|
|
34
|
+
opts.on("-p", "--port=port", Integer,
|
35
|
+
"Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v }
|
36
|
+
opts.on("-b", "--binding=ip", String,
|
37
|
+
"Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| options[:Host] = v }
|
38
|
+
opts.on("-c", "--config=file", String,
|
39
|
+
"Use custom rackup configuration file") { |v| options[:config] = v }
|
40
|
+
opts.on("-d", "--daemon", "Make server run as a Daemon.") { options[:detach] = true }
|
41
|
+
opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { options[:debugger] = true }
|
42
|
+
opts.on("-e", "--environment=name", String,
|
43
|
+
"Specifies the environment to run this server under (test/development/production).",
|
44
|
+
"Default: development") { |v| options[:environment] = v }
|
45
|
+
opts.on("-P", "--path=/path", String, "Runs Rails app mounted at a specific path.", "Default: /") { |v| options[:path] = v }
|
46
|
+
|
47
|
+
opts.separator ""
|
48
|
+
|
49
|
+
opts.on("-h", "--help", "Show this help message.") { puts opts; exit }
|
50
|
+
|
51
|
+
opts.parse!
|
52
|
+
end
|
53
|
+
|
54
|
+
server = Rack::Handler.get(ARGV.first) rescue nil
|
55
|
+
unless server
|
56
|
+
begin
|
57
|
+
server = Rack::Handler::Mongrel
|
58
|
+
rescue LoadError => e
|
59
|
+
server = Rack::Handler::WEBrick
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
|
64
|
+
puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}#{options[:path]}"
|
65
|
+
|
66
|
+
%w(cache pids sessions sockets).each do |dir_to_make|
|
67
|
+
# Harker: patched to use Rails.configuration.tmp_dir
|
68
|
+
FileUtils.mkdir_p(File.join(Rails.configuration.tmp_dir, dir_to_make))
|
69
|
+
end
|
70
|
+
|
71
|
+
if options[:detach]
|
72
|
+
Process.daemon
|
73
|
+
# Harker: patched to use Rails.configuration.tmp_dir
|
74
|
+
pid = File.join(Rails.configuration.tmp_dir, 'pids', 'server.pid')
|
75
|
+
File.open(pid, 'w'){ |f| f.write(Process.pid) }
|
76
|
+
at_exit { File.delete(pid) if File.exist?(pid) }
|
77
|
+
end
|
78
|
+
|
79
|
+
ENV["RAILS_ENV"] = options[:environment]
|
80
|
+
RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV)
|
81
|
+
|
82
|
+
if File.exist?(options[:config])
|
83
|
+
config = options[:config]
|
84
|
+
if config =~ /\.ru$/
|
85
|
+
cfgfile = File.read(config)
|
86
|
+
if cfgfile[/^#\\(.*)/]
|
87
|
+
opts.parse!($1.split(/\s+/))
|
88
|
+
end
|
89
|
+
inner_app = eval("Rack::Builder.new {( " + cfgfile + "\n )}.to_app", nil, config)
|
90
|
+
else
|
91
|
+
require config
|
92
|
+
inner_app = Object.const_get(File.basename(config, '.rb').capitalize)
|
93
|
+
end
|
94
|
+
else
|
95
|
+
require RAILS_ROOT + "/config/environment"
|
96
|
+
inner_app = ActionController::Dispatcher.new
|
97
|
+
end
|
98
|
+
|
99
|
+
if options[:path].nil?
|
100
|
+
map_path = "/"
|
101
|
+
else
|
102
|
+
ActionController::Base.relative_url_root = options[:path]
|
103
|
+
map_path = options[:path]
|
104
|
+
end
|
105
|
+
|
106
|
+
app = Rack::Builder.new {
|
107
|
+
use Rails::Rack::LogTailer unless options[:detach]
|
108
|
+
use Rails::Rack::Debugger if options[:debugger]
|
109
|
+
map map_path do
|
110
|
+
use Rails::Rack::Static
|
111
|
+
run inner_app
|
112
|
+
end
|
113
|
+
}.to_app
|
114
|
+
|
115
|
+
puts "=> Call with -d to detach"
|
116
|
+
|
117
|
+
trap(:INT) { exit }
|
118
|
+
|
119
|
+
puts "=> Ctrl-C to shutdown server"
|
120
|
+
|
121
|
+
begin
|
122
|
+
server.run(app, options.merge(:AccessLog => []))
|
123
|
+
ensure
|
124
|
+
puts 'Exiting'
|
125
|
+
end
|