chef 0.8.16 → 0.9.0.a3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of chef might be problematic. Click here for more details.
- data/bin/shef +1 -0
- data/distro/common/man/man1/chef-server-webui.1 +106 -0
- data/distro/common/man/man1/chef-server.1 +0 -1
- data/distro/common/man/man1/chef-solr-indexer.1 +55 -0
- data/distro/common/man/man1/chef-solr.1 +55 -0
- data/distro/common/man/man8/chef-client.8 +4 -2
- data/distro/common/man/man8/chef-solo.8 +1 -2
- data/distro/common/man/man8/chef-solr-rebuild.8 +37 -0
- data/distro/common/man/man8/knife.8 +668 -266
- data/distro/common/man/man8/shef.8 +45 -0
- data/distro/common/markdown/README +3 -0
- data/distro/common/markdown/knife.mkd +520 -0
- data/distro/debian/etc/default/chef-client +4 -0
- data/distro/debian/etc/default/chef-server +6 -0
- data/distro/debian/etc/default/chef-server-webui +6 -0
- data/distro/debian/etc/default/chef-solr +4 -0
- data/distro/debian/etc/default/chef-solr-indexer +4 -0
- data/distro/debian/etc/init.d/chef-client +41 -41
- data/distro/debian/etc/init.d/chef-server +10 -10
- data/distro/debian/etc/init.d/chef-server-webui +121 -0
- data/distro/debian/etc/init.d/chef-solr +177 -0
- data/distro/debian/etc/init.d/chef-solr-indexer +176 -0
- data/distro/redhat/etc/init.d/chef-client +76 -48
- data/distro/redhat/etc/init.d/chef-server +85 -51
- data/distro/redhat/etc/init.d/chef-server-webui +85 -51
- data/distro/redhat/etc/init.d/chef-solr +77 -49
- data/distro/redhat/etc/init.d/chef-solr-indexer +77 -48
- data/distro/redhat/etc/logrotate.d/chef-client +8 -0
- data/distro/redhat/etc/logrotate.d/chef-server +8 -0
- data/distro/redhat/etc/logrotate.d/chef-server-webui +8 -0
- data/distro/redhat/etc/logrotate.d/chef-solr +8 -0
- data/distro/redhat/etc/logrotate.d/chef-solr-indexer +8 -0
- data/distro/redhat/etc/sysconfig/chef-client +9 -4
- data/distro/redhat/etc/sysconfig/chef-server +10 -6
- data/distro/redhat/etc/sysconfig/chef-server-webui +10 -6
- data/distro/redhat/etc/sysconfig/chef-solr +3 -4
- data/distro/redhat/etc/sysconfig/chef-solr-indexer +3 -3
- data/lib/chef.rb +16 -5
- data/lib/chef/application/knife.rb +2 -2
- data/lib/chef/application/solo.rb +1 -7
- data/lib/chef/cache/checksum.rb +12 -5
- data/lib/chef/cache/file_cache_by_checksum.rb +52 -0
- data/lib/chef/checksum.rb +115 -0
- data/lib/chef/client.rb +193 -185
- data/lib/chef/config.rb +9 -1
- data/lib/chef/cookbook/cookbook_collection.rb +43 -0
- data/lib/chef/cookbook/file_system_file_vendor.rb +53 -0
- data/lib/chef/cookbook/file_vendor.rb +47 -0
- data/lib/chef/cookbook/metadata.rb +34 -35
- data/lib/chef/cookbook/metadata/version.rb +1 -1
- data/lib/chef/cookbook_loader.rb +70 -45
- data/lib/chef/cookbook_version.rb +760 -0
- data/lib/chef/couchdb.rb +8 -5
- data/lib/chef/data_bag_item.rb +5 -5
- data/lib/chef/exceptions.rb +10 -0
- data/lib/chef/file_access_control.rb +134 -0
- data/lib/chef/handler.rb +62 -0
- data/lib/chef/handler/json_file.rb +47 -0
- data/lib/chef/knife.rb +14 -2
- data/lib/chef/knife/bootstrap.rb +126 -0
- data/lib/chef/knife/cookbook_bulk_delete.rb +1 -1
- data/lib/chef/knife/cookbook_delete.rb +4 -4
- data/lib/chef/knife/cookbook_download.rb +57 -26
- data/lib/chef/knife/cookbook_metadata.rb +2 -2
- data/lib/chef/knife/cookbook_show.rb +30 -11
- data/lib/chef/knife/cookbook_upload.rb +113 -86
- data/lib/chef/knife/ec2_server_create.rb +146 -0
- data/lib/chef/knife/ec2_server_delete.rb +84 -0
- data/lib/chef/knife/ec2_server_list.rb +82 -0
- data/lib/chef/knife/status.rb +51 -0
- data/lib/chef/mixin/language_include_attribute.rb +16 -11
- data/lib/chef/mixin/language_include_recipe.rb +15 -16
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +17 -20
- data/lib/chef/mixin/shell_out.rb +38 -0
- data/lib/chef/mixins.rb +1 -1
- data/lib/chef/node.rb +190 -63
- data/lib/chef/node/attribute.rb +92 -78
- data/lib/chef/platform.rb +24 -4
- data/lib/chef/provider.rb +28 -10
- data/lib/chef/provider/breakpoint.rb +2 -2
- data/lib/chef/provider/cookbook_file.rb +96 -0
- data/lib/chef/provider/cron.rb +2 -2
- data/lib/chef/provider/deploy.rb +12 -10
- data/lib/chef/provider/env.rb +152 -0
- data/lib/chef/provider/env/windows.rb +75 -0
- data/lib/chef/provider/file.rb +10 -14
- data/lib/chef/provider/group.rb +15 -2
- data/lib/chef/provider/group/dscl.rb +17 -25
- data/lib/chef/provider/group/gpasswd.rb +6 -3
- data/lib/chef/provider/group/pw.rb +3 -7
- data/lib/chef/provider/group/windows.rb +79 -0
- data/lib/chef/provider/link.rb +4 -5
- data/lib/chef/provider/mdadm.rb +25 -18
- data/lib/chef/provider/mount/mount.rb +28 -27
- data/lib/chef/provider/package.rb +35 -35
- data/lib/chef/provider/package/dpkg.rb +13 -10
- data/lib/chef/provider/package/easy_install.rb +6 -6
- data/lib/chef/provider/package/freebsd.rb +17 -51
- data/lib/chef/provider/package/rpm.rb +1 -1
- data/lib/chef/provider/package/rubygems.rb +391 -74
- data/lib/chef/provider/package/yum.rb +2 -2
- data/lib/chef/provider/package/zypper.rb +2 -1
- data/lib/chef/provider/remote_directory.rb +60 -83
- data/lib/chef/provider/remote_file.rb +17 -66
- data/lib/chef/provider/script.rb +20 -9
- data/lib/chef/provider/service.rb +23 -30
- data/lib/chef/provider/service/arch.rb +3 -3
- data/lib/chef/provider/service/debian.rb +22 -17
- data/lib/chef/provider/service/freebsd.rb +4 -4
- data/lib/chef/provider/service/init.rb +2 -2
- data/lib/chef/provider/service/redhat.rb +14 -16
- data/lib/chef/provider/service/simple.rb +7 -3
- data/lib/chef/provider/service/solaris.rb +85 -0
- data/lib/chef/provider/service/upstart.rb +12 -7
- data/lib/chef/provider/service/windows.rb +2 -2
- data/lib/chef/provider/template.rb +133 -118
- data/lib/chef/provider/user.rb +34 -17
- data/lib/chef/provider/user/dscl.rb +117 -114
- data/lib/chef/provider/user/windows.rb +124 -0
- data/lib/chef/providers.rb +7 -0
- data/lib/chef/recipe.rb +39 -20
- data/lib/chef/resource.rb +47 -52
- data/lib/chef/resource/apt_package.rb +4 -4
- data/lib/chef/resource/bash.rb +4 -4
- data/lib/chef/resource/cookbook_file.rb +45 -0
- data/lib/chef/resource/cron.rb +3 -3
- data/lib/chef/resource/csh.rb +4 -4
- data/lib/chef/resource/deploy.rb +3 -3
- data/lib/chef/resource/directory.rb +4 -4
- data/lib/chef/resource/dpkg_package.rb +4 -4
- data/lib/chef/resource/easy_install_package.rb +3 -3
- data/lib/chef/resource/env.rb +58 -0
- data/lib/chef/resource/erl_call.rb +3 -3
- data/lib/chef/resource/execute.rb +3 -3
- data/lib/chef/resource/file.rb +3 -3
- data/lib/chef/resource/freebsd_package.rb +3 -3
- data/lib/chef/resource/gem_package.rb +17 -9
- data/lib/chef/resource/git.rb +3 -3
- data/lib/chef/resource/group.rb +3 -3
- data/lib/chef/resource/http_request.rb +4 -4
- data/lib/chef/resource/ifconfig.rb +3 -3
- data/lib/chef/resource/link.rb +3 -3
- data/lib/chef/resource/log.rb +2 -2
- data/lib/chef/resource/macports_package.rb +2 -2
- data/lib/chef/resource/mdadm.rb +3 -3
- data/lib/chef/resource/mount.rb +2 -2
- data/lib/chef/resource/package.rb +4 -4
- data/lib/chef/resource/pacman_package.rb +4 -4
- data/lib/chef/resource/perl.rb +4 -4
- data/lib/chef/resource/portage_package.rb +4 -4
- data/lib/chef/resource/python.rb +4 -4
- data/lib/chef/resource/remote_directory.rb +3 -3
- data/lib/chef/resource/remote_file.rb +26 -3
- data/lib/chef/resource/route.rb +3 -3
- data/lib/chef/resource/ruby.rb +3 -3
- data/lib/chef/resource/ruby_block.rb +3 -2
- data/lib/chef/resource/scm.rb +7 -5
- data/lib/chef/resource/script.rb +4 -4
- data/lib/chef/resource/service.rb +3 -3
- data/lib/chef/resource/subversion.rb +4 -2
- data/lib/chef/resource/template.rb +3 -3
- data/lib/chef/resource/user.rb +3 -3
- data/lib/chef/resource/yum_package.rb +3 -3
- data/lib/chef/resource_collection.rb +9 -5
- data/lib/chef/resources.rb +2 -0
- data/lib/chef/rest.rb +4 -0
- data/lib/chef/role.rb +2 -0
- data/lib/chef/run_context.rb +108 -0
- data/lib/chef/run_list.rb +75 -98
- data/lib/chef/run_list/run_list_expansion.rb +156 -0
- data/lib/chef/run_list/run_list_item.rb +71 -0
- data/lib/chef/runner.rb +58 -61
- data/lib/chef/sandbox.rb +147 -0
- data/lib/chef/shef.rb +4 -3
- data/lib/chef/shef/ext.rb +12 -4
- data/lib/chef/shef/shef_session.rb +27 -23
- data/lib/chef/shell_out.rb +375 -0
- data/lib/chef/util/windows.rb +56 -0
- data/lib/chef/util/windows/net_group.rb +101 -0
- data/lib/chef/util/windows/net_user.rb +198 -0
- data/lib/chef/version.rb +20 -0
- metadata +112 -22
- data/lib/chef/compile.rb +0 -158
- data/lib/chef/cookbook.rb +0 -201
- data/lib/chef/mixin/generate_url.rb +0 -58
@@ -21,8 +21,8 @@ require 'chef/mixin/command'
|
|
21
21
|
|
22
22
|
class Chef::Provider::Service::Arch < Chef::Provider::Service::Init
|
23
23
|
|
24
|
-
def initialize(
|
25
|
-
super
|
24
|
+
def initialize(new_resource, run_context)
|
25
|
+
super
|
26
26
|
@init_command = "/etc/rc.d/#{@new_resource.service_name}"
|
27
27
|
end
|
28
28
|
|
@@ -106,4 +106,4 @@ class Chef::Provider::Service::Arch < Chef::Provider::Service::Init
|
|
106
106
|
update_daemons(new_daemons)
|
107
107
|
end
|
108
108
|
|
109
|
-
end
|
109
|
+
end
|
@@ -24,38 +24,43 @@ class Chef
|
|
24
24
|
class Provider
|
25
25
|
class Service
|
26
26
|
class Debian < Chef::Provider::Service::Init
|
27
|
+
UPDATE_RC_D_ENABLED_MATCHES = /etc\/rc[\dS].d\/S|not installed/i
|
28
|
+
|
27
29
|
def load_current_resource
|
28
30
|
super
|
29
31
|
|
32
|
+
@current_resource.enabled(service_currently_enabled?)
|
33
|
+
@current_resource
|
34
|
+
end
|
35
|
+
|
36
|
+
def enable_service()
|
37
|
+
run_command(:command => "/usr/sbin/update-rc.d #{@new_resource.service_name} defaults")
|
38
|
+
end
|
39
|
+
|
40
|
+
def disable_service()
|
41
|
+
run_command(:command => "/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
|
42
|
+
end
|
43
|
+
|
44
|
+
def assert_update_rcd_available
|
30
45
|
unless ::File.exists? "/usr/sbin/update-rc.d"
|
31
46
|
raise Chef::Exceptions::Service, "/usr/sbin/update-rc.d does not exist!"
|
32
47
|
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def service_currently_enabled?
|
51
|
+
assert_update_rcd_available
|
33
52
|
|
34
53
|
status = popen4("/usr/sbin/update-rc.d -n -f #{@current_resource.service_name} remove") do |pid, stdin, stdout, stderr|
|
35
|
-
r = /etc\/rc[\dS].d\/S|not installed/i
|
36
54
|
stdout.each_line do |line|
|
37
|
-
if
|
38
|
-
@current_resource.enabled true
|
39
|
-
break
|
40
|
-
else
|
41
|
-
@current_resource.enabled false
|
42
|
-
end
|
55
|
+
return true if line =~ UPDATE_RC_D_ENABLED_MATCHES
|
43
56
|
end
|
44
57
|
end
|
45
58
|
|
46
59
|
unless status.exitstatus == 0
|
47
60
|
raise Chef::Exceptions::Service, "/usr/sbin/update-rc.d -n -f #{@current_resource.service_name} failed - #{status.inspect}"
|
48
61
|
end
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
def enable_service()
|
54
|
-
run_command(:command => "/usr/sbin/update-rc.d #{@new_resource.service_name} defaults")
|
55
|
-
end
|
56
|
-
|
57
|
-
def disable_service()
|
58
|
-
run_command(:command => "/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
|
62
|
+
|
63
|
+
false
|
59
64
|
end
|
60
65
|
|
61
66
|
end
|
@@ -65,11 +65,11 @@ class Chef
|
|
65
65
|
else
|
66
66
|
Chef::Log.debug("#{@new_resource} does not support status and you have not specified a status command, falling back to process table inspection")
|
67
67
|
|
68
|
-
if
|
68
|
+
if node[:command][:ps].nil? or node[:command][:ps].empty?
|
69
69
|
raise Chef::Exceptions::Service, "#{@new_resource}: could not determine how to inspect the process table, please set this nodes 'ps' attribute"
|
70
70
|
end
|
71
71
|
|
72
|
-
status = popen4(
|
72
|
+
status = popen4(node[:command][:ps]) do |pid, stdin, stdout, stderr|
|
73
73
|
r = Regexp.new(@new_resource.pattern)
|
74
74
|
Chef::Log.debug("#{@new_resource}: attempting to match #{@new_resource.pattern} (#{r}) against process table")
|
75
75
|
stdout.each_line do |line|
|
@@ -81,9 +81,9 @@ class Chef
|
|
81
81
|
@current_resource.running false unless @current_resource.running
|
82
82
|
end
|
83
83
|
unless status.exitstatus == 0
|
84
|
-
raise Chef::Exceptions::Service, "Command #{
|
84
|
+
raise Chef::Exceptions::Service, "Command #{node[:command][:ps]} failed"
|
85
85
|
else
|
86
|
-
Chef::Log.debug("#{@new_resource}: #{
|
86
|
+
Chef::Log.debug("#{@new_resource}: #{node[:command][:ps]} exited and parsed successfully, process running: #{@current_resource.running}")
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -25,8 +25,8 @@ class Chef
|
|
25
25
|
class Service
|
26
26
|
class Init < Chef::Provider::Service::Simple
|
27
27
|
|
28
|
-
def initialize(
|
29
|
-
super
|
28
|
+
def initialize(new_resource, run_context)
|
29
|
+
super
|
30
30
|
@init_command = "/etc/init.d/#{@new_resource.service_name}"
|
31
31
|
end
|
32
32
|
|
@@ -18,42 +18,40 @@
|
|
18
18
|
|
19
19
|
require 'chef/provider/service'
|
20
20
|
require 'chef/provider/service/init'
|
21
|
-
require 'chef/mixin/
|
21
|
+
require 'chef/mixin/shell_out'
|
22
22
|
|
23
23
|
class Chef
|
24
24
|
class Provider
|
25
25
|
class Service
|
26
26
|
class Redhat < Chef::Provider::Service::Init
|
27
|
+
include Chef::Mixin::ShellOut
|
27
28
|
|
28
|
-
|
29
|
-
|
29
|
+
CHKCONFIG_ON = /\d:on/
|
30
|
+
|
31
|
+
def initialize(new_resource, run_context)
|
32
|
+
super
|
30
33
|
@init_command = "/sbin/service #{@new_resource.service_name}"
|
34
|
+
@new_resource.supports[:status] = true
|
31
35
|
end
|
32
36
|
|
33
37
|
def load_current_resource
|
34
|
-
super
|
35
|
-
|
36
38
|
unless ::File.exists? "/sbin/chkconfig"
|
37
39
|
raise Chef::Exceptions::Service, "/sbin/chkconfig does not exist!"
|
38
40
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
@current_resource.enabled false
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
41
|
+
|
42
|
+
super
|
43
|
+
|
44
|
+
chkconfig = shell_out!("/sbin/chkconfig --list #{@current_resource.service_name}")
|
45
|
+
@current_resource.enabled(!!(chkconfig.stdout =~ CHKCONFIG_ON))
|
48
46
|
@current_resource
|
49
47
|
end
|
50
48
|
|
51
49
|
def enable_service()
|
52
|
-
|
50
|
+
shell_out! "/sbin/chkconfig #{@new_resource.service_name} on"
|
53
51
|
end
|
54
52
|
|
55
53
|
def disable_service()
|
56
|
-
|
54
|
+
shell_out! "/sbin/chkconfig #{@new_resource.service_name} off"
|
57
55
|
end
|
58
56
|
|
59
57
|
end
|
@@ -51,10 +51,10 @@ class Chef
|
|
51
51
|
end
|
52
52
|
elsif
|
53
53
|
Chef::Log.debug "#{@new_resource}: falling back to process table inspection"
|
54
|
-
if
|
54
|
+
if ps_cmd.nil? or ps_cmd.empty?
|
55
55
|
raise Chef::Exceptions::Service, "#{@new_resource}: could not determine how to inspect the process table, please set this nodes 'command.ps' attribute"
|
56
56
|
end
|
57
|
-
status = popen4(
|
57
|
+
status = popen4(ps_cmd) do |pid, stdin, stdout, stderr|
|
58
58
|
r = Regexp.new(@new_resource.pattern)
|
59
59
|
Chef::Log.debug "#{@new_resource}: attempting to match '#{@new_resource.pattern}' (#{r}) against process list"
|
60
60
|
stdout.each_line do |line|
|
@@ -66,7 +66,7 @@ class Chef
|
|
66
66
|
@current_resource.running false unless @current_resource.running
|
67
67
|
end
|
68
68
|
unless status.exitstatus == 0
|
69
|
-
raise Chef::Exceptions::Service, "Command #{
|
69
|
+
raise Chef::Exceptions::Service, "Command #{ps_cmd} failed"
|
70
70
|
else
|
71
71
|
Chef::Log.debug "#{@new_resource}: running: #{@current_resource.running}"
|
72
72
|
end
|
@@ -108,6 +108,10 @@ class Chef
|
|
108
108
|
raise Chef::Exceptions::Service, "#{self.to_s} requires that reload_command to be set"
|
109
109
|
end
|
110
110
|
end
|
111
|
+
|
112
|
+
def ps_cmd
|
113
|
+
@run_context.node[:command] && @run_context.node[:command][:ps]
|
114
|
+
end
|
111
115
|
end
|
112
116
|
end
|
113
117
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Toomas Pelberg (<toomasp@gmx.net>)
|
3
|
+
# Copyright:: Copyright (c) 2010 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/provider/service'
|
20
|
+
require 'chef/mixin/command'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Provider
|
24
|
+
class Service
|
25
|
+
class Solaris < Chef::Provider::Service
|
26
|
+
|
27
|
+
def initialize(new_resource, run_context=nil)
|
28
|
+
super
|
29
|
+
@init_command = "/usr/sbin/svcadm"
|
30
|
+
@status_command = "/bin/svcs -l"
|
31
|
+
end
|
32
|
+
|
33
|
+
def load_current_resource
|
34
|
+
@current_resource = Chef::Resource::Service.new(@new_resource.name)
|
35
|
+
@current_resource.service_name(@new_resource.service_name)
|
36
|
+
unless ::File.exists? "/bin/svcs"
|
37
|
+
raise Chef::Exceptions::Service, "/bin/svcs does not exist!"
|
38
|
+
end
|
39
|
+
@status = service_status.enabled
|
40
|
+
@current_resource
|
41
|
+
end
|
42
|
+
|
43
|
+
def enable_service
|
44
|
+
run_command(:command => "#{@init_command} enable #{@new_resource.service_name}")
|
45
|
+
return service_status.enabled
|
46
|
+
end
|
47
|
+
|
48
|
+
def disable_service
|
49
|
+
run_command(:command => "#{@init_command} disable #{@new_resource.service_name}")
|
50
|
+
return service_status.enabled
|
51
|
+
end
|
52
|
+
|
53
|
+
alias_method :stop_service, :disable_service
|
54
|
+
alias_method :start_service, :enable_service
|
55
|
+
|
56
|
+
def reload_service
|
57
|
+
run_command(:command => "#{@init_command} refresh #{@new_resource.service_name}")
|
58
|
+
end
|
59
|
+
|
60
|
+
def restart_service
|
61
|
+
disable_service
|
62
|
+
return enable_service
|
63
|
+
end
|
64
|
+
|
65
|
+
def service_status
|
66
|
+
status = popen4("#{@status_command} #{@current_resource.service_name}") do |pid, stdin, stdout, stderr|
|
67
|
+
stdout.each do |line|
|
68
|
+
case line
|
69
|
+
when /state\s+online/
|
70
|
+
@current_resource.enabled(true)
|
71
|
+
@current_resource.running(true)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
unless @current_resource.enabled
|
76
|
+
@current_resource.enabled(false)
|
77
|
+
@current_resource.running(false)
|
78
|
+
end
|
79
|
+
@current_resource
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -25,6 +25,7 @@ class Chef
|
|
25
25
|
class Provider
|
26
26
|
class Service
|
27
27
|
class Upstart < Chef::Provider::Service::Simple
|
28
|
+
UPSTART_STATE_FORMAT = /\w+ \(?(\w+)\)?[\/ ](\w+)/
|
28
29
|
|
29
30
|
# Upstart does more than start or stop a service, creating multiple 'states' [1] that a service can be in.
|
30
31
|
# In chef, when we ask a service to start, we expect it to have started before performing the next step
|
@@ -35,14 +36,18 @@ class Chef
|
|
35
36
|
# [1] http://upstart.ubuntu.com/wiki/JobStates
|
36
37
|
# [2] http://www.netsplit.com/2008/04/27/upstart-05-events/
|
37
38
|
|
38
|
-
def initialize(
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
def initialize(new_resource, run_context)
|
40
|
+
# TODO: re-evaluate if this is needed after integrating cookbook fix
|
41
|
+
raise ArgumentError, "run_context cannot be nil" unless run_context
|
42
|
+
super
|
43
|
+
|
44
|
+
run_context.node
|
45
|
+
|
46
|
+
platform, version = Chef::Platform.find_platform_and_version(run_context.node)
|
42
47
|
case platform
|
43
48
|
when "ubuntu"
|
44
49
|
case version
|
45
|
-
when /8.04/,/8.10/,/9.04/
|
50
|
+
when /8.04/,/8.10/,/9.04/,/10.04/
|
46
51
|
@upstart_job_dir = "/etc/event.d"
|
47
52
|
@upstart_conf_suffix = ""
|
48
53
|
else
|
@@ -175,13 +180,13 @@ class Chef
|
|
175
180
|
def upstart_state
|
176
181
|
command = "/sbin/status #{@new_resource.service_name}"
|
177
182
|
status = popen4(command) do |pid, stdin, stdout, stderr|
|
178
|
-
stdout.
|
183
|
+
stdout.each_line do |line|
|
179
184
|
# rsyslog stop/waiting
|
180
185
|
# service goal/state
|
181
186
|
# OR
|
182
187
|
# rsyslog (stop) waiting
|
183
188
|
# service (goal) state
|
184
|
-
line =~
|
189
|
+
line =~ UPSTART_STATE_FORMAT
|
185
190
|
data = Regexp.last_match
|
186
191
|
return data[2]
|
187
192
|
end
|
@@ -20,8 +20,8 @@ require 'chef/provider/service/init'
|
|
20
20
|
|
21
21
|
class Chef::Provider::Service::Windows < Chef::Provider::Service::Init
|
22
22
|
|
23
|
-
def initialize(
|
24
|
-
super
|
23
|
+
def initialize(new_resource, run_context)
|
24
|
+
super
|
25
25
|
@init_command = "sc"
|
26
26
|
end
|
27
27
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
-
#
|
3
|
+
# Author:: Daniel DeLeo (<dan@opscode.com>)
|
4
|
+
# Copyright:: Copyright (c) 2008, 2010 Opscode, Inc.
|
4
5
|
# License:: Apache License, Version 2.0
|
5
6
|
#
|
6
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -19,70 +20,37 @@
|
|
19
20
|
require 'chef/provider/file'
|
20
21
|
require 'chef/mixin/template'
|
21
22
|
require 'chef/mixin/checksum'
|
22
|
-
require 'chef/
|
23
|
-
|
24
|
-
require 'chef/
|
25
|
-
require '
|
26
|
-
require '
|
23
|
+
require 'chef/file_access_control'
|
24
|
+
|
25
|
+
#require 'chef/mixin/find_preferred_file'
|
26
|
+
#require 'chef/rest'
|
27
|
+
#require 'chef/file_cache'
|
28
|
+
#require 'uri'
|
29
|
+
#require 'tempfile'
|
27
30
|
|
28
31
|
class Chef
|
29
32
|
class Provider
|
30
33
|
|
31
34
|
class Template < Chef::Provider::File
|
32
35
|
|
33
|
-
include Chef::Mixin::Checksum
|
36
|
+
#include Chef::Mixin::Checksum
|
34
37
|
include Chef::Mixin::Template
|
35
|
-
include Chef::Mixin::FindPreferredFile
|
38
|
+
#include Chef::Mixin::FindPreferredFile
|
36
39
|
|
37
40
|
def action_create
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
template_cache_name = "#{cookbook_name}_#{@new_resource.source}"
|
44
|
-
|
45
|
-
if @new_resource.local
|
46
|
-
cache_file_name = @new_resource.source
|
47
|
-
elsif Chef::Config[:solo]
|
48
|
-
cache_file_name = solo_cache_file_name
|
49
|
-
else
|
50
|
-
raw_template_file = fetch_template_via_rest(cache_file_name, template_cache_name)
|
51
|
-
end
|
52
|
-
|
53
|
-
if template_updated?
|
54
|
-
Chef::Log.debug("Updating template for #{@new_resource} in the cache")
|
55
|
-
Chef::FileCache.move_to(raw_template_file.path, cache_file_name)
|
56
|
-
end
|
57
|
-
|
58
|
-
render_with_context(cache_file_name) do |template_file|
|
59
|
-
|
60
|
-
update = false
|
61
|
-
|
62
|
-
if ::File.exists?(@new_resource.path)
|
63
|
-
@new_resource.checksum(checksum(template_file.path))
|
64
|
-
if @new_resource.checksum != @current_resource.checksum
|
65
|
-
Chef::Log.debug("#{@new_resource} changed from #{@current_resource.checksum} to #{@new_resource.checksum}")
|
66
|
-
Chef::Log.info("Updating #{@new_resource} at #{@new_resource.path}")
|
67
|
-
update = true
|
68
|
-
end
|
41
|
+
render_with_context(template_location) do |rendered_template|
|
42
|
+
rendered(rendered_template)
|
43
|
+
if ::File.exist?(@new_resource.path) && content_matches?
|
44
|
+
Chef::Log.debug("#{@new_resource} content has not changed.")
|
45
|
+
set_all_access_controls(@new_resource.path)
|
69
46
|
else
|
70
|
-
Chef::Log.info("
|
71
|
-
update = true
|
72
|
-
end
|
73
|
-
|
74
|
-
if update
|
47
|
+
Chef::Log.info("Writing updated content for #{@new_resource} to #{@new_resource.path}")
|
75
48
|
backup
|
76
|
-
|
49
|
+
set_all_access_controls(rendered_template.path)
|
50
|
+
FileUtils.cp(rendered_template.path, @new_resource.path)
|
77
51
|
@new_resource.updated = true
|
78
|
-
else
|
79
|
-
Chef::Log.debug("#{@new_resource} is unchanged")
|
80
52
|
end
|
81
53
|
end
|
82
|
-
|
83
|
-
set_owner if @new_resource.owner != nil
|
84
|
-
set_group if @new_resource.group != nil
|
85
|
-
set_mode if @new_resource.mode != nil
|
86
54
|
end
|
87
55
|
|
88
56
|
def action_create_if_missing
|
@@ -93,86 +61,133 @@ class Chef
|
|
93
61
|
end
|
94
62
|
end
|
95
63
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
64
|
+
def template_location
|
65
|
+
Chef::Log.debug("looking for template #{@new_resource.source} in cookbook #{cookbook_name.inspect}")
|
66
|
+
@template_file_cache_location ||= begin
|
67
|
+
if @new_resource.local
|
68
|
+
@new_resource.source
|
69
|
+
else
|
70
|
+
cookbook = run_context.cookbook_collection[resource_cookbook]
|
71
|
+
cookbook.preferred_filename_on_disk_location(node, :templates, @new_resource.source)
|
72
|
+
end
|
73
|
+
end
|
104
74
|
end
|
105
|
-
|
106
|
-
def
|
107
|
-
@
|
75
|
+
|
76
|
+
def resource_cookbook
|
77
|
+
@new_resource.cookbook || @new_resource.cookbook_name
|
108
78
|
end
|
109
79
|
|
110
|
-
def
|
111
|
-
@
|
80
|
+
def rendered(rendered_template)
|
81
|
+
@new_resource.checksum(checksum(rendered_template.path))
|
82
|
+
Chef::Log.debug("Current content's checksum: #{@current_resource.checksum}")
|
83
|
+
Chef::Log.debug("Rendered content's checksum: #{@new_resource.checksum}")
|
112
84
|
end
|
113
85
|
|
114
|
-
def
|
115
|
-
|
116
|
-
context.merge!(@new_resource.variables)
|
117
|
-
context[:node] = @node
|
118
|
-
render_template(Chef::FileCache.load(cache_file_name), context, &block)
|
86
|
+
def content_matches?
|
87
|
+
@current_resource.checksum == @new_resource.checksum
|
119
88
|
end
|
120
89
|
|
121
|
-
def
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
@new_resource.source,
|
126
|
-
@node[:fqdn],
|
127
|
-
@node[:platform],
|
128
|
-
@node[:platform_version]
|
129
|
-
)
|
130
|
-
Chef::Log.debug("Using local file for template:#{filename}")
|
131
|
-
Pathname.new(filename).relative_path_from(Pathname.new(Chef::Config[:file_cache_path])).to_s
|
90
|
+
def set_all_access_controls(file)
|
91
|
+
access_controls = Chef::FileAccessControl.new(@new_resource, file)
|
92
|
+
access_controls.set_all
|
93
|
+
@new_resource.updated = access_controls.modified?
|
132
94
|
end
|
133
95
|
|
134
|
-
def
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
{
|
155
|
-
:checksum => current_checksum
|
156
|
-
}
|
157
|
-
)
|
158
|
-
|
159
|
-
begin
|
160
|
-
raw_template_file = r.get_rest(template_url, true)
|
161
|
-
template_updated
|
162
|
-
rescue Net::HTTPRetriableError => e
|
163
|
-
if e.response.kind_of?(Net::HTTPNotModified)
|
164
|
-
Chef::Log.debug("Cached template for #{@new_resource} is unchanged")
|
165
|
-
else
|
166
|
-
raise e
|
167
|
-
end
|
168
|
-
end
|
96
|
+
# def locate_or_fetch_template
|
97
|
+
# Chef::Log.debug("looking for template #{@new_resource.source} in cookbook #{cookbook_name.inspect}")
|
98
|
+
#
|
99
|
+
# cache_file_name = "cookbooks/#{cookbook_name}/templates/default/#{@new_resource.source}"
|
100
|
+
# template_cache_name = "#{cookbook_name}_#{@new_resource.source}"
|
101
|
+
#
|
102
|
+
# if @new_resource.local
|
103
|
+
# cache_file_name = @new_resource.source
|
104
|
+
# elsif Chef::Config[:solo]
|
105
|
+
# cache_file_name = solo_cache_file_name
|
106
|
+
# else
|
107
|
+
# raw_template_file = fetch_template_via_rest(cache_file_name, template_cache_name)
|
108
|
+
# end
|
109
|
+
#
|
110
|
+
# if template_updated?
|
111
|
+
# Chef::Log.debug("Updating template for #{@new_resource} in the cache")
|
112
|
+
# Chef::FileCache.move_to(raw_template_file.path, cache_file_name)
|
113
|
+
# end
|
114
|
+
# cache_file_name
|
115
|
+
# end
|
169
116
|
|
170
|
-
|
171
|
-
@node.run_state[:template_cache][template_cache_name] = true
|
117
|
+
private
|
172
118
|
|
173
|
-
|
119
|
+
# def template_updated
|
120
|
+
# @template_updated = true
|
121
|
+
# end
|
122
|
+
#
|
123
|
+
# def template_not_updated
|
124
|
+
# @template_updated = false
|
125
|
+
# end
|
126
|
+
#
|
127
|
+
# def template_updated?
|
128
|
+
# @template_updated
|
129
|
+
# end
|
130
|
+
#
|
131
|
+
# def cookbook_name
|
132
|
+
# @cookbook_name = (@new_resource.cookbook || @new_resource.cookbook_name)
|
133
|
+
# end
|
134
|
+
|
135
|
+
def render_with_context(template_location, &block)
|
136
|
+
context = {}
|
137
|
+
context.merge!(@new_resource.variables)
|
138
|
+
context[:node] = node
|
139
|
+
render_template(IO.read(template_location), context, &block)
|
174
140
|
end
|
175
141
|
|
142
|
+
# def solo_cache_file_name
|
143
|
+
# filename = find_preferred_file(
|
144
|
+
# cookbook_name,
|
145
|
+
# :template,
|
146
|
+
# @new_resource.source,
|
147
|
+
# node[:fqdn],
|
148
|
+
# node[:platform],
|
149
|
+
# node[:platform_version]
|
150
|
+
# )
|
151
|
+
# Chef::Log.debug("Using local file for template:#{filename}")
|
152
|
+
# Pathname.new(filename).relative_path_from(Pathname.new(Chef::Config[:file_cache_path])).to_s
|
153
|
+
# end
|
154
|
+
#
|
155
|
+
# def fetch_template_via_rest(cache_file_name, template_cache_name)
|
156
|
+
# if node.run_state[:template_cache].has_key?(template_cache_name)
|
157
|
+
# Chef::Log.debug("I have already fetched the template for #{@new_resource} once this run, not checking again.")
|
158
|
+
# template_not_updated
|
159
|
+
# return false
|
160
|
+
# end
|
161
|
+
#
|
162
|
+
# r = Chef::REST.new(Chef::Config[:template_url])
|
163
|
+
#
|
164
|
+
# current_checksum = nil
|
165
|
+
#
|
166
|
+
# if Chef::FileCache.has_key?(cache_file_name)
|
167
|
+
# current_checksum = self.checksum(Chef::FileCache.load(cache_file_name, false))
|
168
|
+
# else
|
169
|
+
# Chef::Log.debug("Template #{@new_resource} is not in the template cache")
|
170
|
+
# end
|
171
|
+
#
|
172
|
+
# template_url = generate_url(@new_resource.source, "templates", :checksum => current_checksum)
|
173
|
+
#
|
174
|
+
# begin
|
175
|
+
# raw_template_file = r.get_rest(template_url, true)
|
176
|
+
# template_updated
|
177
|
+
# rescue Net::HTTPRetriableError
|
178
|
+
# if e.response.kind_of?(Net::HTTPNotModified)
|
179
|
+
# Chef::Log.debug("Cached template for #{@new_resource} is unchanged")
|
180
|
+
# else
|
181
|
+
# raise
|
182
|
+
# end
|
183
|
+
# end
|
184
|
+
#
|
185
|
+
# # We have checked the cache for this template this run
|
186
|
+
# node.run_state[:template_cache][template_cache_name] = true
|
187
|
+
#
|
188
|
+
# raw_template_file
|
189
|
+
# end
|
190
|
+
|
176
191
|
end
|
177
192
|
end
|
178
193
|
end
|