giraffesoft-chef 0.7.15
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +201 -0
- data/README.rdoc +135 -0
- data/bin/chef-client +26 -0
- data/bin/chef-solo +26 -0
- data/distro/debian/etc/init.d/chef-client +175 -0
- data/distro/debian/etc/init.d/chef-indexer +175 -0
- data/distro/debian/etc/init.d/chef-server +120 -0
- data/distro/debian/man/man1/chef-indexer.1 +42 -0
- data/distro/debian/man/man1/chef-server.1 +108 -0
- data/distro/debian/man/man8/chef-client.8 +61 -0
- data/distro/debian/man/man8/chef-solo.8 +58 -0
- data/distro/redhat/etc/chef/client.rb +16 -0
- data/distro/redhat/etc/chef/indexer.rb +10 -0
- data/distro/redhat/etc/chef/server.rb +22 -0
- data/distro/redhat/etc/init.d/chef-client +74 -0
- data/distro/redhat/etc/init.d/chef-indexer +76 -0
- data/distro/redhat/etc/init.d/chef-server +77 -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 +421 -0
- data/lib/chef/compile.rb +170 -0
- data/lib/chef/config.rb +141 -0
- data/lib/chef/cookbook.rb +171 -0
- data/lib/chef/cookbook/metadata.rb +407 -0
- data/lib/chef/cookbook/metadata/version.rb +87 -0
- data/lib/chef/cookbook_loader.rb +180 -0
- data/lib/chef/couchdb.rb +176 -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 +386 -0
- data/lib/chef/mixin/convert_to_class_name.rb +48 -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 +92 -0
- data/lib/chef/mixin/from_file.rb +50 -0
- data/lib/chef/mixin/generate_url.rb +49 -0
- data/lib/chef/mixin/language.rb +79 -0
- data/lib/chef/mixin/params_validate.rb +197 -0
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +77 -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 +254 -0
- data/lib/chef/provider.rb +101 -0
- data/lib/chef/provider/cron.rb +187 -0
- data/lib/chef/provider/deploy.rb +281 -0
- data/lib/chef/provider/deploy/revision.rb +70 -0
- data/lib/chef/provider/deploy/timestamped.rb +33 -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/git.rb +198 -0
- data/lib/chef/provider/group.rb +120 -0
- data/lib/chef/provider/group/gpasswd.rb +50 -0
- data/lib/chef/provider/group/groupadd.rb +78 -0
- data/lib/chef/provider/group/pw.rb +88 -0
- data/lib/chef/provider/group/usermod.rb +57 -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 +117 -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 +109 -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 +136 -0
- data/lib/chef/provider/package/yum-dump.py +106 -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 +141 -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 +135 -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 +71 -0
- data/lib/chef/provider/service/redhat.rb +62 -0
- data/lib/chef/provider/service/simple.rb +115 -0
- data/lib/chef/provider/subversion.rb +148 -0
- data/lib/chef/provider/template.rb +143 -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 +144 -0
- data/lib/chef/resource.rb +380 -0
- data/lib/chef/resource/apt_package.rb +34 -0
- data/lib/chef/resource/bash.rb +33 -0
- data/lib/chef/resource/cron.rb +179 -0
- data/lib/chef/resource/csh.rb +33 -0
- data/lib/chef/resource/deploy.rb +350 -0
- data/lib/chef/resource/deploy_revision.rb +35 -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/git.rb +36 -0
- data/lib/chef/resource/group.rb +70 -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/scm.rb +129 -0
- data/lib/chef/resource/script.rb +51 -0
- data/lib/chef/resource/service.rb +134 -0
- data/lib/chef/resource/subversion.rb +33 -0
- data/lib/chef/resource/template.rb +60 -0
- data/lib/chef/resource/timestamped_deploy.rb +31 -0
- data/lib/chef/resource/user.rb +98 -0
- data/lib/chef/resource_collection.rb +204 -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 +130 -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 +347 -0
- data/lib/chef/util/file_edit.rb +125 -0
- data/lib/chef/util/fileedit.rb +121 -0
- metadata +293 -0
@@ -0,0 +1,118 @@
|
|
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
|
+
require 'erb'
|
23
|
+
|
24
|
+
class Chef
|
25
|
+
class Provider
|
26
|
+
class Route < Chef::Provider
|
27
|
+
include Chef::Mixin::Command
|
28
|
+
|
29
|
+
def load_current_resource
|
30
|
+
@current_resource = Chef::Resource::Route.new(@new_resource.name)
|
31
|
+
|
32
|
+
Chef::Log.debug("Checking routes for #{@current_resource.target}")
|
33
|
+
status = popen4("route -n") do |pid, stdin, stdout, stderr|
|
34
|
+
stdout.each do |line|
|
35
|
+
case line
|
36
|
+
# Destination Gateway Genmask Flags Metric Ref Use Iface
|
37
|
+
when /^#{@new_resource.target}\s+([\d.]+)\s+([\d.]+)\s+(.+)\s+(\d+)\s+(.+)\s+(.+)\s+(\w+)$/
|
38
|
+
@current_resource.target(@new_resource.target)
|
39
|
+
@current_resource.gateway($1)
|
40
|
+
@current_resource.netmask($2)
|
41
|
+
@current_resource.metric($4.to_i)
|
42
|
+
@current_resource.device($7)
|
43
|
+
Chef::Log.debug("Found route ip:#{@current_resource.target} gw:#{@current_resource.gateway} nm:#{@current_resource.netmask} " +
|
44
|
+
"metric:#{@current_resource.metric} dev:#{@current_resource.device}")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
unless status.exitstatus == 0
|
50
|
+
raise Chef::Exception::Route, "route failed - #{status.inspect}!"
|
51
|
+
end
|
52
|
+
|
53
|
+
@current_resource
|
54
|
+
end
|
55
|
+
|
56
|
+
def action_add
|
57
|
+
# check to see if load_current_resource found the route
|
58
|
+
unless @current_resource.gateway
|
59
|
+
if @new_resource.route_type == :net
|
60
|
+
command = "route add -net #{@new_resource.target}"
|
61
|
+
else
|
62
|
+
command = "route add #{@new_resource.target}"
|
63
|
+
end
|
64
|
+
command << " netmask #{@new_resource.netmask}" if @new_resource.netmask
|
65
|
+
command << " gw #{@new_resource.gateway}" if @new_resource.gateway
|
66
|
+
command << " metric #{@new_resource.metric}" if @new_resource.metric
|
67
|
+
command << " dev #{@new_resource.device}" if @new_resource.device
|
68
|
+
|
69
|
+
run_command(
|
70
|
+
:command => command
|
71
|
+
)
|
72
|
+
@new_resource.updated = true
|
73
|
+
else
|
74
|
+
Chef::Log.debug("Route #{@current_resource} already exists")
|
75
|
+
end
|
76
|
+
# Write out the config files
|
77
|
+
generate_config
|
78
|
+
end
|
79
|
+
|
80
|
+
def action_delete
|
81
|
+
# check to see if load_current_resource found the route
|
82
|
+
if @current_resource.gateway
|
83
|
+
command = "route del #{@new_resource.target}"
|
84
|
+
command << " netmask #{@new_resource.netmask}" if @new_resource.netmask
|
85
|
+
command << " gw #{@new_resource.gateway}" if @new_resource.gateway
|
86
|
+
command << " metric #{@new_resource.metric}" if @new_resource.metric
|
87
|
+
command << " dev #{@new_resource.device}" if @new_resource.device
|
88
|
+
|
89
|
+
run_command(
|
90
|
+
:command => command
|
91
|
+
)
|
92
|
+
@new_resource.updated = true
|
93
|
+
else
|
94
|
+
Chef::Log.debug("Route #{@current_resource} does not exist")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def generate_config
|
99
|
+
b = binding
|
100
|
+
case node[:platform]
|
101
|
+
when ("centos" || "redhat" || "fedora")
|
102
|
+
content = %{
|
103
|
+
<% if @new_resource.networking %>NETWORKING=<%= @new_resource.networking %><% end %>
|
104
|
+
<% if @new_resource.networking_ipv6 %>NETWORKING_IPV6=<%= @new_resource.networking_ipv6 %><% end %>
|
105
|
+
<% if @new_resource.hostname %>HOSTNAME=<%= @new_resource.hostname %><% end %>
|
106
|
+
<% if @new_resource.name %>GATEWAY=<%= @new_resource.name %><% end %>
|
107
|
+
<% if @new_resource.domainname %>DOMAINNAME=<%= @new_resource.domainname %><% end %>
|
108
|
+
<% if @new_resource.domainname %>DOMAIN=<%= @new_resource.domainname %><% end %>
|
109
|
+
}
|
110
|
+
template = ::ERB.new(content)
|
111
|
+
network_file = ::File.new("/etc/sysconfig/network", "w")
|
112
|
+
network_file.puts(template.result(b))
|
113
|
+
network_file.close
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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 'tempfile'
|
20
|
+
require 'chef/provider/execute'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Provider
|
24
|
+
class Script < Chef::Provider::Execute
|
25
|
+
|
26
|
+
def action_run
|
27
|
+
tf = Tempfile.new("chef-script")
|
28
|
+
tf.puts(@new_resource.code)
|
29
|
+
tf.close
|
30
|
+
|
31
|
+
fr = Chef::Resource::File.new(tf.path, nil, @node)
|
32
|
+
fr.owner(@new_resource.user)
|
33
|
+
fr.group(@new_resource.group)
|
34
|
+
fr.run_action(:create)
|
35
|
+
|
36
|
+
@new_resource.command("#{@new_resource.interpreter} #{tf.path}")
|
37
|
+
super
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
#
|
2
|
+
# Author:: AJ Christensen (<aj@hjksolutions.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/mixin/command'
|
20
|
+
require 'chef/provider'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Provider
|
24
|
+
class Service < Chef::Provider
|
25
|
+
|
26
|
+
include Chef::Mixin::Command
|
27
|
+
|
28
|
+
def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
|
29
|
+
super(node, new_resource, collection, definitions, cookbook_loader)
|
30
|
+
@enabled = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def action_enable
|
34
|
+
unless @current_resource.enabled
|
35
|
+
Chef::Log.debug("#{@new_resource}: attempting to enable")
|
36
|
+
status = enable_service()
|
37
|
+
if status
|
38
|
+
@new_resource.updated = true
|
39
|
+
Chef::Log.info("#{@new_resource}: enabled successfully")
|
40
|
+
end
|
41
|
+
else
|
42
|
+
Chef::Log.debug("#{@new_resource}: not enabling, already enabled")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def action_disable
|
47
|
+
if @current_resource.enabled
|
48
|
+
Chef::Log.debug("#{@new_resource}: attempting to disable")
|
49
|
+
status = disable_service()
|
50
|
+
if status
|
51
|
+
@new_resource.updated = true
|
52
|
+
Chef::Log.info("#{@new_resource}: disabled successfully")
|
53
|
+
end
|
54
|
+
else
|
55
|
+
Chef::Log.debug("#{@new_resource}: not disabling, already disabled")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def action_start
|
60
|
+
unless @current_resource.running
|
61
|
+
Chef::Log.debug("#{@new_resource}: attempting to start")
|
62
|
+
status = start_service()
|
63
|
+
if status
|
64
|
+
@new_resource.updated = true
|
65
|
+
Chef::Log.info("Started service #{@new_resource} successfully")
|
66
|
+
end
|
67
|
+
else
|
68
|
+
Chef::Log.debug("#{@new_resource}: not starting, already running")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def action_stop
|
73
|
+
if @current_resource.running
|
74
|
+
Chef::Log.debug("#{@new_resource}: attempting to stop")
|
75
|
+
status = stop_service()
|
76
|
+
if status
|
77
|
+
@new_resource.updated = true
|
78
|
+
Chef::Log.info("#{@new_resource}: stopped successfully")
|
79
|
+
end
|
80
|
+
else
|
81
|
+
Chef::Log.debug("#{@new_resource}: not stopping, already stopped")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def action_restart
|
86
|
+
Chef::Log.debug("#{@new_resource}: attempting to restart")
|
87
|
+
status = restart_service()
|
88
|
+
if status
|
89
|
+
@new_resource.updated = true
|
90
|
+
Chef::Log.info("#{@new_resource}: restarted successfully")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def action_reload
|
95
|
+
unless @new_resource.supports[:reload] or @new_resource.reload_command
|
96
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :reload"
|
97
|
+
else
|
98
|
+
if @current_resource.running
|
99
|
+
Chef::Log.debug("#{@new_resource}: attempting to reload")
|
100
|
+
status = reload_service()
|
101
|
+
if status
|
102
|
+
@new_resource.updated = true
|
103
|
+
Chef::Log.info("#{@new_resource}: reloaded successfully")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def enable_service(name)
|
110
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :enable"
|
111
|
+
end
|
112
|
+
|
113
|
+
def disable_service(name)
|
114
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :disable"
|
115
|
+
end
|
116
|
+
|
117
|
+
def start_service(name)
|
118
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :start"
|
119
|
+
end
|
120
|
+
|
121
|
+
def stop_service(name)
|
122
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :stop"
|
123
|
+
end
|
124
|
+
|
125
|
+
def restart_service(name)
|
126
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :restart"
|
127
|
+
end
|
128
|
+
|
129
|
+
def reload_service(name)
|
130
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :restart"
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#
|
2
|
+
# Author:: AJ Christensen (<aj@hjksolutions.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/provider/service'
|
20
|
+
require 'chef/provider/service/init'
|
21
|
+
require 'chef/mixin/command'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Provider
|
25
|
+
class Service
|
26
|
+
class Debian < Chef::Provider::Service::Init
|
27
|
+
def load_current_resource
|
28
|
+
super
|
29
|
+
|
30
|
+
unless ::File.exists? "/usr/sbin/update-rc.d"
|
31
|
+
raise Chef::Exceptions::Service, "/usr/sbin/update-rc.d does not exist!"
|
32
|
+
end
|
33
|
+
|
34
|
+
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
|
+
stdout.each_line do |line|
|
37
|
+
if r.match(line)
|
38
|
+
@current_resource.enabled true
|
39
|
+
break
|
40
|
+
else
|
41
|
+
@current_resource.enabled false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
unless status.exitstatus == 0
|
47
|
+
raise Chef::Exceptions::Service, "/usr/sbin/update-rc.d -n -f #{@current_resource.service_name} failed - #{status.inspect}"
|
48
|
+
end
|
49
|
+
|
50
|
+
@current_resource
|
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")
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,157 @@
|
|
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/provider/service'
|
20
|
+
require 'chef/mixin/command'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Provider
|
24
|
+
class Service
|
25
|
+
class Freebsd < Chef::Provider::Service::Init
|
26
|
+
|
27
|
+
def load_current_resource
|
28
|
+
@current_resource = Chef::Resource::Service.new(@new_resource.name)
|
29
|
+
@current_resource.service_name(@new_resource.service_name)
|
30
|
+
|
31
|
+
# Determine if we're talking about /etc/rc.d or /usr/local/etc/rc.d
|
32
|
+
if ::File.exists?("/etc/rc.d/#{current_resource.service_name}")
|
33
|
+
@init_command = "/etc/rc.d/#{current_resource.service_name}"
|
34
|
+
elsif ::File.exists?("/usr/local/etc/rc.d/#{current_resource.service_name}")
|
35
|
+
@init_command = "/usr/local/etc/rc.d/#{current_resource.service_name}"
|
36
|
+
else
|
37
|
+
raise Chef::Exceptions::Service, "#{@new_resource}: unable to locate the rc.d script"
|
38
|
+
end
|
39
|
+
Chef::Log.debug("#{@current_resource.name} found at #{@init_command}")
|
40
|
+
|
41
|
+
if @new_resource.supports[:status]
|
42
|
+
Chef::Log.debug("#{@new_resource} supports status, checking state")
|
43
|
+
|
44
|
+
begin
|
45
|
+
if run_command(:command => "#{@init_command} status") == 0
|
46
|
+
@current_resource.running true
|
47
|
+
end
|
48
|
+
rescue Chef::Exceptions::Exec
|
49
|
+
@current_resource.running false
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
|
53
|
+
elsif @new_resource.status_command
|
54
|
+
Chef::Log.debug("#{@new_resource} doesn't support status but you have specified a status command, running..")
|
55
|
+
|
56
|
+
begin
|
57
|
+
if run_command(:command => @new_resource.status_command) == 0
|
58
|
+
@current_resource.running true
|
59
|
+
end
|
60
|
+
rescue Chef::Exceptions::Exec
|
61
|
+
@current_resource.running false
|
62
|
+
nil
|
63
|
+
end
|
64
|
+
|
65
|
+
else
|
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
|
+
|
68
|
+
if @node[:command][:ps].nil? or @node[:command][:ps].empty?
|
69
|
+
raise Chef::Exceptions::Service, "#{@new_resource}: could not determine how to inspect the process table, please set this nodes 'ps' attribute"
|
70
|
+
end
|
71
|
+
|
72
|
+
status = popen4(@node[:command][:ps]) do |pid, stdin, stdout, stderr|
|
73
|
+
stdin.close rescue nil
|
74
|
+
r = Regexp.new(@new_resource.pattern)
|
75
|
+
Chef::Log.debug("#{@new_resource}: attempting to match #{@new_resource.pattern} (#{r}) against process table")
|
76
|
+
stdout.each_line do |line|
|
77
|
+
if r.match(line)
|
78
|
+
@current_resource.running true
|
79
|
+
break
|
80
|
+
end
|
81
|
+
end
|
82
|
+
@current_resource.running false unless @current_resource.running
|
83
|
+
end
|
84
|
+
unless status.exitstatus == 0
|
85
|
+
raise Chef::Exceptions::Service, "Command #{@node[:command][:ps]} failed"
|
86
|
+
else
|
87
|
+
Chef::Log.debug("#{@new_resource}: #{@node[:command][:ps]} exited and parsed successfully, process running: #{@current_resource.running}")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
if ::File.exists?("/etc/rc.conf")
|
92
|
+
read_rc_conf.each do |line|
|
93
|
+
case line
|
94
|
+
when /#{service_enable_variable_name}="(\w+)"/
|
95
|
+
if $1 =~ /[Yy][Ee][Ss]/
|
96
|
+
@current_resource.enabled true
|
97
|
+
elsif $1 =~ /[Nn][Oo][Nn]?[Oo]?[Nn]?[Ee]?/
|
98
|
+
@current_resource.enabled false
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
unless @current_resource.enabled
|
104
|
+
Chef::Log.debug("#{@new_resource.name} enable/disable state unknown")
|
105
|
+
end
|
106
|
+
|
107
|
+
@current_resource
|
108
|
+
end
|
109
|
+
|
110
|
+
def read_rc_conf
|
111
|
+
::File.open("/etc/rc.conf", 'r') { |file| file.readlines }
|
112
|
+
end
|
113
|
+
|
114
|
+
def write_rc_conf(lines)
|
115
|
+
::File.open("/etc/rc.conf", 'w') do |file|
|
116
|
+
lines.each { |line| file.puts(line) }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
# The variable name used in /etc/rc.conf for enabling this service
|
122
|
+
def service_enable_variable_name
|
123
|
+
# Look for name="foo" in the shell script @init_command. Use this for determining the variable name in /etc/rc.conf
|
124
|
+
# corresponding to this service
|
125
|
+
# For example: to enable the service mysql-server with the init command /usr/local/etc/rc.d/mysql-server, you need
|
126
|
+
# to set mysql_enable="YES" in /etc/rc.conf
|
127
|
+
makefile = ::File.open(@init_command)
|
128
|
+
makefile.each do |line|
|
129
|
+
case line
|
130
|
+
when /^name="?(\w+)"?/
|
131
|
+
return $1 + "_enable"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
raise Chef::Exceptions::Service, "Could not find name=\"service\" line in #{@init_command}"
|
135
|
+
end
|
136
|
+
|
137
|
+
def set_service_enable(value)
|
138
|
+
lines = read_rc_conf
|
139
|
+
# Remove line that set the old value
|
140
|
+
lines.delete_if { |line| line =~ /#{service_enable_variable_name}/ }
|
141
|
+
# And append the line that sets the new value at the end
|
142
|
+
lines << "#{service_enable_variable_name}=\"#{value}\""
|
143
|
+
write_rc_conf(lines)
|
144
|
+
end
|
145
|
+
|
146
|
+
def enable_service()
|
147
|
+
set_service_enable("YES") unless @current_resource.enabled
|
148
|
+
end
|
149
|
+
|
150
|
+
def disable_service()
|
151
|
+
set_service_enable("NO") if @current_resource.enabled
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|