chef 0.7.10
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/LICENSE +201 -0
- data/README.rdoc +135 -0
- data/bin/chef-client +26 -0
- data/bin/chef-solo +26 -0
- data/lib/chef.rb +49 -0
- data/lib/chef/application.rb +98 -0
- data/lib/chef/application/agent.rb +18 -0
- data/lib/chef/application/client.rb +209 -0
- data/lib/chef/application/indexer.rb +141 -0
- data/lib/chef/application/server.rb +18 -0
- data/lib/chef/application/solo.rb +214 -0
- data/lib/chef/client.rb +396 -0
- data/lib/chef/compile.rb +138 -0
- data/lib/chef/config.rb +141 -0
- data/lib/chef/cookbook.rb +144 -0
- data/lib/chef/cookbook/metadata.rb +407 -0
- data/lib/chef/cookbook/metadata/version.rb +87 -0
- data/lib/chef/cookbook_loader.rb +168 -0
- data/lib/chef/couchdb.rb +172 -0
- data/lib/chef/daemon.rb +170 -0
- data/lib/chef/exceptions.rb +36 -0
- data/lib/chef/file_cache.rb +205 -0
- data/lib/chef/log.rb +39 -0
- data/lib/chef/mixin/check_helper.rb +31 -0
- data/lib/chef/mixin/checksum.rb +37 -0
- data/lib/chef/mixin/command.rb +351 -0
- data/lib/chef/mixin/create_path.rb +56 -0
- data/lib/chef/mixin/deep_merge.rb +36 -0
- data/lib/chef/mixin/find_preferred_file.rb +99 -0
- data/lib/chef/mixin/from_file.rb +36 -0
- data/lib/chef/mixin/generate_url.rb +48 -0
- data/lib/chef/mixin/language.rb +79 -0
- data/lib/chef/mixin/params_validate.rb +197 -0
- data/lib/chef/mixin/template.rb +84 -0
- data/lib/chef/node.rb +406 -0
- data/lib/chef/node/attribute.rb +412 -0
- data/lib/chef/openid_registration.rb +181 -0
- data/lib/chef/platform.rb +253 -0
- data/lib/chef/provider.rb +40 -0
- data/lib/chef/provider/cron.rb +137 -0
- data/lib/chef/provider/directory.rb +72 -0
- data/lib/chef/provider/execute.rb +58 -0
- data/lib/chef/provider/file.rb +191 -0
- data/lib/chef/provider/group.rb +120 -0
- data/lib/chef/provider/group/groupadd.rb +92 -0
- data/lib/chef/provider/group/pw.rb +88 -0
- data/lib/chef/provider/http_request.rb +102 -0
- data/lib/chef/provider/ifconfig.rb +131 -0
- data/lib/chef/provider/link.rb +157 -0
- data/lib/chef/provider/mount.rb +121 -0
- data/lib/chef/provider/mount/mount.rb +208 -0
- data/lib/chef/provider/package.rb +160 -0
- data/lib/chef/provider/package/apt.rb +110 -0
- data/lib/chef/provider/package/dpkg.rb +113 -0
- data/lib/chef/provider/package/freebsd.rb +153 -0
- data/lib/chef/provider/package/macports.rb +105 -0
- data/lib/chef/provider/package/portage.rb +124 -0
- data/lib/chef/provider/package/rpm.rb +99 -0
- data/lib/chef/provider/package/rubygems.rb +130 -0
- data/lib/chef/provider/package/yum-dump.py +104 -0
- data/lib/chef/provider/package/yum.rb +175 -0
- data/lib/chef/provider/remote_directory.rb +126 -0
- data/lib/chef/provider/remote_file.rb +134 -0
- data/lib/chef/provider/route.rb +118 -0
- data/lib/chef/provider/ruby_block.rb +15 -0
- data/lib/chef/provider/script.rb +42 -0
- data/lib/chef/provider/service.rb +129 -0
- data/lib/chef/provider/service/debian.rb +64 -0
- data/lib/chef/provider/service/freebsd.rb +157 -0
- data/lib/chef/provider/service/gentoo.rb +54 -0
- data/lib/chef/provider/service/init.rb +126 -0
- data/lib/chef/provider/service/redhat.rb +62 -0
- data/lib/chef/provider/template.rb +141 -0
- data/lib/chef/provider/user.rb +170 -0
- data/lib/chef/provider/user/pw.rb +113 -0
- data/lib/chef/provider/user/useradd.rb +107 -0
- data/lib/chef/queue.rb +145 -0
- data/lib/chef/recipe.rb +210 -0
- data/lib/chef/resource.rb +256 -0
- data/lib/chef/resource/apt_package.rb +34 -0
- data/lib/chef/resource/bash.rb +33 -0
- data/lib/chef/resource/cron.rb +143 -0
- data/lib/chef/resource/csh.rb +33 -0
- data/lib/chef/resource/directory.rb +76 -0
- data/lib/chef/resource/dpkg_package.rb +34 -0
- data/lib/chef/resource/execute.rb +127 -0
- data/lib/chef/resource/file.rb +84 -0
- data/lib/chef/resource/gem_package.rb +41 -0
- data/lib/chef/resource/group.rb +68 -0
- data/lib/chef/resource/http_request.rb +52 -0
- data/lib/chef/resource/ifconfig.rb +134 -0
- data/lib/chef/resource/link.rb +78 -0
- data/lib/chef/resource/macports_package.rb +29 -0
- data/lib/chef/resource/mount.rb +135 -0
- data/lib/chef/resource/package.rb +80 -0
- data/lib/chef/resource/perl.rb +33 -0
- data/lib/chef/resource/portage_package.rb +33 -0
- data/lib/chef/resource/python.rb +33 -0
- data/lib/chef/resource/remote_directory.rb +91 -0
- data/lib/chef/resource/remote_file.rb +60 -0
- data/lib/chef/resource/route.rb +135 -0
- data/lib/chef/resource/ruby.rb +33 -0
- data/lib/chef/resource/ruby_block.rb +20 -0
- data/lib/chef/resource/script.rb +51 -0
- data/lib/chef/resource/service.rb +134 -0
- data/lib/chef/resource/template.rb +60 -0
- data/lib/chef/resource/user.rb +98 -0
- data/lib/chef/resource_collection.rb +176 -0
- data/lib/chef/resource_definition.rb +67 -0
- data/lib/chef/rest.rb +238 -0
- data/lib/chef/role.rb +231 -0
- data/lib/chef/run_list.rb +156 -0
- data/lib/chef/runner.rb +123 -0
- data/lib/chef/search.rb +88 -0
- data/lib/chef/search/result.rb +64 -0
- data/lib/chef/search_index.rb +77 -0
- data/lib/chef/tasks/chef_repo.rake +345 -0
- data/lib/chef/util/file_edit.rb +125 -0
- data/lib/chef/util/fileedit.rb +121 -0
- metadata +262 -0
@@ -0,0 +1,253 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.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/config'
|
20
|
+
require 'chef/log'
|
21
|
+
require 'chef/mixin/params_validate'
|
22
|
+
require 'chef/platform'
|
23
|
+
require 'chef/resource'
|
24
|
+
Dir[File.join(File.dirname(__FILE__), 'provider/**/*.rb')].sort.each { |lib| require lib }
|
25
|
+
|
26
|
+
class Chef
|
27
|
+
class Platform
|
28
|
+
|
29
|
+
@platforms = {
|
30
|
+
:mac_os_x => {
|
31
|
+
:default => {
|
32
|
+
:package => Chef::Provider::Package::Macports
|
33
|
+
}
|
34
|
+
},
|
35
|
+
:freebsd => {
|
36
|
+
:default => {
|
37
|
+
:group => Chef::Provider::Group::Pw,
|
38
|
+
:package => Chef::Provider::Package::Freebsd,
|
39
|
+
:service => Chef::Provider::Service::Freebsd,
|
40
|
+
:user => Chef::Provider::User::Pw
|
41
|
+
}
|
42
|
+
},
|
43
|
+
:ubuntu => {
|
44
|
+
:default => {
|
45
|
+
:package => Chef::Provider::Package::Apt,
|
46
|
+
:service => Chef::Provider::Service::Debian,
|
47
|
+
:cron => Chef::Provider::Cron,
|
48
|
+
}
|
49
|
+
},
|
50
|
+
:debian => {
|
51
|
+
:default => {
|
52
|
+
:package => Chef::Provider::Package::Apt,
|
53
|
+
:service => Chef::Provider::Service::Debian,
|
54
|
+
:cron => Chef::Provider::Cron,
|
55
|
+
}
|
56
|
+
},
|
57
|
+
:centos => {
|
58
|
+
:default => {
|
59
|
+
:service => Chef::Provider::Service::Redhat,
|
60
|
+
:cron => Chef::Provider::Cron,
|
61
|
+
:package => Chef::Provider::Package::Yum
|
62
|
+
}
|
63
|
+
},
|
64
|
+
:redhat => {
|
65
|
+
:default => {
|
66
|
+
:service => Chef::Provider::Service::Redhat,
|
67
|
+
:cron => Chef::Provider::Cron,
|
68
|
+
:package => Chef::Provider::Package::Yum
|
69
|
+
}
|
70
|
+
},
|
71
|
+
:gentoo => {
|
72
|
+
:default => {
|
73
|
+
:package => Chef::Provider::Package::Portage,
|
74
|
+
:service => Chef::Provider::Service::Gentoo,
|
75
|
+
:cron => Chef::Provider::Cron,
|
76
|
+
}
|
77
|
+
},
|
78
|
+
:solaris => {},
|
79
|
+
:default => {
|
80
|
+
:file => Chef::Provider::File,
|
81
|
+
:directory => Chef::Provider::Directory,
|
82
|
+
:link => Chef::Provider::Link,
|
83
|
+
:template => Chef::Provider::Template,
|
84
|
+
:remote_file => Chef::Provider::RemoteFile,
|
85
|
+
:remote_directory => Chef::Provider::RemoteDirectory,
|
86
|
+
:execute => Chef::Provider::Execute,
|
87
|
+
:mount => Chef::Provider::Mount::Mount,
|
88
|
+
:script => Chef::Provider::Script,
|
89
|
+
:service => Chef::Provider::Service::Init,
|
90
|
+
:perl => Chef::Provider::Script,
|
91
|
+
:python => Chef::Provider::Script,
|
92
|
+
:ruby => Chef::Provider::Script,
|
93
|
+
:bash => Chef::Provider::Script,
|
94
|
+
:csh => Chef::Provider::Script,
|
95
|
+
:user => Chef::Provider::User::Useradd,
|
96
|
+
:group => Chef::Provider::Group::Groupadd,
|
97
|
+
:http_request => Chef::Provider::HttpRequest,
|
98
|
+
:route => Chef::Provider::Route,
|
99
|
+
:ifconfig => Chef::Provider::Ifconfig,
|
100
|
+
:ruby_block => Chef::Provider::RubyBlock
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
class << self
|
105
|
+
attr_accessor :platforms
|
106
|
+
|
107
|
+
include Chef::Mixin::ParamsValidate
|
108
|
+
|
109
|
+
def find(name, version)
|
110
|
+
provider_map = @platforms[:default].clone
|
111
|
+
|
112
|
+
name_sym = name
|
113
|
+
if name.kind_of?(String)
|
114
|
+
name.downcase!
|
115
|
+
name.gsub!(/\s/, "_")
|
116
|
+
name_sym = name.to_sym
|
117
|
+
end
|
118
|
+
|
119
|
+
if @platforms.has_key?(name_sym)
|
120
|
+
if @platforms[name_sym].has_key?(version)
|
121
|
+
Chef::Log.debug("Platform #{name.to_s} version #{version} found")
|
122
|
+
if @platforms[name_sym].has_key?(:default)
|
123
|
+
provider_map.merge!(@platforms[name_sym][:default])
|
124
|
+
end
|
125
|
+
provider_map.merge!(@platforms[name_sym][version])
|
126
|
+
elsif @platforms[name_sym].has_key?(:default)
|
127
|
+
provider_map.merge!(@platforms[name_sym][:default])
|
128
|
+
end
|
129
|
+
else
|
130
|
+
Chef::Log.debug("Platform #{name} not found, using all defaults. (Unsupported platform?)")
|
131
|
+
end
|
132
|
+
provider_map
|
133
|
+
end
|
134
|
+
|
135
|
+
def find_provider(platform, version, resource_type)
|
136
|
+
pmap = Chef::Platform.find(platform, version)
|
137
|
+
rtkey = resource_type
|
138
|
+
if resource_type.kind_of?(Chef::Resource)
|
139
|
+
return resource_type.provider if resource_type.provider
|
140
|
+
rtkey = resource_type.resource_name.to_sym
|
141
|
+
end
|
142
|
+
if pmap.has_key?(rtkey)
|
143
|
+
pmap[rtkey]
|
144
|
+
else
|
145
|
+
Chef::Log.error("#{rtkey.inspect} #{pmap.inspect}")
|
146
|
+
raise(
|
147
|
+
ArgumentError,
|
148
|
+
"Cannot find a provider for #{resource_type} on #{platform} version #{version}"
|
149
|
+
)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def find_platform_and_version(node)
|
154
|
+
platform = nil
|
155
|
+
version = nil
|
156
|
+
|
157
|
+
if node[:platform]
|
158
|
+
platform = node[:platform]
|
159
|
+
elsif node.attribute?("os")
|
160
|
+
platform = node[:os]
|
161
|
+
end
|
162
|
+
|
163
|
+
raise ArgumentError, "Cannot find a platform for #{node}" unless platform
|
164
|
+
|
165
|
+
if node[:platform_version]
|
166
|
+
version = node[:platform_version]
|
167
|
+
elsif node[:os_version]
|
168
|
+
version = node[:os_version]
|
169
|
+
elsif node[:os_release]
|
170
|
+
version = node[:os_release]
|
171
|
+
end
|
172
|
+
|
173
|
+
raise ArgumentError, "Cannot find a version for #{node}" unless version
|
174
|
+
|
175
|
+
return platform, version
|
176
|
+
end
|
177
|
+
|
178
|
+
def provider_for_node(node, resource_type)
|
179
|
+
find_provider_for_node(node, resource_type).new(node, resource_type)
|
180
|
+
end
|
181
|
+
|
182
|
+
def find_provider_for_node(node, resource_type)
|
183
|
+
platform, version = find_platform_and_version(node)
|
184
|
+
provider = find_provider(platform, version, resource_type)
|
185
|
+
end
|
186
|
+
|
187
|
+
def set(args)
|
188
|
+
validate(
|
189
|
+
args,
|
190
|
+
{
|
191
|
+
:platform => {
|
192
|
+
:kind_of => Symbol,
|
193
|
+
:required => false,
|
194
|
+
},
|
195
|
+
:version => {
|
196
|
+
:kind_of => String,
|
197
|
+
:required => false,
|
198
|
+
},
|
199
|
+
:resource => {
|
200
|
+
:kind_of => Symbol,
|
201
|
+
},
|
202
|
+
:provider => {
|
203
|
+
:kind_of => [ String, Symbol, Class ],
|
204
|
+
}
|
205
|
+
}
|
206
|
+
)
|
207
|
+
if args.has_key?(:platform)
|
208
|
+
if args.has_key?(:version)
|
209
|
+
if @platforms.has_key?(args[:platform])
|
210
|
+
if @platforms[args[:platform]].has_key?(args[:version])
|
211
|
+
@platforms[args[:platform]][args[:version]][args[:resource].to_sym] = args[:provider]
|
212
|
+
else
|
213
|
+
@platforms[args[:platform]][args[:version]] = {
|
214
|
+
args[:resource].to_sym => args[:provider]
|
215
|
+
}
|
216
|
+
end
|
217
|
+
else
|
218
|
+
@platforms[args[:platform]] = {
|
219
|
+
args[:version] => {
|
220
|
+
args[:resource].to_sym => args[:provider]
|
221
|
+
}
|
222
|
+
}
|
223
|
+
end
|
224
|
+
else
|
225
|
+
if @platforms.has_key?(args[:platform])
|
226
|
+
if @platforms[args[:platform]].has_key?(:default)
|
227
|
+
@platforms[args[:platform]][:default][args[:resource].to_sym] = args[:provider]
|
228
|
+
else
|
229
|
+
@platforms[args[:platform]] = { :default => { args[:resource].to_sym => args[:provider] } }
|
230
|
+
end
|
231
|
+
else
|
232
|
+
@platforms[args[:platform]] = {
|
233
|
+
:default => {
|
234
|
+
args[:resource].to_sym => args[:provider]
|
235
|
+
}
|
236
|
+
}
|
237
|
+
end
|
238
|
+
end
|
239
|
+
else
|
240
|
+
if @platforms.has_key?(:default)
|
241
|
+
@platforms[:default][args[:resource].to_sym] = args[:provider]
|
242
|
+
else
|
243
|
+
@platforms[:default] = {
|
244
|
+
args[:resource].to_sym => args[:provider]
|
245
|
+
}
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.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
|
+
|
22
|
+
attr_accessor :node, :new_resource, :current_resource
|
23
|
+
|
24
|
+
def initialize(node, new_resource)
|
25
|
+
@node = node
|
26
|
+
@new_resource = new_resource
|
27
|
+
@current_resource = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def load_current_resource
|
31
|
+
raise Chef::Exceptions::Override, "You must override load_current_resource in #{self.to_s}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def action_nothing
|
35
|
+
Chef::Log.debug("Doing nothing for #{@new_resource.to_s}")
|
36
|
+
true
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,137 @@
|
|
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
|
+
def initialize(node, new_resource)
|
29
|
+
super(node, new_resource)
|
30
|
+
@cron_exists = false
|
31
|
+
@cron_empty = false
|
32
|
+
end
|
33
|
+
attr_accessor :cron_exists, :cron_empty
|
34
|
+
|
35
|
+
def load_current_resource
|
36
|
+
crontab = String.new
|
37
|
+
@current_resource = Chef::Resource::Cron.new(@new_resource.name)
|
38
|
+
status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
|
39
|
+
stdout.each { |line| crontab << line }
|
40
|
+
end
|
41
|
+
if status.exitstatus > 1
|
42
|
+
raise Chef::Exceptions::Cron, "Error determining state of #{@new_resource.name}, exit: #{status.exitstatus}"
|
43
|
+
elsif status.exitstatus == 0
|
44
|
+
crontab.each do |line|
|
45
|
+
case line
|
46
|
+
when /^# Chef Name: #{@new_resource.name}/
|
47
|
+
Chef::Log.debug("Found cron '#{@new_resource.name}'")
|
48
|
+
@cron_exists = true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
Chef::Log.debug("Cron '#{@new_resource.name}' not found") unless @cron_exists
|
52
|
+
elsif status.exitstatus == 1
|
53
|
+
Chef::Log.debug("Cron empty for '#{@new_resource.user}'")
|
54
|
+
@cron_empty = true
|
55
|
+
end
|
56
|
+
|
57
|
+
@current_resource
|
58
|
+
end
|
59
|
+
|
60
|
+
def action_create
|
61
|
+
crontab = String.new
|
62
|
+
cron_found = false
|
63
|
+
if @cron_exists
|
64
|
+
status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
|
65
|
+
stdout.each_line do |line|
|
66
|
+
if cron_found
|
67
|
+
cronline = "#{@new_resource.minute} #{@new_resource.hour} #{@new_resource.day} #{@new_resource.month} #{@new_resource.weekday} #{@new_resource.command}\n"
|
68
|
+
if (line == cronline)
|
69
|
+
Chef::Log.debug("Skipping existing cron entry '#{@new_resource.name}'")
|
70
|
+
return
|
71
|
+
end
|
72
|
+
crontab << cronline
|
73
|
+
cron_found = false
|
74
|
+
next
|
75
|
+
end
|
76
|
+
case line
|
77
|
+
when /^# Chef Name: #{new_resource.name}\n/
|
78
|
+
cron_found = true
|
79
|
+
end
|
80
|
+
crontab << line
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
|
86
|
+
crontab.each { |line| stdin.puts "#{line}" }
|
87
|
+
stdin.close
|
88
|
+
end
|
89
|
+
Chef::Log.info("Updated cron '#{@new_resource.name}'")
|
90
|
+
else
|
91
|
+
unless @cron_empty
|
92
|
+
status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
|
93
|
+
stdout.each { |line| crontab << line }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
crontab << "# Chef Name: #{new_resource.name}\n"
|
98
|
+
crontab << "#{@new_resource.minute} #{@new_resource.hour} #{@new_resource.day} #{@new_resource.month} #{@new_resource.weekday} #{@new_resource.command}\n"
|
99
|
+
|
100
|
+
status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
|
101
|
+
crontab.each { |line| stdin.puts "#{line}" }
|
102
|
+
stdin.close
|
103
|
+
end
|
104
|
+
Chef::Log.info("Added cron '#{@new_resource.name}'")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def action_delete
|
109
|
+
if @cron_exists
|
110
|
+
crontab = String.new
|
111
|
+
cron_found = false
|
112
|
+
status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
|
113
|
+
stdout.each_line do |line|
|
114
|
+
if cron_found
|
115
|
+
cron_found = false
|
116
|
+
next
|
117
|
+
end
|
118
|
+
case line
|
119
|
+
when /^# Chef Name: #{new_resource.name}\n/
|
120
|
+
cron_found = true
|
121
|
+
next
|
122
|
+
end
|
123
|
+
crontab << line
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
|
128
|
+
crontab.each { |line| stdin.puts "#{line}" }
|
129
|
+
stdin.close
|
130
|
+
end
|
131
|
+
Chef::Log.debug("Deleted cron '#{@new_resource.name}'")
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.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/config'
|
20
|
+
require 'chef/log'
|
21
|
+
require 'chef/resource/directory'
|
22
|
+
require 'chef/provider'
|
23
|
+
require 'chef/provider/file'
|
24
|
+
require 'fileutils'
|
25
|
+
|
26
|
+
class Chef
|
27
|
+
class Provider
|
28
|
+
class Directory < Chef::Provider::File
|
29
|
+
def load_current_resource
|
30
|
+
@current_resource = Chef::Resource::Directory.new(@new_resource.name)
|
31
|
+
@current_resource.path(@new_resource.path)
|
32
|
+
if ::File.exist?(@current_resource.path) && ::File.directory?(@current_resource.path)
|
33
|
+
cstats = ::File.stat(@current_resource.path)
|
34
|
+
@current_resource.owner(cstats.uid)
|
35
|
+
@current_resource.group(cstats.gid)
|
36
|
+
@current_resource.mode("%o" % (cstats.mode & 007777))
|
37
|
+
end
|
38
|
+
@current_resource
|
39
|
+
end
|
40
|
+
|
41
|
+
def action_create
|
42
|
+
unless ::File.exists?(@new_resource.path)
|
43
|
+
Chef::Log.info("Creating #{@new_resource} at #{@new_resource.path}")
|
44
|
+
if @new_resource.recursive == true
|
45
|
+
::FileUtils.mkdir_p(@new_resource.path)
|
46
|
+
else
|
47
|
+
::Dir.mkdir(@new_resource.path)
|
48
|
+
end
|
49
|
+
@new_resource.updated = true
|
50
|
+
end
|
51
|
+
set_owner if @new_resource.owner != nil
|
52
|
+
set_group if @new_resource.group != nil
|
53
|
+
set_mode if @new_resource.mode != nil
|
54
|
+
end
|
55
|
+
|
56
|
+
def action_delete
|
57
|
+
if ::File.directory?(@new_resource.path) && ::File.writable?(@new_resource.path)
|
58
|
+
if @new_resource.recursive == true
|
59
|
+
Chef::Log.info("Deleting #{@new_resource} recursively at #{@new_resource.path}")
|
60
|
+
FileUtils.rm_rf(@new_resource.path)
|
61
|
+
else
|
62
|
+
Chef::Log.info("Deleting #{@new_resource} at #{@new_resource.path}")
|
63
|
+
::Dir.delete(@new_resource.path)
|
64
|
+
end
|
65
|
+
@new_resource.updated = true
|
66
|
+
else
|
67
|
+
raise RuntimeError, "Cannot delete #{@new_resource} at #{@new_resource_path}!" if ::File.exists?(@new_resource.path)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|