View | Details | Raw Unified | Return to bug 168656
Collapse All | Expand All

(-)rubygem-chef/Makefile (-1 / +50 lines)
Lines 7-13 Link Here
7
7
8
PORTNAME=	chef
8
PORTNAME=	chef
9
PORTVERSION=	0.10.8
9
PORTVERSION=	0.10.8
10
PORTREVISION=	1
10
PORTREVISION=	2
11
CATEGORIES=	sysutils
11
CATEGORIES=	sysutils
12
MASTER_SITES=	RG
12
MASTER_SITES=	RG
13
13
Lines 34-39 Link Here
34
USE_RUBYGEMS=		yes
34
USE_RUBYGEMS=		yes
35
USE_RUBY_FEATURES=	iconv
35
USE_RUBY_FEATURES=	iconv
36
RUBYGEM_AUTOPLIST=	yes
36
RUBYGEM_AUTOPLIST=	yes
37
REINPLACE_ARGS=		-i ""
37
38
38
PLIST_FILES=	bin/chef-client \
39
PLIST_FILES=	bin/chef-client \
39
		bin/chef-solo \
40
		bin/chef-solo \
Lines 43-46 Link Here
43
SUB_LIST=	RUBY=${RUBY}
44
SUB_LIST=	RUBY=${RUBY}
44
USE_RC_SUBR=	chef_client
45
USE_RC_SUBR=	chef_client
45
46
47
MAN1=	knife-configure.1 knife-cookbook-site.1 knife-status.1 \
48
	knife-search.1 knife-bootstrap.1 knife-index.1 knife-client.1 \
49
	knife-ssh.1 knife-node.1 shef.1 knife.1 knife-data-bag.1 \
50
	knife-environment.1 knife-tag.1 knife-exec.1 knife-role.1 \
51
	knife-cookbook.1
52
MAN8=	chef-solr.8 chef-server-webui.8 chef-expander.8 chef-server.8 \
53
	chef-solo.8 chef-expanderctl.8 chef-client.8
54
55
OPTIONS=	PKGUPGRADE "Use pkgupgrade as a default package provider" Off
56
OPTIONSFILE=	${PORT_DBDIR}/rubygem-${PORTNAME}/options
57
58
.include <bsd.port.options.mk>
59
60
.if defined(WITH_PKGUPGRADE)
61
RUN_DEPENDS+=	bsdadminscripts>0:${PORTSDIR}/sysutils/bsdadminscripts
62
.endif
63
64
post-install:
65
	@${PATCH} -p0 -d ${PREFIX}/${GEM_LIB_DIR} < ${PATCHDIR}/lib-chef-daemon.rb.patch
66
	@${PATCH} -p0 -d ${PREFIX}/${GEM_LIB_DIR} < ${PATCHDIR}/lib-chef-provider-service-freebsd.rb.patch
67
.if defined(WITH_PKGUPGRADE)
68
	@${PATCH} -p0 -d ${PREFIX}/${GEM_LIB_DIR} < ${PATCHDIR}/lib-chef-provider-package-pkgupgrade.rb.patch
69
	@${PATCH} -p0 -d ${PREFIX}/${GEM_LIB_DIR} < ${PATCHDIR}/lib-chef-providers.rb.patch
70
	@${PATCH} -p0 -d ${PREFIX}/${GEM_LIB_DIR} < ${PATCHDIR}/lib-chef-resources.rb.patch
71
	@${PATCH} -p0 -d ${PREFIX}/${GEM_LIB_DIR} < ${PATCHDIR}/lib-chef-resource-pkgupgrade_package.rb.patch
72
	@${PATCH} -p0 -d ${PREFIX}/${GEM_LIB_DIR} < ${PATCHDIR}/lib-chef-platform.patch
73
.endif
74
	@${PATCH} -p0 -d ${PREFIX}/${GEM_LIB_DIR} < ${PATCHDIR}/lib-chef-handler-error_report.patch
75
	@${REINPLACE_CMD} -e 's@/etc@${PREFIX}/etc@' ${PREFIX}/${GEM_LIB_DIR}/lib/chef/application/solo.rb
76
	@${REINPLACE_CMD} -e 's@/etc@${PREFIX}/etc@' ${PREFIX}/${GEM_LIB_DIR}/lib/chef/application/client.rb
77
	@${REINPLACE_CMD} -e 's@/etc@${PREFIX}/etc@' ${PREFIX}/${GEM_LIB_DIR}/lib/chef/encrypted_data_bag_item.rb
78
	@${REINPLACE_CMD} -e 's@/etc@${PREFIX}/etc@' ${PREFIX}/${GEM_LIB_DIR}/lib/chef/shef.rb
79
	@${REINPLACE_CMD} -e 's@/etc@${PREFIX}/etc@' ${PREFIX}/${GEM_LIB_DIR}/lib/chef/config.rb
80
	@${REINPLACE_CMD} -e 's@/etc@${PREFIX}/etc@' ${PREFIX}/${GEM_LIB_DIR}/lib/chef/knife/core/ui.rb
81
	@${REINPLACE_CMD} -e 's@/etc@${PREFIX}/etc@' ${PREFIX}/${GEM_LIB_DIR}/lib/chef/knife/core/bootstrap_context.rb
82
	@${REINPLACE_CMD} -e 's@/etc@${PREFIX}/etc@' ${PREFIX}/${GEM_LIB_DIR}/lib/chef/knife/configure.rb
83
	@${FIND} ${PREFIX}/${GEM_LIB_DIR}/distro/common -type f -exec ${REINPLACE_CMD} -e 's@/etc@${PREFIX}/etc@' {} \;
84
	@${FIND} ${PREFIX}/${GEM_LIB_DIR} -name "*.orig" -delete
85
.if !defined(NO_INSTALL_MANPAGES)
86
.for n in 1 8
87
.for f in ${MAN${n}}
88
	${CP} ${PREFIX}/${GEM_LIB_DIR}/distro/common/man/man${n}/${f} ${PREFIX}/man/man${n}
89
	${CHMOD} ${MANMODE} ${PREFIX}/man/man${n}/${f}
90
	${CHOWN} ${MANOWN}:${MANGRP} ${PREFIX}/man/man${n}/${f}
91
.endfor
92
.endfor
93
.endif
94
46
.include <bsd.port.mk>
95
.include <bsd.port.mk>
(-)rubygem-chef/files/chef_client.in (+6 lines)
Lines 25-30 Link Here
25
: ${chef_client_splay="0"}
25
: ${chef_client_splay="0"}
26
: ${chef_client_logfile="/var/log/chef-client.log"}
26
: ${chef_client_logfile="/var/log/chef-client.log"}
27
: ${chef_client_loglevel="info"}
27
: ${chef_client_loglevel="info"}
28
if [ -f "$chef_client_configfile" ]
29
	then
30
		pidfile=`awk '/^[ \t]*pid_file[ \t]+/ { print $2 }' ${chef_clien
31
t_configfile}`
32
fi
33
: ${chef_client_pidfile=$pidfile}
28
: ${chef_client_pidfile="/var/run/chef-client.pid"}
34
: ${chef_client_pidfile="/var/run/chef-client.pid"}
29
35
30
if [ -n "$chef_client_nodename" ]
36
if [ -n "$chef_client_nodename" ]
(-)rubygem-chef/files/lib-chef-daemon.rb.patch (+102 lines)
Line 0 Link Here
1
--- lib/chef/daemon.rb.dist	2012-04-27 16:37:08.000000000 +0900
2
+++ lib/chef/daemon.rb	2012-05-08 14:31:26.000000000 +0900
3
@@ -32,26 +32,24 @@
4
       #
5
       def daemonize(name)
6
         @name = name
7
-        pid = pid_from_file
8
-        unless running?
9
-          remove_pid_file()
10
-          Chef::Log.info("Daemonizing..")
11
-          begin
12
-            exit if fork
13
-            Process.setsid
14
-            exit if fork
15
-            Chef::Log.info("Forked, in #{Process.pid}. Priveleges: #{Process.euid} #{Process.egid}")
16
-            File.umask Chef::Config[:umask]
17
-            $stdin.reopen("/dev/null")
18
-            $stdout.reopen("/dev/null", "a")
19
-            $stderr.reopen($stdout)
20
-            save_pid_file
21
-            at_exit { remove_pid_file }
22
-          rescue NotImplementedError => e
23
-            Chef::Application.fatal!("There is no fork: #{e.message}")
24
+        Chef::Log.info("Daemonizing..")
25
+        begin
26
+          exit if fork
27
+          Process.setsid
28
+          exit if fork
29
+          Chef::Log.info("Forked, in #{Process.pid}. Priveleges: #{Process.euid} #{Process.egid}")
30
+          File.umask Chef::Config[:umask]
31
+          $stdin.reopen("/dev/null")
32
+          $stdout.reopen("/dev/null", "a")
33
+          $stderr.reopen($stdout)
34
+          read_pid_file
35
+          if running?
36
+            Chef::Application.fatal!("Chef(#{$0}) is already running pid #{@pid}")
37
           end
38
-        else
39
-          Chef::Application.fatal!("Chef is already running pid #{pid}")
40
+          save_pid_file
41
+          at_exit { remove_pid_file }
42
+        rescue NotImplementedError => e
43
+          Chef::Application.fatal!("There is no fork: #{e.message}")
44
         end
45
       end
46
   
47
@@ -62,16 +60,14 @@
48
       # False if Chef is not running
49
       #
50
       def running?
51
-        if pid_from_file.nil?
52
+        if @pid.nil?
53
           false
54
         else
55
-          Process.kill(0, pid_from_file)
56
+          Process.kill(0, @pid)
57
           true
58
         end
59
       rescue Errno::ESRCH, Errno::ENOENT
60
         false
61
-      rescue Errno::EACCES => e
62
-        Chef::Application.fatal!("You don't have access to the PID file at #{pid_file}: #{e.message}")
63
       end
64
       
65
       # Gets the pid file for @name
66
@@ -89,10 +85,19 @@
67
       # nil::
68
       #   Returned if the pid_file does not exist.
69
       #
70
-      def pid_from_file
71
-        File.read(pid_file).chomp.to_i
72
-      rescue Errno::ENOENT, Errno::EACCES
73
-        nil
74
+      def read_pid_file
75
+        @fh = File.open(pid_file, File::RDWR|File::CREAT, 0644)
76
+        @fh.flock(File::LOCK_EX | File::LOCK_NB) || Chef::Application.fatal!("Couldn't lock pidfile #{pid_file}")
77
+        pid = @fh.read.chomp
78
+        if pid =~ /^\d+/
79
+          @pid = pid.to_i
80
+        else
81
+          @pid = nil
82
+        end        
83
+      rescue Errno::EACCES => e
84
+        Chef::Application.fatal!("You don't have access to the PID file at #{pid_file}: #{e.message}")
85
+      rescue Errno::ENOENT
86
+        @pid = nil
87
       end
88
     
89
       # Store the PID on the filesystem
90
@@ -107,7 +112,11 @@
91
         end
92
       
93
         begin
94
-          File.open(file, "w") { |f| f.write(Process.pid.to_s) }
95
+          @fh.rewind
96
+          @fh.write("#{Process.pid.to_s}\n")
97
+          @fh.flush
98
+          @fh.truncate(@fh.pos)
99
+          @fh.close
100
         rescue Errno::EACCES => e
101
           Chef::Application.fatal!("Couldn't write to pidfile #{file}, permission denied: #{e.message}")
102
         end
(-)rubygem-chef/files/lib-chef-handler-error_report.patch (+16 lines)
Line 0 Link Here
1
diff --git a/chef/lib/chef/handler/error_report.rb b/chef/lib/chef/handler/error_report.rb
2
index dc47ed5..d1ed412 100644
3
--- lib/chef/handler/error_report.rb
4
+++ lib/chef/handler/error_report.rb
5
@@ -24,8 +24,9 @@ class Chef
6
     class ErrorReport < ::Chef::Handler
7
 
8
       def report
9
-        Chef::FileCache.store("failed-run-data.json", Chef::JSONCompat.to_json_pretty(data))
10
-        Chef::Log.fatal("Saving node information to #{Chef::FileCache.load("failed-run-data.json", false)}")
11
+        # Chef::FileCache.store("failed-run-data.json", Chef::JSONCompat.to_json_pretty(data))
12
+        # Chef::Log.fatal("Saving node information to #{Chef::FileCache.load("failed-run-data.json", false)}")
13
+        Chef::Log.info("Chef::Handler::ErrorReport is disabled: CHEF-2694")
14
       end
15
 
16
     end
(-)rubygem-chef/files/lib-chef-platform.patch (+11 lines)
Line 0 Link Here
1
--- lib/chef/platform.rb.orig	2010-11-02 15:48:57.000000000 +0900
2
+++ lib/chef/platform.rb	2010-11-02 15:49:12.000000000 +0900
3
@@ -50,7 +50,7 @@
4
           :freebsd => {
5
             :default => {
6
               :group   => Chef::Provider::Group::Pw,
7
-              :package => Chef::Provider::Package::Freebsd,
8
+              :package => Chef::Provider::Package::PkgUpgrade,
9
               :service => Chef::Provider::Service::Freebsd,
10
               :user    => Chef::Provider::User::Pw,
11
               :cron    => Chef::Provider::Cron
(-)rubygem-chef/files/lib-chef-provider-package-pkgupgrade.rb.patch (+402 lines)
Line 0 Link Here
1
--- /dev/null	2011-11-21 16:48:43.000000000 +0900
2
+++ lib/chef/provider/package/pkgupgrade.rb	2011-11-21 16:04:09.951953315 +0900
3
@@ -0,0 +1,399 @@
4
+#
5
+# Author:: Mitsuru Y (<mitsuruy@reallyenglish.com>)
6
+# Copyright:: Copyright (c) 2011 Real English Broadband
7
+# License:: Apache License, Version 2.0
8
+#
9
+# Licensed under the Apache License, Version 2.0 (the "License");
10
+# you may not use this file except in compliance with the License.
11
+# You may obtain a copy of the License at
12
+#
13
+#     http://www.apache.org/licenses/LICENSE-2.0
14
+#
15
+# Unless required by applicable law or agreed to in writing, software
16
+# distributed under the License is distributed on an "AS IS" BASIS,
17
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+# See the License for the specific language governing permissions and
19
+# limitations under the License.
20
+#
21
+
22
+require 'chef/provider/package'
23
+require 'chef/mixin/command'
24
+require 'chef/resource/package'
25
+require 'singleton'
26
+require 'chef/mixin/get_source_from_package'
27
+
28
+class Hash
29
+  def safe_invert
30
+    result = Hash.new{|h,key| h[key] = [] }
31
+    self.each{|key, value|
32
+      result[value] << key
33
+    }
34
+    result
35
+  end
36
+end
37
+
38
+class Chef
39
+  class Provider
40
+    class Package
41
+      class PkgUpgrade < Chef::Provider::Package
42
+
43
+        # Cache for our installed and available packages
44
+
45
+        class PkgCache
46
+          include Chef::Mixin::Command
47
+          include Singleton
48
+
49
+          def initialize
50
+            @pkg_index = Hash.new
51
+            @pkg_index[:name] = Hash.new
52
+            @pkg_index[:version] = Hash.new
53
+            @pkg_index[:origin] = Hash.new
54
+            @pkg_pkgdb = Hash.new
55
+            @pkg_pkgdb[:name] = Hash.new
56
+            @pkg_pkgdb[:version] = Hash.new
57
+
58
+# Next time @pkgdb is accessed:
59
+#  :all       - Trigger updates pkg's cache - this data is slow to gather.
60
+#  :installed - Trigger updates only the local pkg db.
61
+#               Used between client runs for a quick refresh.
62
+#  :none      - Do nothing, a call to one of the reload methods is required.
63
+            @next_refresh = :all
64
+
65
+
66
+            # these are for subsequent runs if we are on an interval
67
+            Chef::Client.when_run_starts do
68
+              PkgCache.instance.reload
69
+            end
70
+          end
71
+
72
+          # Cache management
73
+          #
74
+
75
+          def refresh
76
+            case @next_refresh
77
+            when :none
78
+              return nil
79
+            when :installed
80
+              reset_installed
81
+              # fast
82
+              refresh_pkgdb
83
+            when :all
84
+              reset
85
+              # medium
86
+              refresh_pkgdb
87
+              refresh_index 
88
+            else
89
+              raise ArgumentError, "Unexpected value in next_refresh: #{@next_refresh}"
90
+            end
91
+
92
+            # A reload method must be called before the cache is altered
93
+            @next_refresh = :none
94
+          end
95
+
96
+          def refresh_index
97
+            Chef::Log.debug("#{@new_resource} refresh index")
98
+            run_command_with_systems_locale(
99
+              :command => "uma fetch ftpindex"
100
+            )
101
+            indexfile = ""
102
+            status = popen4("uma env") do |pid, stdin, stdout, stderr|
103
+              stdout.each do |env_var|
104
+                env_var.chomp!
105
+                if env_var =~ /^PKG_INDEX='(.*)'/
106
+                  indexfile = $1
107
+                end
108
+              end
109
+            end
110
+            IO.foreach(indexfile) do |line|
111
+              indexline = line.split("|")
112
+              dir = indexline[0]
113
+              origin = indexline[1].sub(/^\/usr\/ports\//,'')
114
+              pkg_name = pkgversion(dir)
115
+              version = pkg_name[1]
116
+              if version
117
+                @pkg_index[:name][origin] = pkg_name[0]
118
+                @pkg_index[:version][origin] = pkg_name[1]
119
+              end
120
+            end
121
+            @pkg_index[:origin] = @pkg_index[:name].safe_invert
122
+          end
123
+        
124
+          def refresh_pkgdb
125
+            Chef::Log.debug("#{@new_resource} refresh pkgdb")
126
+            status = popen4("pkg_info -Ea") do |pid, stdin, stdout, stderr|
127
+              stdout.each do |pkgname|
128
+                pkgname.chomp!
129
+                pkg_name = pkgversion(pkgname)
130
+                version = pkg_name[1]
131
+                status = popen4("pkg_info -qo #{pkgname}") do |pid, stdin, stdout, stderr|
132
+                  stdout.each do |line|
133
+                    origin = line.chomp
134
+                    @pkg_pkgdb[:name][origin] = pkg_name[0]
135
+                    @pkg_pkgdb[:version][origin] = pkg_name[1]
136
+                  end
137
+                end
138
+              end
139
+            end
140
+          end
141
+        
142
+          def pkgversion(pkgname)
143
+            if /\s/ =~ pkgname
144
+              return nil
145
+        #    raise ArgumentError, "Must not contain whitespace."
146
+            end
147
+        
148
+            if /^(.+)-([^-]+)$/ !~ pkgname
149
+              return nil
150
+        #    raise ArgumentError, "Not in due form: <name>-<version>"
151
+            end
152
+            name = $1
153
+            version = splitversion($2)
154
+            return [name, version]
155
+          end
156
+        
157
+          def splitversion(pkgversion)
158
+            if /[\s-]/ =~ pkgversion    
159
+              return nil
160
+        #    raise ArgumentError, "#{pkgversion}: Must not contain a '-' or whitespace."
161
+            end
162
+        
163
+            if /^([^_,]+)(?:_(\d+))?(?:,(\d+))?$/ !~ pkgversion
164
+              return nil
165
+        #   raise ArgumentError, "#{pkgversion}: Not in due form: '<version>[_<revision>][,<epoch>]'."
166
+             end
167
+        
168
+             version = $1
169
+             revision = $2 ? $2.to_i : 0
170
+             epoch = $3 ? $3.to_i : 0
171
+
172
+             return pkgversion
173
+#             return [version, revision, epoch]
174
+          end
175
+
176
+          def reload
177
+            @next_refresh = :all
178
+          end
179
+
180
+          def reload_installed
181
+            @next_refresh = :installed
182
+          end
183
+
184
+          def reset
185
+            @pkg_index[:name].clear
186
+            @pkg_index[:version].clear
187
+            @pkg_index[:origin].clear
188
+            @pkg_pkgdb[:name].clear
189
+            @pkg_pkgdb[:version].clear
190
+          end
191
+
192
+          def reset_installed
193
+            @pkg_pkgdb[:name].clear
194
+            @pkg_pkgdb[:version].clear
195
+          end
196
+
197
+          # Querying the cache
198
+          #
199
+
200
+          def available_version(package_name)
201
+            refresh
202
+            origin = nil
203
+            if package_name =~ /\//
204
+              origin = package_name
205
+            else
206
+              origin = @pkg_pkgdb[:name].index(package_name)
207
+              unless origin  # not installed
208
+                origins = @pkg_index[:origin][package_name]
209
+                case origins.size
210
+                when 1
211
+                  origin = origins.first
212
+                when 0
213
+                  raise Chef::Exceptions::Package, "Package #{@new_resource} not found."
214
+                else
215
+                  origins.each do |o|
216
+                    if o =~ /^[^\/]*\/#{package_name}$/
217
+                      Chef::Log.warn("#{@new_resource} more than one match and use guessed origin. consider specifying origin. ")
218
+                      origin = o
219
+                      break
220
+                    end
221
+                  end
222
+                  unless origin
223
+                    raise Chef::Exceptions::Package, "Package #{@new_resource} matches multiple packages which origins are #{origins.join(' ')}."
224
+                  end
225
+                end
226
+              end
227
+            end
228
+            if origin
229
+              @pkg_index[:version][origin]
230
+            else
231
+              nil
232
+            end
233
+          end
234
+          alias :candidate_version :available_version
235
+
236
+          def installed_version(package_name)
237
+            refresh
238
+            if package_name =~ /\//
239
+              origin = package_name
240
+            else
241
+              origin = @pkg_pkgdb[:name].index(package_name)
242
+            end
243
+            if origin
244
+              @pkg_pkgdb[:version][origin]
245
+            else
246
+              nil
247
+            end
248
+          end
249
+
250
+        end # PkgCache
251
+
252
+        include Chef::Mixin::GetSourceFromPackage
253
+
254
+        def initialize(new_resource, run_context)
255
+          super
256
+
257
+          @pkg = PkgCache.instance
258
+        end
259
+
260
+        # Extra attributes
261
+        #
262
+
263
+        def flush_cache
264
+          if @new_resource.respond_to?("flush_cache")
265
+            @new_resource.flush_cache
266
+          else
267
+            { :before => false, :after => false }
268
+          end
269
+        end
270
+
271
+        def agree_license
272
+          if @new_resource.respond_to?("agree_license")
273
+            if @new_resource.agree_license
274
+              "yes | "
275
+            else
276
+              ""
277
+            end
278
+          else
279
+            ""
280
+          end
281
+        end
282
+
283
+        # Standard Provider methods for Parent
284
+        #
285
+
286
+        def load_current_resource
287
+          if flush_cache[:before]
288
+            @pkg.reload
289
+          end
290
+
291
+          @current_resource = Chef::Resource::Package.new(@new_resource.name)
292
+          @current_resource.package_name(@new_resource.package_name)
293
+
294
+          if @new_resource.source
295
+            case @new_resource.source
296
+            when /^\//
297
+              unless ::File.exists?(@new_resource.source)
298
+                raise Chef::Exceptions::Package, "Package #{@new_resource.name} not found: #{@new_resource.source}"
299
+              end
300
+            end
301
+
302
+#            Chef::Log.debug("#{@new_resource} checking rpm status")
303
+#            status = popen4("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@new_resource.source}") do |pid, stdin, stdout, stderr|
304
+#              stdout.each do |line|
305
+#                case line
306
+#                when /([\w\d_.-]+)\s([\w\d_.-]+)/
307
+#                  @current_resource.package_name($1)
308
+#                  @new_resource.version($2)
309
+#                end
310
+#              end
311
+#            end
312
+          end
313
+
314
+          if @new_resource.version
315
+            new_resource = "#{@new_resource.package_name}-#{@new_resource.version}"
316
+          else
317
+            new_resource = "#{@new_resource.package_name}"
318
+          end
319
+
320
+          Chef::Log.debug("#{@new_resource} checking package info for #{new_resource}")
321
+
322
+          installed_version = @pkg.installed_version(@new_resource.package_name)
323
+          @current_resource.version(installed_version)
324
+
325
+          @candidate_version = @pkg.candidate_version(@new_resource.package_name)
326
+
327
+          Chef::Log.debug("#{@new_resource} installed version: #{installed_version || "(none)"} candidate version: " +
328
+                          "#{@candidate_version || "(none)"}")
329
+
330
+          @current_resource
331
+        end
332
+
333
+        def install_package(name, version)
334
+          if @new_resource.source && name =~ /^\//
335
+            run_command_with_systems_locale(
336
+              :command => "#{agree_license} pkg_add #{expand_options(@new_resource.options)} #{@new_resource.source}"
337
+            ) 
338
+          else
339
+            if name =~ /\//
340
+              run_command_with_systems_locale(
341
+                :command => "#{agree_license} pkg_upgrade --clean #{expand_options(@new_resource.options)} #{name}"
342
+              )
343
+            else
344
+              run_command_with_systems_locale(
345
+                :command => "#{agree_license} pkg_upgrade --clean #{expand_options(@new_resource.options)} #{name}-#{version}"
346
+              )
347
+            end
348
+          end
349
+          if flush_cache[:after]
350
+            @pkg.reload
351
+          else
352
+            @pkg.reload_installed
353
+          end
354
+        end
355
+
356
+        # Keep upgrades from trying to install an older candidate version. Can happen when a new
357
+        # version is installed then removed from a repository, now the older available version
358
+        # shows up as a viable install candidate.
359
+        #
360
+        # Can be done in upgrade_package but an upgraded from->to log message slips out
361
+        #
362
+        # Hacky - better overall solution? Custom compare in Package provider?
363
+#        def action_upgrade
364
+          # Ensure the candidate is newer
365
+#          if RPMVersion.parse(candidate_version) > RPMVersion.parse(@current_resource.version)
366
+#            super
367
+          # Candidate is older
368
+#          else
369
+#            Chef::Log.debug("#{@new_resource} is at the latest version - nothing to do")
370
+#          end
371
+#        end
372
+
373
+        def upgrade_package(name, version)
374
+          install_package(name, version)
375
+        end
376
+
377
+        def remove_package(name, version)
378
+          if version
379
+            run_command_with_systems_locale(
380
+             :command => "pkg_delete #{expand_options(@new_resource.options)} #{name}-#{version}"
381
+            )
382
+          else
383
+            run_command_with_systems_locale(
384
+             :command => "pkg_delete #{expand_options(@new_resource.options)} #{name}-#{@current_resource.version}"
385
+            )
386
+          end
387
+          if flush_cache[:after]
388
+            @pkg.reload
389
+          else
390
+            @pkg.reload_installed
391
+          end
392
+        end
393
+
394
+        def purge_package(name, version)
395
+          remove_package(name, version)
396
+        end
397
+
398
+
399
+      end
400
+    end
401
+  end
402
+end
(-)rubygem-chef/files/lib-chef-provider-service-freebsd.rb.patch (+13 lines)
Line 0 Link Here
1
diff --git a/chef/lib/chef/provider/service/freebsd.rb b/chef/lib/chef/provider/service/freebsd.rb
2
index 209f1ca..ab72382 100644
3
--- lib/chef/provider/service/freebsd.rb
4
+++ lib/chef/provider/service/freebsd.rb
5
@@ -42,7 +42,7 @@ class Chef
6
             Chef::Log.debug("#{@new_resource} supports status, checking state")
7
 
8
             begin
9
-              if run_command(:command => "#{@init_command} status") == 0
10
+              if run_command(:command => "#{@init_command} onestatus") == 0
11
                 @current_resource.running true
12
               end
13
             rescue Chef::Exceptions::Exec
(-)rubygem-chef/files/lib-chef-providers.rb.patch (+10 lines)
Line 0 Link Here
1
--- lib/chef/providers.rb.org	2011-11-21 17:43:12.194699060 +0900
2
+++ lib/chef/providers.rb	2011-11-21 15:56:58.023058089 +0900
3
@@ -54,6 +54,7 @@
4
 require 'chef/provider/package/freebsd'
5
 require 'chef/provider/package/macports'
6
 require 'chef/provider/package/pacman'
7
+require 'chef/provider/package/pkgupgrade'
8
 require 'chef/provider/package/portage'
9
 require 'chef/provider/package/rpm'
10
 require 'chef/provider/package/rubygems'
(-)rubygem-chef/files/lib-chef-resource-pkgupgrade_package.rb.patch (+57 lines)
Line 0 Link Here
1
--- /dev/null	2011-11-21 16:47:43.000000000 +0900
2
+++ lib/chef/resource/pkgupgrade_package.rb	2011-11-21 15:59:15.255820421 +0900
3
@@ -0,0 +1,54 @@
4
+#
5
+# Author:: Mitsuru Y (<mitsuruy@reallyenglish.com>)
6
+# Copyright:: Copyright (c) 2011 Real English Broadband, Inc.
7
+# License:: Apache License, Version 2.0
8
+#
9
+# Licensed under the Apache License, Version 2.0 (the "License");
10
+# you may not use this file except in compliance with the License.
11
+# You may obtain a copy of the License at
12
+# 
13
+#     http://www.apache.org/licenses/LICENSE-2.0
14
+# 
15
+# Unless required by applicable law or agreed to in writing, software
16
+# distributed under the License is distributed on an "AS IS" BASIS,
17
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+# See the License for the specific language governing permissions and
19
+# limitations under the License.
20
+#
21
+
22
+require 'chef/resource/package'
23
+require 'chef/provider/package/pkgupgrade'
24
+
25
+class Chef
26
+  class Resource
27
+    class PkgupgradePackage < Chef::Resource::Package
28
+
29
+      def initialize(name, run_context=nil)
30
+        super
31
+        @resource_name = :pkgupgrade_package
32
+        @provider = Chef::Provider::Package::PkgUpgrade
33
+        @flush_cache = { :before => false, :after => false }
34
+        @allow_downgrade = false
35
+      end
36
+
37
+      def flush_cache(args={})
38
+        if args.is_a? Array
39
+          args.each { |arg| @flush_cache[arg] = true }
40
+        elsif args.any?
41
+          @flush_cache = args
42
+        else
43
+          @flush_cache
44
+        end
45
+      end
46
+
47
+      def agree_license(arg=nil)
48
+        set_or_return(
49
+          :allow_downgrade,
50
+          arg,
51
+          :kind_of => [ TrueClass, FalseClass ]
52
+        )
53
+      end
54
+
55
+    end
56
+  end
57
+end
(-)rubygem-chef/files/lib-chef-resources.rb.patch (+10 lines)
Line 0 Link Here
1
--- lib/chef/resources.rb.org	2011-11-21 16:54:27.103624659 +0900
2
+++ lib/chef/resources.rb	2011-11-21 15:57:49.055841192 +0900
3
@@ -46,6 +46,7 @@
4
 require 'chef/resource/package'
5
 require 'chef/resource/pacman_package'
6
 require 'chef/resource/perl'
7
+require 'chef/resource/pkgupgrade_package'
8
 require 'chef/resource/portage_package'
9
 require 'chef/resource/python'
10
 require 'chef/resource/remote_directory'

Return to bug 168656