microwave 0.1004.4 → 0.1004.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/README.rdoc +0 -3
  2. data/lib/chef/client.rb +2 -11
  3. data/lib/chef/platform.rb +1 -192
  4. data/lib/chef/providers.rb +0 -68
  5. data/lib/chef/resources.rb +0 -36
  6. data/lib/chef/version.rb +1 -1
  7. metadata +123 -239
  8. data/lib/chef/provider/breakpoint.rb +0 -31
  9. data/lib/chef/provider/cron.rb +0 -186
  10. data/lib/chef/provider/cron/solaris.rb +0 -195
  11. data/lib/chef/provider/deploy.rb +0 -343
  12. data/lib/chef/provider/deploy/revision.rb +0 -80
  13. data/lib/chef/provider/deploy/timestamped.rb +0 -33
  14. data/lib/chef/provider/env.rb +0 -152
  15. data/lib/chef/provider/env/windows.rb +0 -75
  16. data/lib/chef/provider/erl_call.rb +0 -101
  17. data/lib/chef/provider/git.rb +0 -243
  18. data/lib/chef/provider/group.rb +0 -133
  19. data/lib/chef/provider/group/aix.rb +0 -70
  20. data/lib/chef/provider/group/dscl.rb +0 -121
  21. data/lib/chef/provider/group/gpasswd.rb +0 -53
  22. data/lib/chef/provider/group/groupadd.rb +0 -81
  23. data/lib/chef/provider/group/pw.rb +0 -84
  24. data/lib/chef/provider/group/suse.rb +0 -53
  25. data/lib/chef/provider/group/usermod.rb +0 -57
  26. data/lib/chef/provider/group/windows.rb +0 -79
  27. data/lib/chef/provider/ifconfig.rb +0 -134
  28. data/lib/chef/provider/log.rb +0 -54
  29. data/lib/chef/provider/mdadm.rb +0 -91
  30. data/lib/chef/provider/mount.rb +0 -114
  31. data/lib/chef/provider/mount/mount.rb +0 -240
  32. data/lib/chef/provider/mount/windows.rb +0 -81
  33. data/lib/chef/provider/ohai.rb +0 -42
  34. data/lib/chef/provider/package.rb +0 -163
  35. data/lib/chef/provider/package/apt.rb +0 -135
  36. data/lib/chef/provider/package/dpkg.rb +0 -115
  37. data/lib/chef/provider/package/easy_install.rb +0 -136
  38. data/lib/chef/provider/package/freebsd.rb +0 -125
  39. data/lib/chef/provider/package/macports.rb +0 -105
  40. data/lib/chef/provider/package/pacman.rb +0 -101
  41. data/lib/chef/provider/package/portage.rb +0 -135
  42. data/lib/chef/provider/package/rpm.rb +0 -104
  43. data/lib/chef/provider/package/rubygems.rb +0 -465
  44. data/lib/chef/provider/package/solaris.rb +0 -130
  45. data/lib/chef/provider/package/yum.rb +0 -1128
  46. data/lib/chef/provider/package/zypper.rb +0 -144
  47. data/lib/chef/provider/route.rb +0 -193
  48. data/lib/chef/provider/ruby_block.rb +0 -34
  49. data/lib/chef/provider/script.rb +0 -55
  50. data/lib/chef/provider/service.rb +0 -122
  51. data/lib/chef/provider/service/arch.rb +0 -116
  52. data/lib/chef/provider/service/debian.rb +0 -130
  53. data/lib/chef/provider/service/freebsd.rb +0 -154
  54. data/lib/chef/provider/service/gentoo.rb +0 -53
  55. data/lib/chef/provider/service/init.rb +0 -71
  56. data/lib/chef/provider/service/insserv.rb +0 -52
  57. data/lib/chef/provider/service/redhat.rb +0 -60
  58. data/lib/chef/provider/service/simple.rb +0 -120
  59. data/lib/chef/provider/service/solaris.rb +0 -85
  60. data/lib/chef/provider/service/systemd.rb +0 -102
  61. data/lib/chef/provider/service/upstart.rb +0 -198
  62. data/lib/chef/provider/service/windows.rb +0 -146
  63. data/lib/chef/provider/subversion.rb +0 -197
  64. data/lib/chef/provider/user.rb +0 -186
  65. data/lib/chef/provider/user/dscl.rb +0 -280
  66. data/lib/chef/provider/user/pw.rb +0 -113
  67. data/lib/chef/provider/user/useradd.rb +0 -137
  68. data/lib/chef/provider/user/windows.rb +0 -124
  69. data/lib/chef/resource/apt_package.rb +0 -34
  70. data/lib/chef/resource/bash.rb +0 -33
  71. data/lib/chef/resource/breakpoint.rb +0 -35
  72. data/lib/chef/resource/cron.rb +0 -188
  73. data/lib/chef/resource/csh.rb +0 -33
  74. data/lib/chef/resource/deploy.rb +0 -380
  75. data/lib/chef/resource/deploy_revision.rb +0 -40
  76. data/lib/chef/resource/dpkg_package.rb +0 -34
  77. data/lib/chef/resource/easy_install_package.rb +0 -57
  78. data/lib/chef/resource/erl_call.rb +0 -83
  79. data/lib/chef/resource/freebsd_package.rb +0 -35
  80. data/lib/chef/resource/gem_package.rb +0 -53
  81. data/lib/chef/resource/git.rb +0 -46
  82. data/lib/chef/resource/group.rb +0 -70
  83. data/lib/chef/resource/ifconfig.rb +0 -134
  84. data/lib/chef/resource/log.rb +0 -62
  85. data/lib/chef/resource/macports_package.rb +0 -29
  86. data/lib/chef/resource/mdadm.rb +0 -82
  87. data/lib/chef/resource/mount.rb +0 -134
  88. data/lib/chef/resource/ohai.rb +0 -40
  89. data/lib/chef/resource/package.rb +0 -80
  90. data/lib/chef/resource/pacman_package.rb +0 -33
  91. data/lib/chef/resource/perl.rb +0 -33
  92. data/lib/chef/resource/portage_package.rb +0 -33
  93. data/lib/chef/resource/python.rb +0 -33
  94. data/lib/chef/resource/route.rb +0 -135
  95. data/lib/chef/resource/rpm_package.rb +0 -34
  96. data/lib/chef/resource/ruby.rb +0 -33
  97. data/lib/chef/resource/ruby_block.rb +0 -40
  98. data/lib/chef/resource/scm.rb +0 -147
  99. data/lib/chef/resource/script.rb +0 -60
  100. data/lib/chef/resource/service.rb +0 -160
  101. data/lib/chef/resource/solaris_package.rb +0 -36
  102. data/lib/chef/resource/subversion.rb +0 -36
  103. data/lib/chef/resource/timestamped_deploy.rb +0 -31
  104. data/lib/chef/resource/user.rb +0 -130
  105. data/lib/chef/resource/yum_package.rb +0 -63
@@ -1,31 +0,0 @@
1
- #
2
- # Author:: Daniel DeLeo (<dan@kallistec.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- class Chef
20
- class Provider
21
- class Breakpoint < Chef::Provider
22
-
23
- def load_current_resource
24
- end
25
-
26
- def action_break
27
- end
28
-
29
- end
30
- end
31
- end
@@ -1,186 +0,0 @@
1
- #
2
- # Author:: Bryan McLellan (btm@loftninjas.org)
3
- # Copyright:: Copyright (c) 2009 Bryan McLellan
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require 'chef/log'
20
- require 'chef/mixin/command'
21
- require 'chef/provider'
22
-
23
- class Chef
24
- class Provider
25
- class Cron < Chef::Provider
26
- include Chef::Mixin::Command
27
-
28
- CRON_PATTERN = /([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s(.*)/
29
-
30
- def initialize(new_resource, run_context)
31
- super(new_resource, run_context)
32
- @cron_exists = false
33
- @cron_empty = false
34
- end
35
- attr_accessor :cron_exists, :cron_empty
36
-
37
- def load_current_resource
38
- crontab_lines = []
39
- @current_resource = Chef::Resource::Cron.new(@new_resource.name)
40
- @current_resource.user(@new_resource.user)
41
- status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
42
- stdout.each_line { |line| crontab_lines << line }
43
- end
44
- if status.exitstatus > 1
45
- raise Chef::Exceptions::Cron, "Error determining state of #{@new_resource.name}, exit: #{status.exitstatus}"
46
- elsif status.exitstatus == 0
47
- cron_found = false
48
- crontab_lines.each do |line|
49
- case line.chomp
50
- when "# Chef Name: #{@new_resource.name}"
51
- Chef::Log.debug("Found cron '#{@new_resource.name}'")
52
- cron_found = true
53
- @cron_exists = true
54
- next
55
- when /^MAILTO=(\S*)/
56
- @current_resource.mailto($1) if cron_found
57
- next
58
- when /^PATH=(\S*)/
59
- @current_resource.path($1) if cron_found
60
- next
61
- when /^SHELL=(\S*)/
62
- @current_resource.shell($1) if cron_found
63
- next
64
- when /^HOME=(\S*)/
65
- @current_resource.home($1) if cron_found
66
- next
67
- when CRON_PATTERN
68
- if cron_found
69
- @current_resource.minute($1)
70
- @current_resource.hour($2)
71
- @current_resource.day($3)
72
- @current_resource.month($4)
73
- @current_resource.weekday($5)
74
- @current_resource.command($6)
75
- cron_found=false
76
- end
77
- next
78
- else
79
- next
80
- end
81
- end
82
- Chef::Log.debug("Cron '#{@new_resource.name}' not found") unless @cron_exists
83
- elsif status.exitstatus == 1
84
- Chef::Log.debug("Cron empty for '#{@new_resource.user}'")
85
- @cron_empty = true
86
- end
87
-
88
- @current_resource
89
- end
90
-
91
- def compare_cron
92
- [ :minute, :hour, :day, :month, :weekday, :command, :mailto, :path, :shell, :home ].any? do |cron_var|
93
- !@new_resource.send(cron_var).nil? && @new_resource.send(cron_var) != @current_resource.send(cron_var)
94
- end
95
- end
96
-
97
- def action_create
98
- crontab = String.new
99
- newcron = String.new
100
- cron_found = false
101
-
102
- newcron << "# Chef Name: #{new_resource.name}\n"
103
- [ :mailto, :path, :shell, :home ].each do |v|
104
- newcron << "#{v.to_s.upcase}=#{@new_resource.send(v)}\n" if @new_resource.send(v)
105
- end
106
- newcron << "#{@new_resource.minute} #{@new_resource.hour} #{@new_resource.day} #{@new_resource.month} #{@new_resource.weekday} #{@new_resource.command}\n"
107
-
108
- if @cron_exists
109
- unless compare_cron
110
- Chef::Log.debug("Skipping existing cron entry '#{@new_resource.name}'")
111
- return
112
- end
113
- status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
114
- stdout.each_line do |line|
115
- case line.chomp
116
- when "# Chef Name: #{@new_resource.name}"
117
- cron_found = true
118
- next
119
- when CRON_PATTERN
120
- if cron_found
121
- cron_found = false
122
- crontab << newcron
123
- next
124
- end
125
- else
126
- next if cron_found
127
- end
128
- crontab << line
129
- end
130
- end
131
-
132
- status = $testrun || popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
133
- crontab.each_line { |line| stdin.puts "#{line}" }
134
- end
135
- Chef::Log.info("#{@new_resource} updated crontab entry")
136
- @new_resource.updated_by_last_action(true)
137
- else
138
- unless @cron_empty
139
- status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
140
- stdout.each { |line| crontab << line }
141
- end
142
- end
143
-
144
- crontab << newcron
145
-
146
- status = $testrun || popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
147
- crontab.each_line { |line| stdin.puts "#{line}" }
148
- end
149
- Chef::Log.info("#{@new_resource} added crontab entry")
150
- @new_resource.updated_by_last_action(true)
151
- end
152
- end
153
-
154
- def action_delete
155
- if @cron_exists
156
- crontab = String.new
157
- cron_found = false
158
- status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
159
- stdout.each_line do |line|
160
- case line.chomp
161
- when "# Chef Name: #{@new_resource.name}"
162
- cron_found = true
163
- next
164
- when CRON_PATTERN
165
- if cron_found
166
- cron_found = false
167
- next
168
- end
169
- else
170
- next if cron_found
171
- end
172
- crontab << line
173
- end
174
- end
175
-
176
- status = $testrun || popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
177
- crontab.each_line { |line| stdin.puts "#{line}" }
178
- end
179
- Chef::Log.info("#{@new_resource} deleted crontab entry")
180
- @new_resource.updated_by_last_action(true)
181
- end
182
- end
183
-
184
- end
185
- end
186
- end
@@ -1,195 +0,0 @@
1
- #
2
- # Author:: Bryan McLellan (btm@loftninjas.org)
3
- # Author:: Toomas Pelberg (toomasp@gmx.net)
4
- # Copyright:: Copyright (c) 2009 Bryan McLellan
5
- # Copyright:: Copyright (c) 2010 Toomas Pelberg
6
- # License:: Apache License, Version 2.0
7
- #
8
- # Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- # See the License for the specific language governing permissions and
18
- # limitations under the License.
19
- #
20
-
21
- require 'chef/log'
22
- require 'chef/mixin/command'
23
- require 'chef/provider'
24
-
25
- class Chef
26
- class Provider
27
- class Cron
28
- class Solaris < Chef::Provider::Cron
29
- include Chef::Mixin::Command
30
-
31
- CRON_PATTERN = /([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s(.*)/
32
-
33
- def initialize(new_resource, run_context)
34
- super(new_resource, run_context)
35
- @cron_exists = false
36
- @cron_empty = false
37
- end
38
- attr_accessor :cron_exists, :cron_empty
39
-
40
- def load_current_resource
41
- crontab_lines = []
42
- @current_resource = Chef::Resource::Cron.new(@new_resource.name)
43
- @current_resource.user(@new_resource.user)
44
- status = popen4("crontab -l #{@new_resource.user}") do |pid, stdin, stdout, stderr|
45
- stdout.each_line { |line| crontab_lines << line }
46
- end
47
- if status.exitstatus > 1
48
- raise Chef::Exceptions::Cron, "Error determining state of #{@new_resource.name}, exit: #{status.exitstatus}"
49
- elsif status.exitstatus == 0
50
- cron_found = false
51
- crontab_lines.each do |line|
52
- case line.chomp
53
- when "# Chef Name: #{@new_resource.name}"
54
- Chef::Log.debug("#{@new_resource} found cron '#{@new_resource.name}'")
55
- cron_found = true
56
- @cron_exists = true
57
- next
58
- when /^MAILTO=(\S*)/
59
- @current_resource.mailto($1) if cron_found
60
- next
61
- when /^PATH=(\S*)/
62
- @current_resource.path($1) if cron_found
63
- next
64
- when /^SHELL=(\S*)/
65
- @current_resource.shell($1) if cron_found
66
- next
67
- when /^HOME=(\S*)/
68
- @current_resource.home($1) if cron_found
69
- next
70
- when CRON_PATTERN
71
- if cron_found
72
- @current_resource.minute($1)
73
- @current_resource.hour($2)
74
- @current_resource.day($3)
75
- @current_resource.month($4)
76
- @current_resource.weekday($5)
77
- @current_resource.command($6)
78
- cron_found=false
79
- end
80
- next
81
- else
82
- next
83
- end
84
- end
85
- Chef::Log.debug("#{@new_resource} cron '#{@new_resource.name}' not found") unless @cron_exists
86
- elsif status.exitstatus == 1
87
- Chef::Log.debug("#{@new_resource} cron empty for '#{@new_resource.user}'")
88
- @cron_empty = true
89
- end
90
-
91
- @current_resource
92
- end
93
-
94
- def compare_cron
95
- [ :minute, :hour, :day, :month, :weekday, :command, :mailto, :path, :shell, :home ].any? do |cron_var|
96
- !@new_resource.send(cron_var).nil? && @new_resource.send(cron_var) != @current_resource.send(cron_var)
97
- end
98
- end
99
-
100
- def write_crontab(crontab)
101
- tempcron = Tempfile.new("chef-cron")
102
- tempcron << crontab
103
- tempcron.flush
104
- tempcron.chmod(0644)
105
- status = run_command(:command => "/usr/bin/crontab #{tempcron.path}",:user => @new_resource.user)
106
- if(status == 0)
107
- @new_resource.updated_by_last_action(true)
108
- else
109
- @new_resource.updated_by_last_action(false)
110
- end
111
- tempcron.close!
112
- return status
113
- end
114
-
115
- def action_create
116
- crontab = String.new
117
- newcron = String.new
118
- cron_found = false
119
-
120
- newcron << "# Chef Name: #{new_resource.name}\n"
121
- [ :mailto, :path, :shell, :home ].each do |v|
122
- newcron << "#{v.to_s.upcase}=#{@new_resource.send(v)}\n" if @new_resource.send(v)
123
- end
124
- newcron << "#{@new_resource.minute} #{@new_resource.hour} #{@new_resource.day} #{@new_resource.month} #{@new_resource.weekday} #{@new_resource.command}\n"
125
-
126
- if @cron_exists
127
- unless compare_cron
128
- Chef::Log.debug("#{@new_resource} skipping existing cron entry '#{@new_resource.name}'")
129
- return
130
- end
131
- status = popen4("crontab -l #{@new_resource.user}") do |pid, stdin, stdout, stderr|
132
- stdout.each_line do |line|
133
- case line.chomp
134
- when "# Chef Name: #{@new_resource.name}"
135
- cron_found = true
136
- next
137
- when CRON_PATTERN
138
- if cron_found
139
- cron_found = false
140
- crontab << newcron
141
- next
142
- end
143
- else
144
- next if cron_found
145
- end
146
- crontab << line
147
- end
148
- end
149
-
150
- status = write_crontab(crontab)
151
- Chef::Log.info("#{@new_resource} updated crontab entry")
152
- else
153
- unless @cron_empty
154
- status = popen4("crontab -l #{@new_resource.user}") do |pid, stdin, stdout, stderr|
155
- stdout.each { |line| crontab << line }
156
- end
157
- end
158
-
159
- crontab << newcron
160
- status = write_crontab(crontab)
161
- Chef::Log.info("#{@new_resource} added crontab entry")
162
- end
163
- end
164
-
165
- def action_delete
166
- if @cron_exists
167
- crontab = String.new
168
- cron_found = false
169
- status = popen4("crontab -l #{@new_resource.user}") do |pid, stdin, stdout, stderr|
170
- stdout.each_line do |line|
171
- case line.chomp
172
- when "# Chef Name: #{@new_resource.name}"
173
- cron_found = true
174
- next
175
- when CRON_PATTERN
176
- if cron_found
177
- cron_found = false
178
- next
179
- end
180
- else
181
- next if cron_found
182
- end
183
- crontab << line
184
- end
185
- end
186
-
187
- status = write_crontab(crontab)
188
- Chef::Log.info("#{@new_resource} deleted crontab entry")
189
- end
190
- end
191
-
192
- end
193
- end
194
- end
195
- end
@@ -1,343 +0,0 @@
1
- #
2
- # Author:: Daniel DeLeo (<dan@kallistec.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require "chef/mixin/command"
20
- require "chef/mixin/from_file"
21
- require "chef/provider/git"
22
- require "chef/provider/subversion"
23
-
24
- class Chef
25
- class Provider
26
- class Deploy < Chef::Provider
27
-
28
- include Chef::Mixin::FromFile
29
- include Chef::Mixin::Command
30
-
31
- attr_reader :scm_provider, :release_path
32
-
33
- def initialize(new_resource, run_context)
34
- super(new_resource, run_context)
35
-
36
- @scm_provider = new_resource.scm_provider.new(new_resource, run_context)
37
-
38
- # @configuration is not used by Deploy, it is only for backwards compat with
39
- # chef-deploy or capistrano hooks that might use it to get environment information
40
- @configuration = @new_resource.to_hash
41
- @configuration[:environment] = @configuration[:environment] && @configuration[:environment]["RAILS_ENV"]
42
- end
43
-
44
- def load_current_resource
45
- @release_path = @new_resource.deploy_to + "/releases/#{release_slug}"
46
- end
47
-
48
- def sudo(command,&block)
49
- execute(command, &block)
50
- end
51
-
52
- def run(command, &block)
53
- exec = execute(command, &block)
54
- exec.user(@new_resource.user) if @new_resource.user
55
- exec.group(@new_resource.group) if @new_resource.group
56
- exec.cwd(release_path) unless exec.cwd
57
- exec.environment(@new_resource.environment) unless exec.environment
58
- exec
59
- end
60
-
61
- def action_deploy
62
- if all_releases.include?(release_path)
63
- if all_releases[-1] == release_path
64
- Chef::Log.debug("#{@new_resource} is the latest version")
65
- else
66
- action_rollback
67
- end
68
- else
69
- deploy
70
- @new_resource.updated_by_last_action(true)
71
- end
72
- end
73
-
74
- def action_force_deploy
75
- if all_releases.include?(release_path)
76
- FileUtils.rm_rf(release_path)
77
- Chef::Log.info("#{@new_resource} forcing deploy of already deployed app at #{release_path}")
78
- end
79
- deploy
80
- @new_resource.updated_by_last_action(true)
81
- end
82
-
83
- def action_rollback
84
- if release_path
85
- rp_index = all_releases.index(release_path)
86
- raise RuntimeError, "There is no release to rollback to!" unless rp_index
87
- rp_index += 1
88
- releases_to_nuke = all_releases[rp_index..-1]
89
- else
90
- @release_path = all_releases[-2]
91
- raise RuntimeError, "There is no release to rollback to!" unless @release_path
92
- releases_to_nuke = [ all_releases.last ]
93
- end
94
-
95
- Chef::Log.info "#{@new_resource} rolling back to previous release #{release_path}"
96
- symlink
97
- Chef::Log.info "#{@new_resource} restarting with previous release"
98
- restart
99
- releases_to_nuke.each do |i|
100
- Chef::Log.info "#{@new_resource} removing release: #{i}"
101
- FileUtils.rm_rf i
102
- release_deleted(i)
103
- end
104
- @new_resource.updated_by_last_action(true)
105
- end
106
-
107
- def deploy
108
- enforce_ownership
109
- update_cached_repo
110
- copy_cached_repo
111
- install_gems
112
- enforce_ownership
113
- callback(:before_migrate, @new_resource.before_migrate)
114
- migrate
115
- callback(:before_symlink, @new_resource.before_symlink)
116
- symlink
117
- callback(:before_restart, @new_resource.before_restart)
118
- restart
119
- callback(:after_restart, @new_resource.after_restart)
120
- cleanup!
121
- Chef::Log.info "#{@new_resource} deployed to #{@new_resource.deploy_to}"
122
- end
123
-
124
- def callback(what, callback_code=nil)
125
- @collection = Chef::ResourceCollection.new
126
- case callback_code
127
- when Proc
128
- Chef::Log.info "#{@new_resource} running callback #{what}"
129
- recipe_eval(&callback_code)
130
- when String
131
- callback_file = "#{release_path}/#{callback_code}"
132
- unless ::File.exist?(callback_file)
133
- raise RuntimeError, "Can't find your callback file #{callback_file}"
134
- end
135
- run_callback_from_file(callback_file)
136
- when nil
137
- run_callback_from_file("#{release_path}/deploy/#{what}.rb")
138
- else
139
- raise RuntimeError, "You gave me a callback I don't know what to do with: #{callback_code.inspect}"
140
- end
141
- end
142
-
143
- def migrate
144
- run_symlinks_before_migrate
145
-
146
- if @new_resource.migrate
147
- enforce_ownership
148
-
149
- environment = @new_resource.environment
150
- env_info = environment && environment.map do |key_and_val|
151
- "#{key_and_val.first}='#{key_and_val.last}'"
152
- end.join(" ")
153
-
154
- Chef::Log.info "#{@new_resource} migrating #{@new_resource.user} with environment #{env_info}"
155
- run_command(run_options(:command => @new_resource.migration_command, :cwd=>release_path, :command_log_level => :info))
156
- end
157
- end
158
-
159
- def symlink
160
- purge_tempfiles_from_current_release
161
- link_tempfiles_to_current_release
162
- link_current_release_to_production
163
- Chef::Log.info "#{@new_resource} updated symlinks"
164
- end
165
-
166
- def restart
167
- if restart_cmd = @new_resource.restart_command
168
- if restart_cmd.kind_of?(Proc)
169
- Chef::Log.info("#{@new_resource} restarting app with embedded recipe")
170
- recipe_eval(&restart_cmd)
171
- else
172
- Chef::Log.info("#{@new_resource} restarting app")
173
- run_command(run_options(:command => @new_resource.restart_command, :cwd => @new_resource.current_path))
174
- end
175
- end
176
- end
177
-
178
- def cleanup!
179
- all_releases[0..-6].each do |old_release|
180
- Chef::Log.info "#{@new_resource} removing old release #{old_release}"
181
- FileUtils.rm_rf(old_release)
182
- release_deleted(old_release)
183
- end
184
- end
185
-
186
- def all_releases
187
- Dir.glob(@new_resource.deploy_to + "/releases/*").sort
188
- end
189
-
190
- def update_cached_repo
191
- @scm_provider.load_current_resource
192
- if @new_resource.svn_force_export
193
- svn_force_export
194
- else
195
- run_scm_sync
196
- end
197
- end
198
-
199
- def run_scm_sync
200
- @scm_provider.action_sync
201
- end
202
-
203
- def svn_force_export
204
- Chef::Log.info "#{@new_resource} exporting source repository"
205
- @scm_provider.action_force_export
206
- end
207
-
208
- def copy_cached_repo
209
- FileUtils.mkdir_p(@new_resource.deploy_to + "/releases")
210
- run_command(:command => "cp -RPp #{::File.join(@new_resource.destination, ".")} #{release_path}")
211
- Chef::Log.info "#{@new_resource} copied the cached checkout to #{release_path}"
212
- release_created(release_path)
213
- end
214
-
215
- def enforce_ownership
216
- FileUtils.chown_R(@new_resource.user, @new_resource.group, @new_resource.deploy_to)
217
- Chef::Log.info("#{@new_resource} set user to #{@new_resource.user}") if @new_resource.user
218
- Chef::Log.info("#{@new_resource} set group to #{@new_resource.group}") if @new_resource.group
219
- end
220
-
221
- def link_current_release_to_production
222
- FileUtils.rm_f(@new_resource.current_path)
223
- begin
224
- FileUtils.ln_sf(release_path, @new_resource.current_path)
225
- rescue => e
226
- raise Chef::Exceptions::FileNotFound.new("Cannot symlink current release to production: #{e.message}")
227
- end
228
- Chef::Log.info "#{@new_resource} linked release #{release_path} into production at #{@new_resource.current_path}"
229
- enforce_ownership
230
- end
231
-
232
- def run_symlinks_before_migrate
233
- links_info = @new_resource.symlink_before_migrate.map { |src, dst| "#{src} => #{dst}" }.join(", ")
234
- @new_resource.symlink_before_migrate.each do |src, dest|
235
- begin
236
- FileUtils.ln_sf(@new_resource.shared_path + "/#{src}", release_path + "/#{dest}")
237
- rescue => e
238
- raise Chef::Exceptions::FileNotFound.new("Cannot symlink #{@new_resource.shared_path}/#{src} to #{release_path}/#{dest} before migrate: #{e.message}")
239
- end
240
- end
241
- Chef::Log.info "#{@new_resource} made pre-migration symlinks"
242
- end
243
-
244
- def link_tempfiles_to_current_release
245
- dirs_info = @new_resource.create_dirs_before_symlink.join(",")
246
- @new_resource.create_dirs_before_symlink.each do |dir|
247
- begin
248
- FileUtils.mkdir_p(release_path + "/#{dir}")
249
- rescue => e
250
- raise Chef::Exceptions::FileNotFound.new("Cannot create directory #{dir}: #{e.message}")
251
- end
252
- end
253
- Chef::Log.info("#{@new_resource} created directories before symlinking #{dirs_info}")
254
-
255
- links_info = @new_resource.symlinks.map { |src, dst| "#{src} => #{dst}" }.join(", ")
256
- @new_resource.symlinks.each do |src, dest|
257
- begin
258
- FileUtils.ln_sf(@new_resource.shared_path + "/#{src}", release_path + "/#{dest}")
259
- rescue => e
260
- raise Chef::Exceptions::FileNotFound.new("Cannot symlink shared data #{@new_resource.shared_path}/#{src} to #{release_path}/#{dest}: #{e.message}")
261
- end
262
- end
263
- Chef::Log.info("#{@new_resource} linked shared paths into current release: #{links_info}")
264
- run_symlinks_before_migrate
265
- enforce_ownership
266
- end
267
-
268
- def create_dirs_before_symlink
269
- end
270
-
271
- def purge_tempfiles_from_current_release
272
- log_info = @new_resource.purge_before_symlink.join(", ")
273
- @new_resource.purge_before_symlink.each { |dir| FileUtils.rm_rf(release_path + "/#{dir}") }
274
- Chef::Log.info("#{@new_resource} purged directories in checkout #{log_info}")
275
- end
276
-
277
- protected
278
-
279
- # Internal callback, called after copy_cached_repo.
280
- # Override if you need to keep state externally.
281
- def release_created(release_path)
282
- end
283
-
284
- # Internal callback, called during cleanup! for each old release removed.
285
- # Override if you need to keep state externally.
286
- def release_deleted(release_path)
287
- end
288
-
289
- def release_slug
290
- raise Chef::Exceptions::Override, "You must override release_slug in #{self.to_s}"
291
- end
292
-
293
- def install_gems
294
- gem_resource_collection_runner.converge
295
- end
296
-
297
- def gem_resource_collection_runner
298
- gems_collection = Chef::ResourceCollection.new
299
- gem_packages.each { |rbgem| gems_collection << rbgem }
300
- gems_run_context = run_context.dup
301
- gems_run_context.resource_collection = gems_collection
302
- Chef::Runner.new(gems_run_context)
303
- end
304
-
305
- def gem_packages
306
- return [] unless ::File.exist?("#{release_path}/gems.yml")
307
- gems = YAML.load(IO.read("#{release_path}/gems.yml"))
308
-
309
- gems.map do |g|
310
- r = Chef::Resource::GemPackage.new(g[:name], run_context)
311
- r.version g[:version]
312
- r.action :install
313
- r.source "http://gems.github.com"
314
- r
315
- end
316
- end
317
-
318
- def run_options(run_opts={})
319
- run_opts[:user] = @new_resource.user if @new_resource.user
320
- run_opts[:group] = @new_resource.group if @new_resource.group
321
- run_opts[:environment] = @new_resource.environment if @new_resource.environment
322
- run_opts[:command_log_prepend] = @new_resource.to_s
323
- run_opts[:command_log_level] ||= :debug
324
- if run_opts[:command_log_level] == :info
325
- if STDOUT.tty? && Chef::Log.info?
326
- run_opts[:live_stream] = STDOUT
327
- end
328
- end
329
- run_opts
330
- end
331
-
332
- def run_callback_from_file(callback_file)
333
- if ::File.exist?(callback_file)
334
- Dir.chdir(release_path) do
335
- Chef::Log.info "#{@new_resource} running deploy hook #{callback_file}"
336
- recipe_eval { from_file(callback_file) }
337
- end
338
- end
339
- end
340
-
341
- end
342
- end
343
- end