microwave 0.1004.4 → 0.1004.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +0 -3
- data/lib/chef/client.rb +2 -11
- data/lib/chef/platform.rb +1 -192
- data/lib/chef/providers.rb +0 -68
- data/lib/chef/resources.rb +0 -36
- data/lib/chef/version.rb +1 -1
- metadata +123 -239
- data/lib/chef/provider/breakpoint.rb +0 -31
- data/lib/chef/provider/cron.rb +0 -186
- data/lib/chef/provider/cron/solaris.rb +0 -195
- data/lib/chef/provider/deploy.rb +0 -343
- data/lib/chef/provider/deploy/revision.rb +0 -80
- data/lib/chef/provider/deploy/timestamped.rb +0 -33
- data/lib/chef/provider/env.rb +0 -152
- data/lib/chef/provider/env/windows.rb +0 -75
- data/lib/chef/provider/erl_call.rb +0 -101
- data/lib/chef/provider/git.rb +0 -243
- data/lib/chef/provider/group.rb +0 -133
- data/lib/chef/provider/group/aix.rb +0 -70
- data/lib/chef/provider/group/dscl.rb +0 -121
- data/lib/chef/provider/group/gpasswd.rb +0 -53
- data/lib/chef/provider/group/groupadd.rb +0 -81
- data/lib/chef/provider/group/pw.rb +0 -84
- data/lib/chef/provider/group/suse.rb +0 -53
- data/lib/chef/provider/group/usermod.rb +0 -57
- data/lib/chef/provider/group/windows.rb +0 -79
- data/lib/chef/provider/ifconfig.rb +0 -134
- data/lib/chef/provider/log.rb +0 -54
- data/lib/chef/provider/mdadm.rb +0 -91
- data/lib/chef/provider/mount.rb +0 -114
- data/lib/chef/provider/mount/mount.rb +0 -240
- data/lib/chef/provider/mount/windows.rb +0 -81
- data/lib/chef/provider/ohai.rb +0 -42
- data/lib/chef/provider/package.rb +0 -163
- data/lib/chef/provider/package/apt.rb +0 -135
- data/lib/chef/provider/package/dpkg.rb +0 -115
- data/lib/chef/provider/package/easy_install.rb +0 -136
- data/lib/chef/provider/package/freebsd.rb +0 -125
- data/lib/chef/provider/package/macports.rb +0 -105
- data/lib/chef/provider/package/pacman.rb +0 -101
- data/lib/chef/provider/package/portage.rb +0 -135
- data/lib/chef/provider/package/rpm.rb +0 -104
- data/lib/chef/provider/package/rubygems.rb +0 -465
- data/lib/chef/provider/package/solaris.rb +0 -130
- data/lib/chef/provider/package/yum.rb +0 -1128
- data/lib/chef/provider/package/zypper.rb +0 -144
- data/lib/chef/provider/route.rb +0 -193
- data/lib/chef/provider/ruby_block.rb +0 -34
- data/lib/chef/provider/script.rb +0 -55
- data/lib/chef/provider/service.rb +0 -122
- data/lib/chef/provider/service/arch.rb +0 -116
- data/lib/chef/provider/service/debian.rb +0 -130
- data/lib/chef/provider/service/freebsd.rb +0 -154
- data/lib/chef/provider/service/gentoo.rb +0 -53
- data/lib/chef/provider/service/init.rb +0 -71
- data/lib/chef/provider/service/insserv.rb +0 -52
- data/lib/chef/provider/service/redhat.rb +0 -60
- data/lib/chef/provider/service/simple.rb +0 -120
- data/lib/chef/provider/service/solaris.rb +0 -85
- data/lib/chef/provider/service/systemd.rb +0 -102
- data/lib/chef/provider/service/upstart.rb +0 -198
- data/lib/chef/provider/service/windows.rb +0 -146
- data/lib/chef/provider/subversion.rb +0 -197
- data/lib/chef/provider/user.rb +0 -186
- data/lib/chef/provider/user/dscl.rb +0 -280
- data/lib/chef/provider/user/pw.rb +0 -113
- data/lib/chef/provider/user/useradd.rb +0 -137
- data/lib/chef/provider/user/windows.rb +0 -124
- data/lib/chef/resource/apt_package.rb +0 -34
- data/lib/chef/resource/bash.rb +0 -33
- data/lib/chef/resource/breakpoint.rb +0 -35
- data/lib/chef/resource/cron.rb +0 -188
- data/lib/chef/resource/csh.rb +0 -33
- data/lib/chef/resource/deploy.rb +0 -380
- data/lib/chef/resource/deploy_revision.rb +0 -40
- data/lib/chef/resource/dpkg_package.rb +0 -34
- data/lib/chef/resource/easy_install_package.rb +0 -57
- data/lib/chef/resource/erl_call.rb +0 -83
- data/lib/chef/resource/freebsd_package.rb +0 -35
- data/lib/chef/resource/gem_package.rb +0 -53
- data/lib/chef/resource/git.rb +0 -46
- data/lib/chef/resource/group.rb +0 -70
- data/lib/chef/resource/ifconfig.rb +0 -134
- data/lib/chef/resource/log.rb +0 -62
- data/lib/chef/resource/macports_package.rb +0 -29
- data/lib/chef/resource/mdadm.rb +0 -82
- data/lib/chef/resource/mount.rb +0 -134
- data/lib/chef/resource/ohai.rb +0 -40
- data/lib/chef/resource/package.rb +0 -80
- data/lib/chef/resource/pacman_package.rb +0 -33
- data/lib/chef/resource/perl.rb +0 -33
- data/lib/chef/resource/portage_package.rb +0 -33
- data/lib/chef/resource/python.rb +0 -33
- data/lib/chef/resource/route.rb +0 -135
- data/lib/chef/resource/rpm_package.rb +0 -34
- data/lib/chef/resource/ruby.rb +0 -33
- data/lib/chef/resource/ruby_block.rb +0 -40
- data/lib/chef/resource/scm.rb +0 -147
- data/lib/chef/resource/script.rb +0 -60
- data/lib/chef/resource/service.rb +0 -160
- data/lib/chef/resource/solaris_package.rb +0 -36
- data/lib/chef/resource/subversion.rb +0 -36
- data/lib/chef/resource/timestamped_deploy.rb +0 -31
- data/lib/chef/resource/user.rb +0 -130
- data/lib/chef/resource/yum_package.rb +0 -63
@@ -1,198 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Bryan McLellan <btm@loftninjas.org>
|
3
|
-
# Copyright:: Copyright (c) 2010 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/provider/service/simple'
|
21
|
-
require 'chef/mixin/command'
|
22
|
-
require 'chef/util/file_edit'
|
23
|
-
|
24
|
-
class Chef
|
25
|
-
class Provider
|
26
|
-
class Service
|
27
|
-
class Upstart < Chef::Provider::Service::Simple
|
28
|
-
UPSTART_STATE_FORMAT = /\w+ \(?(\w+)\)?[\/ ](\w+)/
|
29
|
-
|
30
|
-
# Upstart does more than start or stop a service, creating multiple 'states' [1] that a service can be in.
|
31
|
-
# In chef, when we ask a service to start, we expect it to have started before performing the next step
|
32
|
-
# since we have top down dependencies. Which is to say we may follow witha resource next that requires
|
33
|
-
# that service to be running. According to [2] we can trust that sending a 'goal' such as start will not
|
34
|
-
# return until that 'goal' is reached, or some error has occured.
|
35
|
-
#
|
36
|
-
# [1] http://upstart.ubuntu.com/wiki/JobStates
|
37
|
-
# [2] http://www.netsplit.com/2008/04/27/upstart-05-events/
|
38
|
-
|
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)
|
47
|
-
if platform == "ubuntu" && (8.04..9.04).include?(version.to_f)
|
48
|
-
@upstart_job_dir = "/etc/event.d"
|
49
|
-
@upstart_conf_suffix = ""
|
50
|
-
else
|
51
|
-
@upstart_job_dir = "/etc/init"
|
52
|
-
@upstart_conf_suffix = ".conf"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def load_current_resource
|
57
|
-
@current_resource = Chef::Resource::Service.new(@new_resource.name)
|
58
|
-
@current_resource.service_name(@new_resource.service_name)
|
59
|
-
|
60
|
-
# Get running/stopped state
|
61
|
-
# We do not support searching for a service via ps when using upstart since status is a native
|
62
|
-
# upstart function. We will however support status_command in case someone wants to do something special.
|
63
|
-
if @new_resource.status_command
|
64
|
-
Chef::Log.debug("#{@new_resource} you have specified a status command, running..")
|
65
|
-
|
66
|
-
begin
|
67
|
-
if run_command_with_systems_locale(:command => @new_resource.status_command) == 0
|
68
|
-
@current_resource.running true
|
69
|
-
end
|
70
|
-
rescue Chef::Exceptions::Exec
|
71
|
-
@current_resource.running false
|
72
|
-
nil
|
73
|
-
end
|
74
|
-
else
|
75
|
-
begin
|
76
|
-
if upstart_state == "running"
|
77
|
-
@current_resource.running true
|
78
|
-
else
|
79
|
-
@current_resource.running false
|
80
|
-
end
|
81
|
-
rescue Chef::Exceptions::Exec
|
82
|
-
@current_resource.running false
|
83
|
-
nil
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# Get enabled/disabled state by reading job configuration file
|
88
|
-
if ::File.exists?("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}")
|
89
|
-
Chef::Log.debug("#{@new_resource} found #{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}")
|
90
|
-
::File.open("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}",'r') do |file|
|
91
|
-
while line = file.gets
|
92
|
-
case line
|
93
|
-
when /^start on/
|
94
|
-
Chef::Log.debug("#{@new_resource} enabled: #{line.chomp}")
|
95
|
-
@current_resource.enabled true
|
96
|
-
break
|
97
|
-
when /^#start on/
|
98
|
-
Chef::Log.debug("#{@new_resource} disabled: #{line.chomp}")
|
99
|
-
@current_resource.enabled false
|
100
|
-
break
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
else
|
105
|
-
Chef::Log.debug("#{@new_resource} did not find #{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}")
|
106
|
-
@current_resource.enabled false
|
107
|
-
end
|
108
|
-
|
109
|
-
@current_resource
|
110
|
-
end
|
111
|
-
|
112
|
-
def start_service
|
113
|
-
# Calling start on a service that is already started will return 1
|
114
|
-
# Our 'goal' when we call start is to ensure the service is started
|
115
|
-
if @current_resource.running
|
116
|
-
Chef::Log.debug("#{@new_resource} already running, not starting")
|
117
|
-
else
|
118
|
-
if @new_resource.start_command
|
119
|
-
super
|
120
|
-
else
|
121
|
-
run_command_with_systems_locale(:command => "/sbin/start #{@new_resource.service_name}")
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def stop_service
|
127
|
-
# Calling stop on a service that is already stopped will return 1
|
128
|
-
# Our 'goal' when we call stop is to ensure the service is stopped
|
129
|
-
unless @current_resource.running
|
130
|
-
Chef::Log.debug("#{@new_resource} not running, not stopping")
|
131
|
-
else
|
132
|
-
if @new_resource.stop_command
|
133
|
-
super
|
134
|
-
else
|
135
|
-
run_command_with_systems_locale(:command => "/sbin/stop #{@new_resource.service_name}")
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def restart_service
|
141
|
-
if @new_resource.restart_command
|
142
|
-
super
|
143
|
-
# Upstart always provides restart functionality so we don't need to mimic it with stop/sleep/start.
|
144
|
-
# Older versions of upstart would fail on restart if the service was currently stopped, check for that. LP:430883
|
145
|
-
else @new_resource.supports[:restart]
|
146
|
-
if @current_resource.running
|
147
|
-
run_command_with_systems_locale(:command => "/sbin/restart #{@new_resource.service_name}")
|
148
|
-
else
|
149
|
-
start_service
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def reload_service
|
155
|
-
if @new_resource.reload_command
|
156
|
-
super
|
157
|
-
else
|
158
|
-
# upstart >= 0.6.3-4 supports reload (HUP)
|
159
|
-
run_command_with_systems_locale(:command => "/sbin/reload #{@new_resource.service_name}")
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
# https://bugs.launchpad.net/upstart/+bug/94065
|
164
|
-
|
165
|
-
def enable_service
|
166
|
-
Chef::Log.debug("#{@new_resource} upstart lacks inherent support for enabling services, editing job config file")
|
167
|
-
conf = Chef::Util::FileEdit.new("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}")
|
168
|
-
conf.search_file_replace(/^#start on/, "start on")
|
169
|
-
conf.write_file
|
170
|
-
end
|
171
|
-
|
172
|
-
def disable_service
|
173
|
-
Chef::Log.debug("#{@new_resource} upstart lacks inherent support for disabling services, editing job config file")
|
174
|
-
conf = Chef::Util::FileEdit.new("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}")
|
175
|
-
conf.search_file_replace(/^start on/, "#start on")
|
176
|
-
conf.write_file
|
177
|
-
end
|
178
|
-
|
179
|
-
def upstart_state
|
180
|
-
command = "/sbin/status #{@new_resource.service_name}"
|
181
|
-
status = popen4(command) do |pid, stdin, stdout, stderr|
|
182
|
-
stdout.each_line do |line|
|
183
|
-
# rsyslog stop/waiting
|
184
|
-
# service goal/state
|
185
|
-
# OR
|
186
|
-
# rsyslog (stop) waiting
|
187
|
-
# service (goal) state
|
188
|
-
line =~ UPSTART_STATE_FORMAT
|
189
|
-
data = Regexp.last_match
|
190
|
-
return data[2]
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
@@ -1,146 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Nuo Yan <nuo@opscode.com>
|
3
|
-
# Author:: Bryan McLellan <btm@loftninjas.org>
|
4
|
-
# Copyright:: Copyright (c) 2010 Opscode, Inc
|
5
|
-
# License:: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
|
20
|
-
# pick up popen4 from chef/mixin/command/windows
|
21
|
-
require 'chef/mixin/command'
|
22
|
-
require 'chef/provider/service/simple'
|
23
|
-
|
24
|
-
class Chef::Provider::Service::Windows < Chef::Provider::Service::Simple
|
25
|
-
|
26
|
-
def initialize(new_resource, run_context)
|
27
|
-
super
|
28
|
-
@init_command = "sc"
|
29
|
-
end
|
30
|
-
|
31
|
-
def io_popen(command)
|
32
|
-
io = IO.popen(command)
|
33
|
-
entries = io.readlines
|
34
|
-
io.close
|
35
|
-
entries
|
36
|
-
end
|
37
|
-
|
38
|
-
def load_current_resource
|
39
|
-
@current_resource = Chef::Resource::Service.new(@new_resource.name)
|
40
|
-
@current_resource.service_name(@new_resource.service_name)
|
41
|
-
begin
|
42
|
-
# Check if service is running
|
43
|
-
status = popen4("#{@init_command} query #{@new_resource.service_name}") do |pid, stdin, stdout, stderr|
|
44
|
-
stdout.each_line do |line|
|
45
|
-
raise Chef::Exceptions::Service, "Service #{@new_resource.service_name} does not exist.\n#{stdout}\n" if line =~ /FAILED 1060/
|
46
|
-
@current_resource.running true if line =~/RUNNING/
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# Check if service is enabled
|
51
|
-
status = popen4("#{@init_command} qc #{@new_resource.service_name}") do |pid, stdin, stdout, stderr|
|
52
|
-
stdout.each_line do |line|
|
53
|
-
raise Chef::Exceptions::Service, "Service #{@new_resource.service_name} does not exist.\n#{stdout}\n" if line =~ /FAILED 1060/
|
54
|
-
@current_resource.enabled true if line =~/AUTO_START/
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
Chef::Log.debug "#{@new_resource} running: #{@current_resource.running}"
|
59
|
-
rescue Exception => e
|
60
|
-
raise Chef::Exceptions::Service, "Exception determining state of service #{@new_resource.service_name}: #{e.message}"
|
61
|
-
end
|
62
|
-
@current_resource
|
63
|
-
end
|
64
|
-
|
65
|
-
def start_service
|
66
|
-
begin
|
67
|
-
if @new_resource.start_command
|
68
|
-
popen4(@new_resource.start_command) do |pid, stdin, stdout, stderr|
|
69
|
-
Chef::Log.debug stdout.readlines
|
70
|
-
end
|
71
|
-
else
|
72
|
-
popen4("#{@init_command} start #{@new_resource.service_name}") do |pid, stdin, stdout, stderr|
|
73
|
-
output = stdout.readlines
|
74
|
-
Chef::Log.debug output.join
|
75
|
-
output.join =~ /RUNNING/ || output.join =~ /START_PENDING/ ? true : false
|
76
|
-
end
|
77
|
-
end
|
78
|
-
rescue Exception => e
|
79
|
-
raise Chef::Exceptions::Service, "Failed to start service #{@new_resource.service_name}: #{e.message}"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def stop_service
|
84
|
-
begin
|
85
|
-
if @new_resource.stop_command
|
86
|
-
Chef::Log.debug "#{@new_resource} stopping service using the given stop_command"
|
87
|
-
popen4(@new_resource.stop_command) do |pid, stdin, stdout, stderr|
|
88
|
-
Chef::Log.debug stdout.readlines
|
89
|
-
end
|
90
|
-
else
|
91
|
-
popen4("#{@init_command} stop #{@new_resource.service_name}") do |pid, stdin, stdout, stderr|
|
92
|
-
output = stdout.readlines
|
93
|
-
Chef::Log.debug output.join
|
94
|
-
raise Chef::Exceptions::Service, "Service #{@new_resource.service_name} has dependencies and cannot be stopped.\n" if output.join =~ /FAILED 1051/
|
95
|
-
output.join =~ /1/
|
96
|
-
end
|
97
|
-
end
|
98
|
-
rescue Exception => e
|
99
|
-
raise Chef::Exceptions::Service, "Failed to start service #{@new_resource.service_name}: #{e.message}"
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def restart_service
|
104
|
-
begin
|
105
|
-
if @new_resource.restart_command
|
106
|
-
Chef::Log.debug "#{@new_resource} restarting service using the given restart_command"
|
107
|
-
popen4(@new_resource.restart_command) do |pid, stdin, stdout, stderr|
|
108
|
-
Chef::Log.debug stdout.readlines
|
109
|
-
end
|
110
|
-
else
|
111
|
-
stop_service
|
112
|
-
sleep 1
|
113
|
-
start_service
|
114
|
-
end
|
115
|
-
rescue Exception => e
|
116
|
-
raise Chef::Exceptions::Service, "Failed to start service #{@new_resource.service_name}: #{e.message}"
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def enable_service()
|
121
|
-
begin
|
122
|
-
popen4("#{@init_command} config #{@new_resource.service_name} start= #{determine_startup_type}") do |pid, stdin, stdout, stderr|
|
123
|
-
stdout.readlines.join =~ /SUCCESS/
|
124
|
-
end
|
125
|
-
rescue Exception => e
|
126
|
-
raise Chef::Exceptions::Service, "Failed to start service #{@new_resource.service_name}: #{e.message}"
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def disable_service()
|
131
|
-
begin
|
132
|
-
popen4("#{@init_command} config #{@new_resource.service_name} start= disabled") do |pid, stdin, stdout, stderr|
|
133
|
-
stdout.readlines.join =~ /SUCCESS/
|
134
|
-
end
|
135
|
-
rescue Exception => e
|
136
|
-
raise Chef::Exceptions::Service, "Failed to start service #{@new_resource.service_name}: #{e.message}"
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
private
|
141
|
-
|
142
|
-
def determine_startup_type
|
143
|
-
{:automatic => 'auto', :mannual => 'demand'}[@new_resource.startup_type]
|
144
|
-
end
|
145
|
-
|
146
|
-
end
|
@@ -1,197 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Daniel DeLeo (<dan@kallistec.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
|
-
|
20
|
-
require 'chef/log'
|
21
|
-
require 'chef/provider'
|
22
|
-
require 'chef/mixin/command'
|
23
|
-
require 'fileutils'
|
24
|
-
|
25
|
-
class Chef
|
26
|
-
class Provider
|
27
|
-
class Subversion < Chef::Provider
|
28
|
-
|
29
|
-
include Chef::Mixin::Command
|
30
|
-
|
31
|
-
def load_current_resource
|
32
|
-
@current_resource = Chef::Resource::Subversion.new(@new_resource.name)
|
33
|
-
|
34
|
-
unless [:export, :force_export].include?(Array(@new_resource.action).first)
|
35
|
-
if current_revision = find_current_revision
|
36
|
-
@current_resource.revision current_revision
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def action_checkout
|
42
|
-
assert_target_directory_valid!
|
43
|
-
if target_dir_non_existant_or_empty?
|
44
|
-
run_command(run_options(:command => checkout_command))
|
45
|
-
@new_resource.updated_by_last_action(true)
|
46
|
-
else
|
47
|
-
Chef::Log.debug "#{@new_resource} checkout destination #{@new_resource.destination} already exists or is a non-empty directory - nothing to do"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def action_export
|
52
|
-
assert_target_directory_valid!
|
53
|
-
if target_dir_non_existant_or_empty?
|
54
|
-
run_command(run_options(:command => export_command))
|
55
|
-
@new_resource.updated_by_last_action(true)
|
56
|
-
else
|
57
|
-
Chef::Log.debug "#{@new_resource} export destination #{@new_resource.destination} already exists or is a non-empty directory - nothing to do"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def action_force_export
|
62
|
-
assert_target_directory_valid!
|
63
|
-
run_command(run_options(:command => export_command))
|
64
|
-
@new_resource.updated_by_last_action(true)
|
65
|
-
end
|
66
|
-
|
67
|
-
def action_sync
|
68
|
-
assert_target_directory_valid!
|
69
|
-
if ::File.exist?(::File.join(@new_resource.destination, ".svn"))
|
70
|
-
current_rev = find_current_revision
|
71
|
-
Chef::Log.debug "#{@new_resource} current revision: #{current_rev} target revision: #{revision_int}"
|
72
|
-
unless current_revision_matches_target_revision?
|
73
|
-
run_command(run_options(:command => sync_command))
|
74
|
-
Chef::Log.info "#{@new_resource} updated to revision: #{revision_int}"
|
75
|
-
@new_resource.updated_by_last_action(true)
|
76
|
-
end
|
77
|
-
else
|
78
|
-
action_checkout
|
79
|
-
@new_resource.updated_by_last_action(true)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def sync_command
|
84
|
-
c = scm :update, @new_resource.svn_arguments, verbose, authentication, "-r#{revision_int}", @new_resource.destination
|
85
|
-
Chef::Log.debug "#{@new_resource} updated working copy #{@new_resource.destination} to revision #{@new_resource.revision}"
|
86
|
-
c
|
87
|
-
end
|
88
|
-
|
89
|
-
def checkout_command
|
90
|
-
c = scm :checkout, @new_resource.svn_arguments, verbose, authentication,
|
91
|
-
"-r#{revision_int}", @new_resource.repository, @new_resource.destination
|
92
|
-
Chef::Log.info "#{@new_resource} checked out #{@new_resource.repository} at revision #{@new_resource.revision} to #{@new_resource.destination}"
|
93
|
-
c
|
94
|
-
end
|
95
|
-
|
96
|
-
def export_command
|
97
|
-
args = ["--force"]
|
98
|
-
args << @new_resource.svn_arguments << verbose << authentication <<
|
99
|
-
"-r#{revision_int}" << @new_resource.repository << @new_resource.destination
|
100
|
-
c = scm :export, *args
|
101
|
-
Chef::Log.info "#{@new_resource} exported #{@new_resource.repository} at revision #{@new_resource.revision} to #{@new_resource.destination}"
|
102
|
-
c
|
103
|
-
end
|
104
|
-
|
105
|
-
# If the specified revision isn't an integer ("HEAD" for example), look
|
106
|
-
# up the revision id by asking the server
|
107
|
-
# If the specified revision is an integer, trust it.
|
108
|
-
def revision_int
|
109
|
-
@revision_int ||= begin
|
110
|
-
if @new_resource.revision =~ /^\d+$/
|
111
|
-
@new_resource.revision
|
112
|
-
else
|
113
|
-
command = scm(:info, @new_resource.repository, @new_resource.svn_info_args, authentication, "-r#{@new_resource.revision}")
|
114
|
-
status, svn_info, error_message = output_of_command(command, run_options)
|
115
|
-
handle_command_failures(status, "STDOUT: #{svn_info}\nSTDERR: #{error_message}")
|
116
|
-
extract_revision_info(svn_info)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
alias :revision_slug :revision_int
|
122
|
-
|
123
|
-
def find_current_revision
|
124
|
-
return nil unless ::File.exist?(::File.join(@new_resource.destination, ".svn"))
|
125
|
-
command = scm(:info)
|
126
|
-
status, svn_info, error_message = output_of_command(command, run_options(:cwd => cwd))
|
127
|
-
|
128
|
-
unless [0,1].include?(status.exitstatus)
|
129
|
-
handle_command_failures(status, "STDOUT: #{svn_info}\nSTDERR: #{error_message}")
|
130
|
-
end
|
131
|
-
extract_revision_info(svn_info)
|
132
|
-
end
|
133
|
-
|
134
|
-
def current_revision_matches_target_revision?
|
135
|
-
(!@current_resource.revision.nil?) && (revision_int.strip.to_i == @current_resource.revision.strip.to_i)
|
136
|
-
end
|
137
|
-
|
138
|
-
def run_options(run_opts={})
|
139
|
-
run_opts[:user] = @new_resource.user if @new_resource.user
|
140
|
-
run_opts[:group] = @new_resource.group if @new_resource.group
|
141
|
-
run_opts
|
142
|
-
end
|
143
|
-
|
144
|
-
private
|
145
|
-
|
146
|
-
def cwd
|
147
|
-
@new_resource.destination
|
148
|
-
end
|
149
|
-
|
150
|
-
def verbose
|
151
|
-
"-q"
|
152
|
-
end
|
153
|
-
|
154
|
-
def extract_revision_info(svn_info)
|
155
|
-
begin
|
156
|
-
repo_attrs = YAML.load(svn_info)
|
157
|
-
rescue ArgumentError
|
158
|
-
# YAML doesn't appreciate input like "svn: '/tmp/deploydir' is not a working copy\n"
|
159
|
-
return nil
|
160
|
-
end
|
161
|
-
raise "Could not parse `svn info` data: #{svn_info}" unless repo_attrs.kind_of?(Hash)
|
162
|
-
rev = (repo_attrs['Last Changed Rev'] || repo_attrs['Revision']).to_s
|
163
|
-
Chef::Log.debug "#{@new_resource} resolved revision #{@new_resource.revision} to #{rev}"
|
164
|
-
rev
|
165
|
-
end
|
166
|
-
|
167
|
-
# If a username is configured for the SCM, return the command-line
|
168
|
-
# switches for that. Note that we don't need to return the password
|
169
|
-
# switch, since Capistrano will check for that prompt in the output
|
170
|
-
# and will respond appropriately.
|
171
|
-
def authentication
|
172
|
-
return "" unless @new_resource.svn_username
|
173
|
-
result = "--username #{@new_resource.svn_username} "
|
174
|
-
result << "--password #{@new_resource.svn_password} "
|
175
|
-
result
|
176
|
-
end
|
177
|
-
|
178
|
-
def scm(*args)
|
179
|
-
['svn', *args].compact.join(" ")
|
180
|
-
end
|
181
|
-
|
182
|
-
# TODO these methods are the same as the git provider...need to REFACTOR
|
183
|
-
# ...the subversion and git providers should extend from the same parent
|
184
|
-
def assert_target_directory_valid!
|
185
|
-
target_parent_directory = ::File.dirname(@new_resource.destination)
|
186
|
-
unless ::File.directory?(target_parent_directory)
|
187
|
-
msg = "Cannot clone #{@new_resource} to #{@new_resource.destination}, the enclosing directory #{target_parent_directory} does not exist"
|
188
|
-
raise Chef::Exceptions::MissingParentDirectory, msg
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
def target_dir_non_existant_or_empty?
|
193
|
-
!::File.exist?(@new_resource.destination) || Dir.entries(@new_resource.destination).sort == ['.','..']
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|