Skip to content

Commit ff65944

Browse files
author
Danial Pearce
committedJul 26, 2012
Remove all the Proc hacks since I know a bit more about how defaults work now.
1 parent 17d7770 commit ff65944

File tree

2 files changed

+30
-38
lines changed

2 files changed

+30
-38
lines changed
 

‎attributes/default.rb

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
default['unicorn']['installs'] = []
2-
default['unicorn']['rack_env'] = 'production'
3-
default['unicorn']['user'] = 'root'
4-
default['unicorn']['group'] = 'root'
5-
default['unicorn']['pid'] = Proc.new{|root| "#{root}/tmp/pids/unicorn.pid" }
6-
default['unicorn']['service'] = Proc.new{|env| "unicorn-#{env}" }
7-
default['unicorn']['command'] = Proc.new{|root, env, config| "cd #{root} && bundle exec unicorn_rails -D -E #{env} -c #{config}" }
82

93
default['unicorn']['config']['generate'] = true
10-
default['unicorn']['config']['path'] = Proc.new{|root| "#{root}/config/unicorn.rb" }
11-
default['unicorn']['config']['stderr_path'] = Proc.new{|root| "#{root}/log/unicorn.log" }
12-
default['unicorn']['config']['stdout_path'] = Proc.new{|root| "#{root}/log/unicorn.log" }
4+
default['unicorn']['config']['path'] = "#{node['unicorn']['app_root']}/config/unicorn.rb"
5+
default['unicorn']['config']['stderr_path'] = "#{node['unicorn']['app_root']}/log/unicorn.log"
6+
default['unicorn']['config']['stdout_path'] = "#{node['unicorn']['app_root']}/log/unicorn.log"
137
default['unicorn']['config']['listen'] = [['3000', '{ :tcp_nodelay => true, :tries => 5 }']]
148
default['unicorn']['config']['working_directory'] = nil
159
default['unicorn']['config']['worker_timeout'] = 60
@@ -18,3 +12,10 @@
1812
default['unicorn']['config']['before_exec'] = nil
1913
default['unicorn']['config']['before_fork'] = nil
2014
default['unicorn']['config']['after_fork'] = nil
15+
16+
default['unicorn']['rack_env'] = 'production'
17+
default['unicorn']['user'] = 'root'
18+
default['unicorn']['group'] = 'root'
19+
default['unicorn']['pid'] = "#{node['unicorn']['app_root']}/tmp/pids/unicorn.pid"
20+
default['unicorn']['service'] = "unicorn-#{node['unicorn']['rack_env']}"
21+
default['unicorn']['command'] = "cd #{node['unicorn']['app_root']} && bundle exec unicorn_rails -D -E #{node['unicorn']['rack_env']} -c #{node['unicorn']['config']['path']}"

‎recipes/default.rb

+20-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
node['unicorn']['installs'].each do |install|
2-
# Make sure the install defaults come across for each unicorn install
2+
3+
# Since a lot of defaults rely on app_root, set it and reload defeaults
4+
node.set['unicorn']['app_root'] = install['app_root']
5+
node.load_attribute_by_short_filename('default', 'unicorn')
6+
7+
# Apply the defaults for each unicorn install
38
install['config'] ||= {}
49
%w(rack_env user group pid service command).each do |k|
510
install[k] ||= node['unicorn'][k]
@@ -8,49 +13,34 @@
813
install['config'][k] ||= node['unicorn']['config'][k]
914
end
1015

11-
# installure defaults, tricky since some defaults are dependant on others and we have interpolation!
12-
parsed_pid = install['pid'] .is_a?(Proc) ? install['pid'] .call(install['app_root']) : install['pid']
13-
parsed_service = install['service'].is_a?(Proc) ? install['service'].call(install['rack_env']) : install['service']
14-
parsed_config = install['config']['path'] .is_a?(Proc) ? install['config']['path'] .call(install['app_root']) : install['config']['path']
15-
parsed_stdout_path = install['config']['stdout_path'].is_a?(Proc) ? install['config']['stdout_path'].call(install['app_root']) : install['config']['stdout_path']
16-
parsed_stderr_path = install['config']['stderr_path'].is_a?(Proc) ? install['config']['stderr_path'].call(install['app_root']) : install['config']['stderr_path']
17-
parsed_command = install['command'].is_a?(Proc) ? install['command'].call(install['app_root'], install['rack_env'], parsed_config) : install['command']
18-
19-
# Setup the boot time flags
20-
bash "update-rc.d #{parsed_service} defaults" do
21-
user 'root'
22-
code "update-rc.d #{parsed_service} defaults"
23-
action :nothing
24-
end
25-
2616
# Create the init.d script
27-
template "/etc/init.d/#{parsed_service}" do
17+
template "/etc/init.d/#{install['service']}" do
2818
source 'unicorn.erb'
2919
variables(
3020
:root => install['app_root'],
3121
:env => install['rack_env'],
3222
:user => install['user'],
33-
:pid => parsed_pid,
34-
:command => parsed_command
23+
:pid => install['pid'],
24+
:command => install['command']
3525
)
3626
mode '775'
37-
notifies :run, resources(:bash => "update-rc.d #{parsed_service} defaults")
3827
end
3928

40-
# Setup the chef service
41-
service parsed_service do
29+
# Setup the service to run at boot. We can't start it yet cos no config,
30+
# but we need to enable it so the config can notify the restarter.
31+
service install['service'] do
4232
supports [:start, :restart, :reload, :stop, :status]
4333
action :enable
4434
end
4535

4636
# Create the install if necessary
47-
template parsed_config do
37+
template install['config']['path'] do
4838
only_if { install['config']['generate'] }
4939
source 'config.rb.erb'
5040
user install['user']
5141
group install['group']
5242
variables(
53-
:identifier => parsed_service,
43+
:identifier => install['service'],
5444
:listen => install['config']['listen'],
5545
:user => install['user'],
5646
:group => install['group'],
@@ -61,15 +51,16 @@
6151
:before_exec => install['config']['before_exec'],
6252
:before_fork => install['config']['before_fork'],
6353
:after_fork => install['config']['after_fork'],
64-
:pid => parsed_pid,
65-
:stderr_path => parsed_stderr_path,
66-
:stdout_path => parsed_stdout_path
54+
:pid => install['pid'],
55+
:stderr_path => install['config']['stderr_path'],
56+
:stdout_path => install['config']['stdout_path']
6757
)
6858
mode '755'
69-
notifies :restart, resources(:service => parsed_service), :delayed
59+
notifies :restart, resources(:service => install['service']), :delayed
7060
end
7161

72-
service parsed_service do
62+
# Start 'er up.
63+
service install['service'] do
7364
action :start
7465
end
7566
end

0 commit comments

Comments
 (0)
Please sign in to comment.