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,54 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Lee Jensen (<ljensen@engineyard.com>)
|
3
|
+
# Author:: AJ Christensen (<aj@opscode.com>)
|
4
|
+
# Copyright:: Copyright (c) 2008 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
|
+
require 'chef/provider/service'
|
21
|
+
require 'chef/mixin/command'
|
22
|
+
|
23
|
+
class Chef::Provider::Service::Gentoo < Chef::Provider::Service::Init
|
24
|
+
def load_current_resource
|
25
|
+
|
26
|
+
@new_resource.supports[:status] = true
|
27
|
+
@new_resource.supports[:restart] = true
|
28
|
+
|
29
|
+
super
|
30
|
+
|
31
|
+
raise Chef::Exceptions::Service unless ::File.exists?("/sbin/rc-update")
|
32
|
+
|
33
|
+
Chef::Log.debug "#{@new_resource}: checking service enable state"
|
34
|
+
@current_resource.enabled(
|
35
|
+
Dir.glob("/etc/runlevels/**/#{@current_resource.service_name}").any? do |file|
|
36
|
+
exists = ::File.exists? file
|
37
|
+
readable = ::File.readable? file
|
38
|
+
Chef::Log.debug "#{@new_resource}: exists: #{exists}, readable: #{readable}"
|
39
|
+
exists and readable
|
40
|
+
end
|
41
|
+
)
|
42
|
+
Chef::Log.debug "#{@new_resource}: enabled: #{@current_resource.enabled}"
|
43
|
+
|
44
|
+
@current_resource
|
45
|
+
end
|
46
|
+
|
47
|
+
def enable_service()
|
48
|
+
run_command(:command => "/sbin/rc-update add #{@new_resource.service_name} default")
|
49
|
+
end
|
50
|
+
|
51
|
+
def disable_service()
|
52
|
+
run_command(:command => "/sbin/rc-update del #{@new_resource.service_name} default")
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,71 @@
|
|
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/simple'
|
21
|
+
require 'chef/mixin/command'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Provider
|
25
|
+
class Service
|
26
|
+
class Init < Chef::Provider::Service::Simple
|
27
|
+
|
28
|
+
def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
|
29
|
+
super(node, new_resource, collection, definitions, cookbook_loader)
|
30
|
+
@init_command = "/etc/init.d/#{@new_resource.service_name}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def start_service
|
34
|
+
if @new_resource.start_command
|
35
|
+
super
|
36
|
+
else
|
37
|
+
run_command(:command => "#{@init_command} start")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def stop_service
|
42
|
+
if @new_resource.stop_command
|
43
|
+
super
|
44
|
+
else
|
45
|
+
run_command(:command => "#{@init_command} stop")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def restart_service
|
50
|
+
if @new_resource.restart_command
|
51
|
+
super
|
52
|
+
elsif @new_resource.supports[:restart]
|
53
|
+
run_command(:command => "#{@init_command} restart")
|
54
|
+
else
|
55
|
+
stop_service
|
56
|
+
sleep 1
|
57
|
+
start_service
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def reload_service
|
62
|
+
if @new_resource.reload_command
|
63
|
+
super
|
64
|
+
elsif @new_resource.supports[:reload]
|
65
|
+
run_command(:command => "#{@init_command} reload")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,62 @@
|
|
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 Redhat < Chef::Provider::Service::Init
|
27
|
+
|
28
|
+
def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
|
29
|
+
super(node, new_resource, collection, definitions, cookbook_loader)
|
30
|
+
@init_command = "/sbin/service #{@new_resource.service_name}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def load_current_resource
|
34
|
+
super
|
35
|
+
|
36
|
+
unless ::File.exists? "/sbin/chkconfig"
|
37
|
+
raise Chef::Exceptions::Service, "/sbin/chkconfig does not exist!"
|
38
|
+
end
|
39
|
+
|
40
|
+
status = popen4("/sbin/chkconfig --list #{@current_resource.service_name}") do |pid, stdin, stdout, stderr|
|
41
|
+
if stdout.gets =~ /\d:on/
|
42
|
+
@current_resource.enabled true
|
43
|
+
else
|
44
|
+
@current_resource.enabled false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
@current_resource
|
49
|
+
end
|
50
|
+
|
51
|
+
def enable_service()
|
52
|
+
run_command(:command => "/sbin/chkconfig #{@new_resource.service_name} on")
|
53
|
+
end
|
54
|
+
|
55
|
+
def disable_service()
|
56
|
+
run_command(:command => "/sbin/chkconfig #{@new_resource.service_name} off")
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Mathieu Sauve-Frankel <msf@kisoku.net>
|
3
|
+
# Copyright:: Copyright (c) 2009 Mathieu Sauve-Frankel
|
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 Simple < Chef::Provider::Service
|
26
|
+
def load_current_resource
|
27
|
+
@current_resource = Chef::Resource::Service.new(@new_resource.name)
|
28
|
+
@current_resource.service_name(@new_resource.service_name)
|
29
|
+
if @new_resource.status_command
|
30
|
+
Chef::Log.debug("#{@new_resource} you have specified a status command, running..")
|
31
|
+
|
32
|
+
begin
|
33
|
+
if run_command(:command => @new_resource.status_command) == 0
|
34
|
+
@current_resource.running true
|
35
|
+
end
|
36
|
+
rescue Chef::Exceptions::Exec
|
37
|
+
@current_resource.running false
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
|
41
|
+
elsif @new_resource.supports[:status]
|
42
|
+
Chef::Log.debug("#{@new_resource} supports status, running")
|
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
|
+
elsif
|
53
|
+
Chef::Log.warn "#{@new_resource}: falling back to process table inspection"
|
54
|
+
if @node[:command][:ps].nil? or @node[:command][:ps].empty?
|
55
|
+
raise Chef::Exceptions::Service, "#{@new_resource}: could not determine how to inspect the process table, please set this nodes 'command.ps' attribute"
|
56
|
+
end
|
57
|
+
status = popen4(@node[:command][:ps]) do |pid, stdin, stdout, stderr|
|
58
|
+
stdin.close rescue nil
|
59
|
+
r = Regexp.new(@new_resource.pattern)
|
60
|
+
Chef::Log.warn "#{@new_resource}: attempting to match '#{@new_resource.pattern}' (#{r}) against process list"
|
61
|
+
stdout.each_line do |line|
|
62
|
+
if r.match(line)
|
63
|
+
@current_resource.running true
|
64
|
+
break
|
65
|
+
end
|
66
|
+
end
|
67
|
+
@current_resource.running false unless @current_resource.running
|
68
|
+
end
|
69
|
+
unless status.exitstatus == 0
|
70
|
+
raise Chef::Exceptions::Service, "Command #{@node[:command][:ps]} failed"
|
71
|
+
else
|
72
|
+
Chef::Log.debug "#{@new_resource}: running: #{@current_resource.running}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
@current_resource
|
77
|
+
end
|
78
|
+
|
79
|
+
def start_service
|
80
|
+
if @new_resource.start_command
|
81
|
+
run_command(:command => @new_resource.start_command)
|
82
|
+
else
|
83
|
+
raise Chef::Exceptions::Service, "#{self.to_s} requires that start_command to be set"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def stop_service
|
88
|
+
if @new_resource.stop_command
|
89
|
+
run_command(:command => @new_resource.stop_command)
|
90
|
+
else
|
91
|
+
raise Chef::Exceptions::Service, "#{self.to_s} requires that stop_command to be set"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def restart_service
|
96
|
+
if @new_resource.restart_command
|
97
|
+
run_command(:command => @new_resource.restart_command)
|
98
|
+
else
|
99
|
+
stop_service
|
100
|
+
sleep 1
|
101
|
+
start_service
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def reload_service
|
106
|
+
if @new_resource.reload_command
|
107
|
+
run_command(:command => @new_resource.reload_command)
|
108
|
+
else
|
109
|
+
raise Chef::Exceptions::Service, "#{self.to_s} requires that reload_command to be set"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,148 @@
|
|
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
|
+
if current_revision = find_current_revision
|
34
|
+
@current_resource.revision current_revision
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def action_checkout
|
39
|
+
run_command(run_options(:command => checkout_command))
|
40
|
+
@new_resource.updated = true
|
41
|
+
end
|
42
|
+
|
43
|
+
def action_export
|
44
|
+
run_command(run_options(:command => export_command))
|
45
|
+
@new_resource.updated = true
|
46
|
+
end
|
47
|
+
|
48
|
+
def action_sync
|
49
|
+
if !::File.exist?(@new_resource.destination + "/.svn") || ::Dir.entries(@new_resource.destination) == ['.','..']
|
50
|
+
action_checkout
|
51
|
+
else
|
52
|
+
run_command(run_options(:command => sync_command))
|
53
|
+
end
|
54
|
+
@new_resource.updated = true
|
55
|
+
end
|
56
|
+
|
57
|
+
def sync_command
|
58
|
+
Chef::Log.info "Updating working copy #{@new_resource.destination} to revision #{@new_resource.revision}"
|
59
|
+
scm :update, @new_resource.svn_arguments, verbose, authentication, "-r#{revision_int}", @new_resource.destination
|
60
|
+
end
|
61
|
+
|
62
|
+
def checkout_command
|
63
|
+
Chef::Log.info "checking out #{@new_resource.repository} at revision #{@new_resource.revision} to #{@new_resource.destination}"
|
64
|
+
scm :checkout, @new_resource.svn_arguments, verbose, authentication,
|
65
|
+
"-r#{revision_int}", @new_resource.repository, @new_resource.destination
|
66
|
+
end
|
67
|
+
|
68
|
+
def export_command
|
69
|
+
Chef::Log.info "exporting #{@new_resource.repository} at revision #{@new_resource.revision} to #{@new_resource.destination}"
|
70
|
+
scm :export, @new_resource.svn_arguments, verbose, authentication,
|
71
|
+
"-r#{revision_int}", @new_resource.repository, @new_resource.destination
|
72
|
+
end
|
73
|
+
|
74
|
+
# If the specified revision isn't an integer ("HEAD" for example), look
|
75
|
+
# up the revision id by asking the server
|
76
|
+
# If the specified revision is an integer, trust it.
|
77
|
+
def revision_int
|
78
|
+
@revision_int ||= begin
|
79
|
+
if @new_resource.revision =~ /^\d+$/
|
80
|
+
@new_resource.revision
|
81
|
+
else
|
82
|
+
command = scm(:info, @new_resource.repository, authentication, "-r#{@new_resource.revision}")
|
83
|
+
status, svn_info, error_message = output_of_command(command, run_options)
|
84
|
+
handle_command_failures(status, "STDOUT: #{svn_info}\nSTDERR: #{error_message}")
|
85
|
+
extract_revision_info(svn_info)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
alias :revision_slug :revision_int
|
91
|
+
|
92
|
+
def find_current_revision
|
93
|
+
return nil unless ::File.exist?(@new_resource.destination)
|
94
|
+
command = scm(:info)
|
95
|
+
status, svn_info, error_message = output_of_command(command, run_options(:cwd => cwd))
|
96
|
+
|
97
|
+
unless [0,1].include?(status.exitstatus)
|
98
|
+
handle_command_failures(status, "STDOUT: #{svn_info}\nSTDERR: #{error_message}")
|
99
|
+
end
|
100
|
+
extract_revision_info(svn_info)
|
101
|
+
end
|
102
|
+
|
103
|
+
def run_options(run_opts={})
|
104
|
+
run_opts[:user] = @new_resource.user if @new_resource.user
|
105
|
+
run_opts
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def cwd
|
111
|
+
@new_resource.destination
|
112
|
+
end
|
113
|
+
|
114
|
+
def verbose
|
115
|
+
"-q"
|
116
|
+
end
|
117
|
+
|
118
|
+
def extract_revision_info(svn_info)
|
119
|
+
begin
|
120
|
+
repo_attrs = YAML.load(svn_info)
|
121
|
+
rescue ArgumentError
|
122
|
+
# YAML doesn't appreciate input like "svn: '/tmp/deploydir' is not a working copy\n"
|
123
|
+
return nil
|
124
|
+
end
|
125
|
+
raise "tried to run `#{command}' and got unexpected result #{result.inspect}" unless repo_attrs.kind_of?(Hash)
|
126
|
+
rev = (repo_attrs['Last Changed Rev'] || repo_attrs['Revision']).to_s
|
127
|
+
Chef::Log.debug "Resolved revision #{@new_resource.revision} to #{rev}"
|
128
|
+
rev
|
129
|
+
end
|
130
|
+
|
131
|
+
# If a username is configured for the SCM, return the command-line
|
132
|
+
# switches for that. Note that we don't need to return the password
|
133
|
+
# switch, since Capistrano will check for that prompt in the output
|
134
|
+
# and will respond appropriately.
|
135
|
+
def authentication
|
136
|
+
return "" unless @new_resource.svn_username
|
137
|
+
result = "--username #{@new_resource.svn_username} "
|
138
|
+
result << "--password #{@new_resource.svn_password} "
|
139
|
+
result
|
140
|
+
end
|
141
|
+
|
142
|
+
def scm(*args)
|
143
|
+
['svn', *args].compact.join(" ")
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|