|
1 | 1 | 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 |
3 | 8 | install['config'] ||= {}
|
4 | 9 | %w(rack_env user group pid service command).each do |k|
|
5 | 10 | install[k] ||= node['unicorn'][k]
|
|
8 | 13 | install['config'][k] ||= node['unicorn']['config'][k]
|
9 | 14 | end
|
10 | 15 |
|
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 |
| - |
26 | 16 | # Create the init.d script
|
27 |
| - template "/etc/init.d/#{parsed_service}" do |
| 17 | + template "/etc/init.d/#{install['service']}" do |
28 | 18 | source 'unicorn.erb'
|
29 | 19 | variables(
|
30 | 20 | :root => install['app_root'],
|
31 | 21 | :env => install['rack_env'],
|
32 | 22 | :user => install['user'],
|
33 |
| - :pid => parsed_pid, |
34 |
| - :command => parsed_command |
| 23 | + :pid => install['pid'], |
| 24 | + :command => install['command'] |
35 | 25 | )
|
36 | 26 | mode '775'
|
37 |
| - notifies :run, resources(:bash => "update-rc.d #{parsed_service} defaults") |
38 | 27 | end
|
39 | 28 |
|
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 |
42 | 32 | supports [:start, :restart, :reload, :stop, :status]
|
43 | 33 | action :enable
|
44 | 34 | end
|
45 | 35 |
|
46 | 36 | # Create the install if necessary
|
47 |
| - template parsed_config do |
| 37 | + template install['config']['path'] do |
48 | 38 | only_if { install['config']['generate'] }
|
49 | 39 | source 'config.rb.erb'
|
50 | 40 | user install['user']
|
51 | 41 | group install['group']
|
52 | 42 | variables(
|
53 |
| - :identifier => parsed_service, |
| 43 | + :identifier => install['service'], |
54 | 44 | :listen => install['config']['listen'],
|
55 | 45 | :user => install['user'],
|
56 | 46 | :group => install['group'],
|
|
61 | 51 | :before_exec => install['config']['before_exec'],
|
62 | 52 | :before_fork => install['config']['before_fork'],
|
63 | 53 | :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'] |
67 | 57 | )
|
68 | 58 | mode '755'
|
69 |
| - notifies :restart, resources(:service => parsed_service), :delayed |
| 59 | + notifies :restart, resources(:service => install['service']), :delayed |
70 | 60 | end
|
71 | 61 |
|
72 |
| - service parsed_service do |
| 62 | + # Start 'er up. |
| 63 | + service install['service'] do |
73 | 64 | action :start
|
74 | 65 | end
|
75 | 66 | end
|
0 commit comments