golden_brindle 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{golden_brindle}
8
- s.version = "0.0.5"
8
+ s.version = "0.0.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alexander Simonov"]
12
- s.date = %q{2010-07-03}
12
+ s.date = %q{2010-09-05}
13
13
  s.default_executable = %q{golden_brindle}
14
14
  s.description = %q{Unicorn HTTP server clustering tool like mongrel_cluster for Mongrel}
15
15
  s.email = %q{alex@simonov.me}
@@ -3,7 +3,7 @@ module GoldenBrindle
3
3
  module Const
4
4
 
5
5
  # current version
6
- VERSION="0.0.5".freeze
6
+ VERSION="0.0.6".freeze
7
7
  # main banner
8
8
  BANNER = "Usage: golden_brindle <command> [options]".freeze
9
9
 
@@ -32,7 +32,7 @@ module Brindle
32
32
  # Rails 3 dispatcher support
33
33
  # Code from unicorn_rails script
34
34
  #
35
- def rails_dispatcher
35
+ def self.rails_dispatcher
36
36
  if ::Rails::VERSION::MAJOR >= 3 && ::File.exist?('config/application.rb')
37
37
  if ::File.read('config/application.rb') =~ /^module\s+([\w:]+)\s*$/
38
38
  app_module = Object.const_get($1)
@@ -66,11 +66,11 @@ module Brindle
66
66
  defined?(::Rails::VERSION::STRING) or
67
67
  abort "Rails::VERSION::STRING not defined by config/{boot,environment}"
68
68
  # it seems Rails >=2.2 support Rack, but only >=2.3 requires it
69
- old_rails = if ::Rails::VERSION::MAJOR >= 3
70
- false
69
+ old_rails = case ::Rails::VERSION::MAJOR
70
+ when 0, 1 then true
71
+ when 2 then Rails::VERSION::MINOR < 3 ? true : false
71
72
  else
72
- return false if ( ::Rails::VERSION::MAJOR == 2 && ::Rails::VERSION::MINOR >= 3 )
73
- true
73
+ false
74
74
  end
75
75
 
76
76
  Rack::Builder.new do
@@ -95,7 +95,7 @@ module Brindle
95
95
  unless defined?(ActionDispatch::Static)
96
96
  use Rails::Rack::Static
97
97
  end
98
- run rails_dispatcher
98
+ run Brindle::Start.rails_dispatcher
99
99
  end
100
100
  end
101
101
  end.to_app
@@ -128,12 +128,14 @@ module Brindle
128
128
  def run
129
129
  # Change there to start, then we'll have to come back after daemonize
130
130
  Dir.chdir(@cwd)
131
- options = { :listeners => []}
132
- options[:pid] = @pid_file
133
- options[:config_file] = @config_script
134
- options[:worker_processes] = @workers.to_i
135
- options[:working_directory] = @cwd
136
- options[:timeout] = @timeout
131
+ options = {
132
+ :listeners => [],
133
+ :pid => @pid_file,
134
+ :config_file => @config_script,
135
+ :worker_processes => @workers.to_i,
136
+ :working_directory => @cwd,
137
+ :timeout => @timeout
138
+ }
137
139
  # set user via Unicorn options. If we don't set group - then use only user
138
140
  options[:user] = @user unless @user.nil?
139
141
  options[:stderr_path] = options[:stdout_path] = @log_file if @daemon
@@ -148,34 +150,41 @@ module Brindle
148
150
  defined?(ActiveRecord::Base) and
149
151
  ActiveRecord::Base.establish_connection
150
152
  # trying to change user and group
151
- begin
152
- # check if something not set in config or cli
153
- unless @user.nil? || @group.nil?
154
- uid, gid = Process.euid, Process.egid
155
- user, group = @user, @group
156
- target_uid = Etc.getpwnam(user).uid
157
- target_gid = Etc.getgrnam(group).gid
158
- worker.tmp.chown(target_uid, target_gid)
159
- if uid != target_uid || gid != target_gid
160
- Process.initgroups(user, target_gid)
161
- Process::GID.change_privilege(target_gid)
162
- Process::UID.change_privilege(target_uid)
163
- end
153
+ begin
154
+ # check if something not set in config or cli
155
+ unless @user.nil? || @group.nil?
156
+ uid, gid = Process.euid, Process.egid
157
+ user, group = @user, @group
158
+ target_uid = Etc.getpwnam(user).uid
159
+ target_gid = Etc.getgrnam(group).gid
160
+ worker.tmp.chown(target_uid, target_gid)
161
+ if uid != target_uid || gid != target_gid
162
+ Process.initgroups(user, target_gid)
163
+ Process::GID.change_privilege(target_gid)
164
+ Process::UID.change_privilege(target_uid)
164
165
  end
165
- rescue => e
166
- if ENV['RAILS_ENV'] == 'development'
167
- STDERR.puts "couldn't change user, oh well"
168
- else
169
- raise e
170
- end
166
+ end
167
+ rescue => e
168
+ if ENV['RAILS_ENV'] == 'development'
169
+ STDERR.puts "couldn't change user, oh well"
170
+ else
171
+ raise e
171
172
  end
173
+ end
172
174
  end
173
175
  options[:before_fork] = lambda do |server, worker|
174
176
  defined?(ActiveRecord::Base) and
175
177
  ActiveRecord::Base.connection.disconnect!
176
178
  # http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
177
179
  if GC.respond_to?(:copy_on_write_friendly=)
178
- GC.copy_on_write_friendly = true
180
+ GC.copy_on_write_friendly = true
181
+ end
182
+ old_pid = "#{server.config[:pid]}.oldbin"
183
+ if File.exists?(old_pid) && server.pid != old_pid
184
+ begin
185
+ Process.kill("QUIT", File.read(old_pid).to_i)
186
+ rescue Errno::ENOENT, Errno::ESRCH
187
+ end
179
188
  end
180
189
  end
181
190
  ENV['RAILS_ENV'] = @environment
@@ -2,6 +2,6 @@ require 'helper'
2
2
 
3
3
  class TestGoldenBrindle < Test::Unit::TestCase
4
4
  should "probably rename this file and start testing for real" do
5
- #flunk "hey buddy, you should probably rename this file and start testing for real"
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: golden_brindle
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alexander Simonov
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-03 00:00:00 +03:00
18
+ date: 2010-09-05 00:00:00 +03:00
19
19
  default_executable: golden_brindle
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency