chef 0.10.8 → 0.10.10.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/distro/arch/etc/rc.d/chef-client +15 -1
- data/distro/common/html/chef-client.8.html +4 -4
- data/distro/common/html/chef-expander.8.html +4 -4
- data/distro/common/html/chef-expanderctl.8.html +4 -4
- data/distro/common/html/chef-server-webui.8.html +4 -4
- data/distro/common/html/chef-server.8.html +4 -4
- data/distro/common/html/chef-solo.8.html +4 -4
- data/distro/common/html/chef-solr.8.html +4 -4
- data/distro/common/html/knife-bootstrap.1.html +6 -10
- data/distro/common/html/knife-client.1.html +4 -4
- data/distro/common/html/knife-configure.1.html +4 -4
- data/distro/common/html/knife-cookbook-site.1.html +6 -6
- data/distro/common/html/knife-cookbook.1.html +4 -4
- data/distro/common/html/knife-data-bag.1.html +4 -4
- data/distro/common/html/knife-environment.1.html +4 -4
- data/distro/common/html/knife-exec.1.html +4 -4
- data/distro/common/html/knife-index.1.html +4 -4
- data/distro/common/html/knife-node.1.html +5 -5
- data/distro/common/html/knife-role.1.html +4 -4
- data/distro/common/html/knife-search.1.html +4 -4
- data/distro/common/html/knife-ssh.1.html +5 -6
- data/distro/common/html/knife-status.1.html +4 -4
- data/distro/common/html/knife-tag.1.html +4 -4
- data/distro/common/html/knife.1.html +7 -8
- data/distro/common/html/shef.1.html +4 -4
- data/distro/common/man/man1/knife-bootstrap.1 +4 -4
- data/distro/common/man/man1/knife-client.1 +1 -1
- data/distro/common/man/man1/knife-configure.1 +1 -1
- data/distro/common/man/man1/knife-cookbook-site.1 +4 -4
- data/distro/common/man/man1/knife-cookbook.1 +1 -1
- data/distro/common/man/man1/knife-data-bag.1 +1 -1
- data/distro/common/man/man1/knife-environment.1 +1 -1
- data/distro/common/man/man1/knife-exec.1 +1 -1
- data/distro/common/man/man1/knife-index.1 +1 -1
- data/distro/common/man/man1/knife-node.1 +2 -2
- data/distro/common/man/man1/knife-role.1 +1 -1
- data/distro/common/man/man1/knife-search.1 +1 -1
- data/distro/common/man/man1/knife-ssh.1 +3 -7
- data/distro/common/man/man1/knife-status.1 +1 -1
- data/distro/common/man/man1/knife-tag.1 +1 -1
- data/distro/common/man/man1/knife.1 +5 -9
- data/distro/common/man/man1/shef.1 +1 -1
- data/distro/common/man/man8/chef-client.8 +1 -1
- data/distro/common/man/man8/chef-expander.8 +1 -1
- data/distro/common/man/man8/chef-expanderctl.8 +1 -1
- data/distro/common/man/man8/chef-server-webui.8 +1 -1
- data/distro/common/man/man8/chef-server.8 +1 -1
- data/distro/common/man/man8/chef-solo.8 +1 -1
- data/distro/common/man/man8/chef-solr.8 +1 -1
- data/distro/common/markdown/man1/knife-bootstrap.mkd +3 -7
- data/distro/common/markdown/man1/knife-cookbook-site.mkd +3 -3
- data/distro/common/markdown/man1/knife-node.mkd +2 -2
- data/distro/common/markdown/man1/knife-ssh.mkd +2 -5
- data/distro/common/markdown/man1/knife.mkd +7 -9
- data/distro/debian/etc/init.d/chef-client +22 -1
- data/distro/redhat/etc/init.d/chef-client +12 -1
- data/distro/windows/service_manager.rb +164 -0
- data/lib/chef/application.rb +12 -6
- data/lib/chef/application/client.rb +4 -3
- data/lib/chef/application/knife.rb +7 -12
- data/lib/chef/application/solo.rb +2 -1
- data/lib/chef/application/windows_service.rb +224 -0
- data/lib/chef/checksum_cache.rb +1 -0
- data/lib/chef/client.rb +3 -16
- data/lib/chef/config.rb +42 -13
- data/lib/chef/cookbook/metadata.rb +1 -1
- data/lib/chef/cookbook/syntax_check.rb +2 -2
- data/lib/chef/cookbook_version.rb +5 -0
- data/lib/chef/daemon.rb +1 -1
- data/lib/chef/exceptions.rb +7 -1
- data/lib/chef/file_access_control.rb +13 -87
- data/lib/chef/file_access_control/unix.rb +119 -0
- data/lib/chef/file_access_control/windows.rb +257 -0
- data/lib/chef/handler/json_file.rb +7 -1
- data/lib/chef/knife.rb +10 -16
- data/lib/chef/knife/bootstrap.rb +15 -8
- data/lib/chef/knife/bootstrap/centos5-gems.erb +1 -1
- data/lib/chef/knife/bootstrap/chef-full.erb +59 -0
- data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +1 -0
- data/lib/chef/knife/configure.rb +2 -2
- data/lib/chef/knife/cookbook_site_download.rb +60 -21
- data/lib/chef/knife/cookbook_site_install.rb +16 -21
- data/lib/chef/knife/cookbook_upload.rb +77 -48
- data/lib/chef/knife/core/bootstrap_context.rb +3 -1
- data/lib/chef/knife/core/cookbook_scm_repo.rb +1 -1
- data/lib/chef/knife/core/node_editor.rb +1 -1
- data/lib/chef/knife/core/subcommand_loader.rb +1 -1
- data/lib/chef/knife/core/ui.rb +3 -2
- data/lib/chef/knife/help_topics.rb +1 -1
- data/lib/chef/knife/node_run_list_add.rb +14 -6
- data/lib/chef/knife/node_run_list_remove.rb +3 -3
- data/lib/chef/knife/ssh.rb +32 -13
- data/lib/chef/mash.rb +14 -0
- data/lib/chef/mixin/command.rb +1 -0
- data/lib/chef/mixin/command/unix.rb +5 -0
- data/lib/chef/mixin/convert_to_class_name.rb +2 -0
- data/lib/chef/mixin/deep_merge.rb +40 -18
- data/lib/chef/mixin/enforce_ownership_and_permissions.rb +39 -0
- data/lib/chef/mixin/language.rb +89 -3
- data/lib/chef/mixin/language_include_recipe.rb +8 -4
- data/lib/chef/mixin/path_sanity.rb +67 -0
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +19 -11
- data/lib/chef/mixin/securable.rb +152 -0
- data/lib/chef/mixin/shell_out.rb +1 -1
- data/lib/chef/mixin/template.rb +8 -3
- data/lib/chef/mixins.rb +3 -0
- data/lib/chef/monkey_patches/moneta.rb +50 -0
- data/lib/chef/monkey_patches/string.rb +1 -1
- data/lib/chef/node.rb +2 -1
- data/lib/chef/platform.rb +34 -0
- data/lib/chef/provider.rb +23 -21
- data/lib/chef/provider/cron.rb +17 -12
- data/lib/chef/provider/cron/solaris.rb +6 -18
- data/lib/chef/provider/deploy.rb +14 -15
- data/lib/chef/provider/deploy/timestamped.rb +0 -1
- data/lib/chef/provider/directory.rb +1 -3
- data/lib/chef/provider/execute.rb +2 -2
- data/lib/chef/provider/file.rb +1 -75
- data/lib/chef/provider/git.rb +11 -9
- data/lib/chef/provider/group/gpasswd.rb +14 -9
- data/lib/chef/provider/link.rb +28 -59
- data/lib/chef/provider/mdadm.rb +2 -2
- data/lib/chef/provider/mount/mount.rb +1 -1
- data/lib/chef/provider/package.rb +10 -6
- data/lib/chef/provider/package/apt.rb +3 -1
- data/lib/chef/provider/package/dpkg.rb +1 -1
- data/lib/chef/provider/package/portage.rb +6 -3
- data/lib/chef/provider/package/rubygems.rb +75 -6
- data/lib/chef/provider/package/smartos.rb +84 -0
- data/lib/chef/provider/package/yum-dump.py +3 -2
- data/lib/chef/provider/package/yum.rb +51 -10
- data/lib/chef/provider/remote_directory.rb +24 -3
- data/lib/chef/provider/remote_file.rb +0 -6
- data/lib/chef/provider/route.rb +3 -3
- data/lib/chef/provider/service/debian.rb +2 -2
- data/lib/chef/provider/service/freebsd.rb +1 -1
- data/lib/chef/provider/service/macosx.rb +125 -0
- data/lib/chef/provider/service/windows.rb +5 -1
- data/lib/chef/provider/subversion.rb +10 -7
- data/lib/chef/providers.rb +3 -0
- data/lib/chef/resource.rb +181 -87
- data/lib/chef/resource/apt_package.rb +10 -1
- data/lib/chef/resource/chef_gem.rb +53 -0
- data/lib/chef/resource/conditional.rb +3 -0
- data/lib/chef/resource/cookbook_file.rb +12 -6
- data/lib/chef/resource/cron.rb +9 -0
- data/lib/chef/resource/directory.rb +14 -31
- data/lib/chef/resource/execute.rb +11 -9
- data/lib/chef/resource/file.rb +9 -33
- data/lib/chef/resource/link.rb +13 -8
- data/lib/chef/resource/mdadm.rb +10 -1
- data/lib/chef/resource/remote_directory.rb +13 -2
- data/lib/chef/resource/remote_file.rb +14 -7
- data/lib/chef/resource/smartos_package.rb +36 -0
- data/lib/chef/resource/template.rb +12 -5
- data/lib/chef/resource_platform_map.rb +153 -0
- data/lib/chef/resources.rb +2 -0
- data/lib/chef/rest.rb +55 -10
- data/lib/chef/rest/auth_credentials.rb +1 -0
- data/lib/chef/rest/rest_request.rb +24 -8
- data/lib/chef/role.rb +8 -2
- data/lib/chef/run_list.rb +1 -1
- data/lib/chef/run_list/run_list_expansion.rb +2 -2
- data/lib/chef/run_list/run_list_item.rb +7 -0
- data/lib/chef/runner.rb +4 -0
- data/lib/chef/shef.rb +2 -2
- data/lib/chef/shef/shef_session.rb +4 -5
- data/lib/chef/shell_out.rb +2 -245
- data/lib/chef/util/file_edit.rb +99 -89
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/api.rb +349 -0
- data/lib/chef/win32/api/error.rb +921 -0
- data/lib/chef/win32/api/file.rb +289 -0
- data/lib/chef/win32/api/memory.rb +105 -0
- data/lib/chef/win32/api/process.rb +40 -0
- data/lib/chef/win32/api/psapi.rb +51 -0
- data/lib/chef/win32/api/security.rb +341 -0
- data/lib/chef/win32/api/system.rb +192 -0
- data/lib/chef/win32/api/unicode.rb +178 -0
- data/lib/chef/win32/error.rb +73 -0
- data/lib/chef/win32/file.rb +117 -0
- data/lib/chef/win32/file/info.rb +100 -0
- data/lib/chef/win32/handle.rb +48 -0
- data/lib/chef/win32/memory.rb +101 -0
- data/lib/chef/win32/process.rb +84 -0
- data/lib/chef/win32/security.rb +489 -0
- data/lib/chef/win32/security/ace.rb +125 -0
- data/lib/chef/win32/security/acl.rb +101 -0
- data/lib/chef/win32/security/securable_object.rb +109 -0
- data/lib/chef/win32/security/security_descriptor.rb +93 -0
- data/lib/chef/win32/security/sid.rb +199 -0
- data/lib/chef/win32/security/token.rb +64 -0
- data/lib/chef/win32/unicode.rb +43 -0
- data/lib/chef/win32/version.rb +119 -0
- metadata +104 -158
- data/lib/chef/shell_out/unix.rb +0 -223
- data/lib/chef/shell_out/windows.rb +0 -588
data/lib/chef/application.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: AJ Christensen (<aj@opscode.com>)
|
3
|
+
# Author:: Mark Mzyk (mmzyk@opscode.com)
|
3
4
|
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
5
|
# License:: Apache License, Version 2.0
|
5
6
|
#
|
@@ -19,8 +20,10 @@ require 'socket'
|
|
19
20
|
require 'chef/config'
|
20
21
|
require 'chef/exceptions'
|
21
22
|
require 'chef/log'
|
23
|
+
require 'chef/platform'
|
22
24
|
require 'mixlib/cli'
|
23
25
|
require 'tmpdir'
|
26
|
+
require 'rbconfig'
|
24
27
|
|
25
28
|
class Chef::Application
|
26
29
|
include Mixlib::CLI
|
@@ -39,7 +42,7 @@ class Chef::Application
|
|
39
42
|
Chef::Application.fatal!("SIGINT received, stopping", 2)
|
40
43
|
end
|
41
44
|
|
42
|
-
unless
|
45
|
+
unless Chef::Platform.windows?
|
43
46
|
trap("QUIT") do
|
44
47
|
Chef::Log.info("SIGQUIT received, call stack:\n " + caller.join("\n "))
|
45
48
|
end
|
@@ -78,15 +81,18 @@ class Chef::Application
|
|
78
81
|
else
|
79
82
|
::File::open(config[:config_file]) { |f| apply_config(f.path) }
|
80
83
|
end
|
81
|
-
rescue
|
82
|
-
Chef::Application.fatal!("Error getting config file #{Chef::Config[:config_file]}", 2)
|
83
|
-
rescue Exception => error
|
84
|
+
rescue Errno::ENOENT => error
|
84
85
|
Chef::Log.warn("*****************************************")
|
85
|
-
Chef::Log.warn("
|
86
|
-
Chef::Log.warn("#{error.message}")
|
86
|
+
Chef::Log.warn("Did not find config file: #{config[:config_file]}, using command line options.")
|
87
87
|
Chef::Log.warn("*****************************************")
|
88
88
|
|
89
89
|
Chef::Config.merge!(config)
|
90
|
+
rescue SocketError => error
|
91
|
+
Chef::Application.fatal!("Error getting config file #{Chef::Config[:config_file]}", 2)
|
92
|
+
rescue Chef::Exceptions::ConfigurationError => error
|
93
|
+
Chef::Application.fatal!("Error processing config file #{Chef::Config[:config_file]} with error #{error.message}", 2)
|
94
|
+
rescue Exception => error
|
95
|
+
Chef::Application.fatal!("Unknown error processing config file #{Chef::Config[:config_file]} with error #{error.message}", 2)
|
90
96
|
end
|
91
97
|
|
92
98
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Author:: AJ Christensen (<aj@opscode.com)
|
3
3
|
# Author:: Christopher Brown (<cb@opscode.com>)
|
4
|
+
# Author:: Mark Mzyk (mmzyk@opscode.com)
|
4
5
|
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
5
6
|
# License:: Apache License, Version 2.0
|
6
7
|
#
|
@@ -33,7 +34,7 @@ class Chef::Application::Client < Chef::Application
|
|
33
34
|
option :config_file,
|
34
35
|
:short => "-c CONFIG",
|
35
36
|
:long => "--config CONFIG",
|
36
|
-
:default => "/etc/chef/client.rb",
|
37
|
+
:default => Chef::Config.platform_specific_path("/etc/chef/client.rb"),
|
37
38
|
:description => "The configuration file to use"
|
38
39
|
|
39
40
|
option :log_level,
|
@@ -209,7 +210,7 @@ class Chef::Application::Client < Chef::Application
|
|
209
210
|
|
210
211
|
# Run the chef client, optionally daemonizing or looping at intervals.
|
211
212
|
def run_application
|
212
|
-
unless
|
213
|
+
unless Chef::Platform.windows?
|
213
214
|
SELF_PIPE.replace IO.pipe
|
214
215
|
|
215
216
|
trap("USR1") do
|
@@ -276,7 +277,7 @@ class Chef::Application::Client < Chef::Application
|
|
276
277
|
end
|
277
278
|
end
|
278
279
|
|
279
|
-
private
|
280
|
+
private
|
280
281
|
|
281
282
|
def client_sleep(sec)
|
282
283
|
IO.select([ SELF_PIPE[0] ], nil, nil, sec) or return
|
@@ -41,16 +41,10 @@ class Chef::Application::Knife < Chef::Application
|
|
41
41
|
:default => 0
|
42
42
|
|
43
43
|
option :color,
|
44
|
-
:long => '--color',
|
44
|
+
:long => '--[no-]color',
|
45
45
|
:boolean => true,
|
46
46
|
:default => true,
|
47
|
-
:description => "Use colored output"
|
48
|
-
|
49
|
-
option :no_color,
|
50
|
-
:long => '--no-color',
|
51
|
-
:boolean => true,
|
52
|
-
:default => false,
|
53
|
-
:description => "Don't use colors in the output"
|
47
|
+
:description => "Use colored output, defaults to enabled"
|
54
48
|
|
55
49
|
option :environment,
|
56
50
|
:short => "-E ENVIRONMENT",
|
@@ -63,11 +57,12 @@ class Chef::Application::Knife < Chef::Application
|
|
63
57
|
:description => "Set the editor to use for interactive commands",
|
64
58
|
:default => ENV['EDITOR']
|
65
59
|
|
66
|
-
option :
|
67
|
-
:short => "-
|
68
|
-
:long => "--
|
60
|
+
option :disable_editing,
|
61
|
+
:short => "-d",
|
62
|
+
:long => "--disable-editing",
|
69
63
|
:description => "Do not open EDITOR, just accept the data as is",
|
70
|
-
:boolean => true
|
64
|
+
:boolean => true,
|
65
|
+
:defaut => false
|
71
66
|
|
72
67
|
option :help,
|
73
68
|
:short => "-h",
|
@@ -1,5 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: AJ Christensen (<aj@opscode.com>)
|
3
|
+
# Author:: Mark Mzyk (mmzyk@opscode.com)
|
3
4
|
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
5
|
# License:: Apache License, Version 2.0
|
5
6
|
#
|
@@ -30,7 +31,7 @@ class Chef::Application::Solo < Chef::Application
|
|
30
31
|
option :config_file,
|
31
32
|
:short => "-c CONFIG",
|
32
33
|
:long => "--config CONFIG",
|
33
|
-
:default =>
|
34
|
+
:default => Chef::Config.platform_specfic_path('/etc/chef/solo.rb'),
|
34
35
|
:description => "The configuration file to use"
|
35
36
|
|
36
37
|
option :log_level,
|
@@ -0,0 +1,224 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Christopher Maier (<maier@lambda.local>)
|
3
|
+
# Copyright:: Copyright (c) 2011 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/application'
|
20
|
+
require 'chef/client'
|
21
|
+
require 'chef/config'
|
22
|
+
require 'chef/handler/error_report'
|
23
|
+
require 'chef/log'
|
24
|
+
require 'chef/rest'
|
25
|
+
require 'mixlib/cli'
|
26
|
+
require 'socket'
|
27
|
+
require 'win32/daemon'
|
28
|
+
|
29
|
+
class Chef
|
30
|
+
class Application
|
31
|
+
class WindowsService < ::Win32::Daemon
|
32
|
+
include Mixlib::CLI
|
33
|
+
|
34
|
+
option :config_file,
|
35
|
+
:short => "-c CONFIG",
|
36
|
+
:long => "--config CONFIG",
|
37
|
+
:default => "#{ENV['SYSTEMDRIVE']}/chef/client.rb",
|
38
|
+
:description => ""
|
39
|
+
|
40
|
+
option :log_location,
|
41
|
+
:short => "-L LOGLOCATION",
|
42
|
+
:long => "--logfile LOGLOCATION",
|
43
|
+
:description => "Set the log file location",
|
44
|
+
:default => "#{ENV['SYSTEMDRIVE']}/chef/client.log"
|
45
|
+
|
46
|
+
option :splay,
|
47
|
+
:short => "-s SECONDS",
|
48
|
+
:long => "--splay SECONDS",
|
49
|
+
:description => "The splay time for running at intervals, in seconds",
|
50
|
+
:proc => lambda { |s| s.to_i }
|
51
|
+
|
52
|
+
option :interval,
|
53
|
+
:short => "-i SECONDS",
|
54
|
+
:long => "--interval SECONDS",
|
55
|
+
:description => "Set the number of seconds to wait between chef-client runs",
|
56
|
+
:proc => lambda { |s| s.to_i }
|
57
|
+
|
58
|
+
def service_init
|
59
|
+
reconfigure
|
60
|
+
Chef::Log.info("Chef Client Service initialized")
|
61
|
+
end
|
62
|
+
|
63
|
+
def service_main(*startup_parameters)
|
64
|
+
|
65
|
+
while running?
|
66
|
+
if state == RUNNING
|
67
|
+
begin
|
68
|
+
# Reconfigure each time through to pick up any changes in the client file
|
69
|
+
Chef::Log.info("Reconfiguring with startup parameters")
|
70
|
+
reconfigure(startup_parameters)
|
71
|
+
|
72
|
+
splay = rand Chef::Config[:splay]
|
73
|
+
Chef::Log.debug("Splay sleep #{splay} seconds")
|
74
|
+
sleep splay
|
75
|
+
|
76
|
+
# If we've stopped, then bail out now, instead of going on to run Chef
|
77
|
+
next if state != RUNNING
|
78
|
+
|
79
|
+
@chef_client = Chef::Client.new(@chef_client_json)
|
80
|
+
@chef_client_json = nil
|
81
|
+
|
82
|
+
@chef_client.run
|
83
|
+
@chef_client = nil
|
84
|
+
|
85
|
+
Chef::Log.debug("Sleeping for #{Chef::Config[:interval]} seconds")
|
86
|
+
client_sleep Chef::Config[:interval]
|
87
|
+
rescue Chef::Application::Wakeup => e
|
88
|
+
Chef::Log.debug("Received Wakeup signal. Starting run.")
|
89
|
+
next
|
90
|
+
rescue SystemExit => e
|
91
|
+
raise
|
92
|
+
rescue Exception => e
|
93
|
+
Chef::Log.error("#{e.class}: #{e}")
|
94
|
+
Chef::Application.debug_stacktrace(e)
|
95
|
+
Chef::Log.error("Sleeping for #{Chef::Config[:interval]} seconds before trying again")
|
96
|
+
client_sleep Chef::Config[:interval]
|
97
|
+
retry
|
98
|
+
ensure
|
99
|
+
GC.start
|
100
|
+
end
|
101
|
+
else # PAUSED or IDLE
|
102
|
+
sleep 5
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
################################################################################
|
108
|
+
# Control Signal Callback Methods
|
109
|
+
################################################################################
|
110
|
+
|
111
|
+
def service_stop
|
112
|
+
Chef::Log.info("SERVICE_CONTROL_STOP received, stopping")
|
113
|
+
end
|
114
|
+
|
115
|
+
def service_pause
|
116
|
+
Chef::Log.info("SERVICE_CONTROL_PAUSE received, pausing")
|
117
|
+
end
|
118
|
+
|
119
|
+
def service_resume
|
120
|
+
Chef::Log.info("SERVICE_CONTROL_CONTINUE received, resuming")
|
121
|
+
end
|
122
|
+
|
123
|
+
def service_shutdown
|
124
|
+
Chef::Log.info("SERVICE_CONTROL_SHUTDOWN received, shutting down")
|
125
|
+
end
|
126
|
+
|
127
|
+
################################################################################
|
128
|
+
# Internal Methods
|
129
|
+
################################################################################
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def apply_config(config_file_path)
|
134
|
+
Chef::Config.from_file(config_file_path)
|
135
|
+
Chef::Config.merge!(config)
|
136
|
+
end
|
137
|
+
|
138
|
+
# Lifted from Chef::Application, with addition of optional startup parameters
|
139
|
+
# for playing nicely with Windows Services
|
140
|
+
def reconfigure(startup_parameters=[])
|
141
|
+
configure_chef startup_parameters
|
142
|
+
configure_logging
|
143
|
+
|
144
|
+
Chef::Config[:chef_server_url] = config[:chef_server_url] if config.has_key? :chef_server_url
|
145
|
+
unless Chef::Config[:exception_handlers].any? {|h| Chef::Handler::ErrorReport === h}
|
146
|
+
Chef::Config[:exception_handlers] << Chef::Handler::ErrorReport.new
|
147
|
+
end
|
148
|
+
|
149
|
+
Chef::Config[:interval] ||= 1800
|
150
|
+
end
|
151
|
+
|
152
|
+
# Lifted from Chef::Application and Chef::Application::Client
|
153
|
+
# MUST BE RUN AFTER configuration has been parsed!
|
154
|
+
def configure_logging
|
155
|
+
# Implementation from Chef::Application
|
156
|
+
Chef::Log.init(Chef::Config[:log_location])
|
157
|
+
Chef::Log.level = Chef::Config[:log_level]
|
158
|
+
|
159
|
+
# Implementation from Chef::Application::Client
|
160
|
+
Mixlib::Authentication::Log.use_log_devices( Chef::Log )
|
161
|
+
Ohai::Log.use_log_devices( Chef::Log )
|
162
|
+
end
|
163
|
+
|
164
|
+
def configure_chef(startup_parameters)
|
165
|
+
# Bit of a hack ahead:
|
166
|
+
# It is possible to specify a service's binary_path_name with arguments, like "foo.exe -x argX".
|
167
|
+
# It is also possible to specify startup parameters separately, either via the the Services manager
|
168
|
+
# or by using the registry (I think).
|
169
|
+
|
170
|
+
# In order to accommodate all possible sources of parameterization, we first parse any command line
|
171
|
+
# arguments. We then parse any startup parameters. This works, because Mixlib::CLI reuses its internal
|
172
|
+
# 'config' hash; thus, anything in startup parameters will override any command line parameters that
|
173
|
+
# might be set via the service's binary_path_name
|
174
|
+
#
|
175
|
+
# All these parameters then get layered on top of those from Chef::Config
|
176
|
+
|
177
|
+
parse_options # Operates on ARGV by default
|
178
|
+
parse_options startup_parameters
|
179
|
+
|
180
|
+
begin
|
181
|
+
case config[:config_file]
|
182
|
+
when /^(http|https):\/\//
|
183
|
+
Chef::REST.new("", nil, nil).fetch(config[:config_file]) { |f| apply_config(f.path) }
|
184
|
+
else
|
185
|
+
::File::open(config[:config_file]) { |f| apply_config(f.path) }
|
186
|
+
end
|
187
|
+
rescue Errno::ENOENT => error
|
188
|
+
Chef::Log.warn("*****************************************")
|
189
|
+
Chef::Log.warn("Did not find config file: #{config[:config_file]}, using command line options.")
|
190
|
+
Chef::Log.warn("*****************************************")
|
191
|
+
|
192
|
+
Chef::Config.merge!(config)
|
193
|
+
rescue SocketError => error
|
194
|
+
Chef::Application.fatal!("Error getting config file #{Chef::Config[:config_file]}", 2)
|
195
|
+
rescue Chef::Exceptions::ConfigurationError => error
|
196
|
+
Chef::Application.fatal!("Error processing config file #{Chef::Config[:config_file]} with error #{error.message}", 2)
|
197
|
+
rescue Exception => error
|
198
|
+
Chef::Application.fatal!("Unknown error processing config file #{Chef::Config[:config_file]} with error #{error.message}", 2)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
# Since we need to be able to respond to signals between Chef runs, we need to periodically
|
203
|
+
# wake up to see if we're still in the running state. The method returns when it has slept
|
204
|
+
# for +sec+ seconds (but at least +10+ seconds), or when the service
|
205
|
+
# is no client_sleep in the +RUNNING+ state, whichever comes first.
|
206
|
+
def client_sleep(sec)
|
207
|
+
chunk_length = 10
|
208
|
+
chunks = sec / chunk_length
|
209
|
+
chunks = 1 if chunks < 1
|
210
|
+
(1..chunks).each do
|
211
|
+
return unless state == RUNNING
|
212
|
+
sleep chunk_length
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
# To run this file as a service, it must be called as a script from within
|
221
|
+
# the Windows Service framework. In that case, kick off the main loop!
|
222
|
+
if __FILE__ == $0
|
223
|
+
Chef::Application::WindowsService.mainloop
|
224
|
+
end
|
data/lib/chef/checksum_cache.rb
CHANGED
data/lib/chef/client.rb
CHANGED
@@ -20,6 +20,7 @@
|
|
20
20
|
|
21
21
|
require 'chef/config'
|
22
22
|
require 'chef/mixin/params_validate'
|
23
|
+
require 'chef/mixin/path_sanity'
|
23
24
|
require 'chef/log'
|
24
25
|
require 'chef/rest'
|
25
26
|
require 'chef/api_client'
|
@@ -36,14 +37,14 @@ require 'chef/cookbook/file_system_file_vendor'
|
|
36
37
|
require 'chef/cookbook/remote_file_vendor'
|
37
38
|
require 'chef/version'
|
38
39
|
require 'ohai'
|
40
|
+
require 'rbconfig'
|
39
41
|
|
40
42
|
class Chef
|
41
43
|
# == Chef::Client
|
42
44
|
# The main object in a Chef run. Preps a Chef::Node and Chef::RunContext,
|
43
45
|
# syncs cookbooks if necessary, and triggers convergence.
|
44
46
|
class Client
|
45
|
-
|
46
|
-
SANE_PATHS = %w[/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin]
|
47
|
+
include Chef::Mixin::PathSanity
|
47
48
|
|
48
49
|
# Clears all notifications for client run status events.
|
49
50
|
# Primarily for testing purposes.
|
@@ -313,20 +314,6 @@ class Chef
|
|
313
314
|
true
|
314
315
|
end
|
315
316
|
|
316
|
-
def enforce_path_sanity(env=ENV)
|
317
|
-
if Chef::Config[:enforce_path_sanity] && RUBY_PLATFORM !~ /mswin|mingw32|windows/
|
318
|
-
existing_paths = env["PATH"].split(':')
|
319
|
-
SANE_PATHS.each do |sane_path|
|
320
|
-
unless existing_paths.include?(sane_path)
|
321
|
-
env_path = env["PATH"].dup
|
322
|
-
env_path << ':' unless env["PATH"].empty?
|
323
|
-
env_path << sane_path
|
324
|
-
env["PATH"] = env_path
|
325
|
-
end
|
326
|
-
end
|
327
|
-
end
|
328
|
-
end
|
329
|
-
|
330
317
|
private
|
331
318
|
|
332
319
|
def directory_not_empty?(path)
|
data/lib/chef/config.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
3
|
# Author:: Christopher Brown (<cb@opscode.com>)
|
4
4
|
# Author:: AJ Christensen (<aj@opscode.com>)
|
5
|
+
# Author:: Mark Mzyk (mmzyk@opscode.com)
|
5
6
|
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
6
7
|
# License:: Apache License, Version 2.0
|
7
8
|
#
|
@@ -46,6 +47,16 @@ class Chef
|
|
46
47
|
configuration.inspect
|
47
48
|
end
|
48
49
|
|
50
|
+
def self.platform_specific_path(path)
|
51
|
+
if RUBY_PLATFORM =~ /mswin|mingw|windows/
|
52
|
+
# turns /etc/chef/client.rb into C:/chef/client.rb
|
53
|
+
path = File.join(ENV['SYSTEMDRIVE'], path.split('/')[2..-1])
|
54
|
+
# ensure all forward slashes are backslashes
|
55
|
+
path.gsub!(File::SEPARATOR, (File::ALT_SEPARATOR || '\\'))
|
56
|
+
end
|
57
|
+
path
|
58
|
+
end
|
59
|
+
|
49
60
|
# Override the config dispatch to set the value of multiple server options simultaneously
|
50
61
|
#
|
51
62
|
# === Parameters
|
@@ -85,9 +96,13 @@ class Chef
|
|
85
96
|
location.sync = true
|
86
97
|
location
|
87
98
|
elsif location.respond_to? :to_str
|
88
|
-
|
89
|
-
|
90
|
-
|
99
|
+
begin
|
100
|
+
f = File.new(location.to_str, "a")
|
101
|
+
f.sync = true
|
102
|
+
rescue Errno::ENOENT => error
|
103
|
+
raise Chef::Exceptions::ConfigurationError("Failed to open or create log file at #{location.to_str}")
|
104
|
+
end
|
105
|
+
f
|
91
106
|
end
|
92
107
|
end
|
93
108
|
|
@@ -115,7 +130,8 @@ class Chef
|
|
115
130
|
|
116
131
|
# Where the cookbooks are located. Meaning is somewhat context dependent between
|
117
132
|
# knife, chef-client, and chef-solo.
|
118
|
-
cookbook_path [ "/var/chef/cookbooks",
|
133
|
+
cookbook_path [ platform_specific_path("/var/chef/cookbooks"),
|
134
|
+
platform_specific_path("/var/chef/site-cookbooks") ]
|
119
135
|
|
120
136
|
# Where files are stored temporarily during uploads
|
121
137
|
sandbox_path "/var/chef/sandboxes"
|
@@ -129,10 +145,10 @@ class Chef
|
|
129
145
|
couchdb_url "http://localhost:5984"
|
130
146
|
|
131
147
|
# Where chef's cache files should be stored
|
132
|
-
file_cache_path "/var/chef/cache"
|
148
|
+
file_cache_path platform_specific_path("/var/chef/cache")
|
133
149
|
|
134
150
|
# Where backups of chef-managed files should go
|
135
|
-
file_backup_path "/var/chef/backup"
|
151
|
+
file_backup_path platform_specific_path("/var/chef/backup")
|
136
152
|
|
137
153
|
## Daemonization Settings ##
|
138
154
|
# What user should Chef run as?
|
@@ -148,7 +164,7 @@ class Chef
|
|
148
164
|
log_level :info
|
149
165
|
log_location STDOUT
|
150
166
|
# toggle info level log items that can create a lot of output
|
151
|
-
verbose_logging true
|
167
|
+
verbose_logging true
|
152
168
|
node_name nil
|
153
169
|
node_path "/var/chef/node"
|
154
170
|
|
@@ -179,7 +195,9 @@ class Chef
|
|
179
195
|
|
180
196
|
|
181
197
|
# Where should chef-solo look for role files?
|
182
|
-
role_path "/var/chef/roles"
|
198
|
+
role_path platform_specific_path("/var/chef/roles")
|
199
|
+
|
200
|
+
data_bag_path platform_specific_path("/var/chef/data_bags")
|
183
201
|
|
184
202
|
# Where should chef-solo download recipes from?
|
185
203
|
recipe_url nil
|
@@ -201,8 +219,8 @@ class Chef
|
|
201
219
|
# (persist across rabbitmq restarts)
|
202
220
|
amqp_consumer_id "default"
|
203
221
|
|
204
|
-
client_key "/etc/chef/client.pem"
|
205
|
-
validation_key "/etc/chef/validation.pem"
|
222
|
+
client_key platform_specific_path("/etc/chef/client.pem")
|
223
|
+
validation_key platform_specific_path("/etc/chef/validation.pem")
|
206
224
|
validation_client_name "chef-validator"
|
207
225
|
web_ui_client_name "chef-webui"
|
208
226
|
web_ui_key "/etc/chef/webui.pem"
|
@@ -235,14 +253,25 @@ class Chef
|
|
235
253
|
# Checksum Cache
|
236
254
|
# Uses Moneta on the back-end
|
237
255
|
cache_type "BasicFile"
|
238
|
-
cache_options({ :path => "/
|
256
|
+
cache_options({ :path => platform_specific_path("/etc/chef/cache/checksums"), :skip_expires => true })
|
239
257
|
|
240
258
|
# Arbitrary knife configuration data
|
241
259
|
knife Hash.new
|
242
260
|
|
243
261
|
# Those lists of regular expressions define what chef considers a
|
244
262
|
# valid user and group name
|
245
|
-
|
246
|
-
|
263
|
+
if RUBY_PLATFORM =~ /mswin|mingw|windows/
|
264
|
+
# From http://technet.microsoft.com/en-us/library/cc776019(WS.10).aspx
|
265
|
+
|
266
|
+
principal_valid_regex_part = '[^"\/\\\\\[\]\:;|=,+*?<>]+'
|
267
|
+
user_valid_regex [ /^(#{principal_valid_regex_part}\\)?#{principal_valid_regex_part}$/ ]
|
268
|
+
group_valid_regex [ /^(#{principal_valid_regex_part}\\)?#{principal_valid_regex_part}$/ ]
|
269
|
+
else
|
270
|
+
user_valid_regex [ /^([-a-zA-Z0-9_.]+)$/, /^\d+$/ ]
|
271
|
+
group_valid_regex [ /^([-a-zA-Z0-9_.\\ ]+)$/, /^\d+$/ ]
|
272
|
+
end
|
273
|
+
|
274
|
+
# returns a platform specific path to the user home dir
|
275
|
+
user_home (ENV['HOME'] || ENV['SYSTEMDRIVE'] + ENV['HOMEPATH'] || ENV['USERPROFILE'])
|
247
276
|
end
|
248
277
|
end
|