summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-01-11 20:45:06 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-01-11 20:45:06 +0000
commit11b546385de28a2a51ad15accbd5d797031e6ed3 (patch)
tree2ddfd8aa2e327fab4ec60e81f1eab883c386f0f7 /lib
parent932b783a1ea64711f3fc10f375e91c9ad8e4f593 (diff)
downloadpuppet-11b546385de28a2a51ad15accbd5d797031e6ed3.tar.gz
puppet-11b546385de28a2a51ad15accbd5d797031e6ed3.tar.xz
puppet-11b546385de28a2a51ad15accbd5d797031e6ed3.zip
Adding a requires? method to types, fixed the bug where exec fail when Puppet is downloading the script to execute, and modified "exec" to autorequire any managed scripts
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@803 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/type.rb19
-rwxr-xr-xlib/puppet/type/exec.rb51
2 files changed, 52 insertions, 18 deletions
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index ad76cfe8e..2b228c678 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -1310,7 +1310,7 @@ class Type < Puppet::Element
# @callbacks[object][event] = method
#end
- # return all objects subscribed to the current object
+ # return all objects that we depend on
def eachdependency
Puppet::Event::Subscription.dependencies(self).each { |dep|
yield dep.source
@@ -1365,10 +1365,6 @@ class Type < Puppet::Element
subargs[:callback] = method
end
Puppet::Event::Subscription.new(subargs)
- #if self.respond_to?(method)
- # self.addcallback(object, event, method)
- #end
- #object.addnotify(self)
}
end
@@ -1382,6 +1378,19 @@ class Type < Puppet::Element
end
end
+ def requires?(object)
+ #Puppet.notice "Checking reqs for %s" % object.name
+ req = false
+ self.eachdependency { |dep|
+ if dep == object
+ req = true
+ break
+ end
+ }
+
+ return req
+ end
+
def subscribe(hash)
hash[:source] = self
Puppet::Event::Subscription.new(hash)
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb
index 4d4e1d624..04be7f62a 100755
--- a/lib/puppet/type/exec.rb
+++ b/lib/puppet/type/exec.rb
@@ -34,18 +34,8 @@ module Puppet
return "executed successfully"
end
- # because this command always runs,
- # we're just using retrieve to verify that the command
- # exists and such
- def retrieve
- if file = @parent[:creates]
- if FileTest.exists?(file)
- @is = true
- @should = [true]
- return
- end
- end
-
+ # Verify that we have the executable
+ def checkexe
cmd = self.parent[:command]
if cmd =~ /^\//
exe = cmd.split(/ /)[0]
@@ -77,6 +67,19 @@ module Puppet
self.parent[:command]
)
end
+ end
+
+ # because this command always runs,
+ # we're just using retrieve to verify that the command
+ # exists and such
+ def retrieve
+ if file = @parent[:creates]
+ if FileTest.exists?(file)
+ @is = true
+ @should = [true]
+ return
+ end
+ end
if self.parent[:refreshonly]
# if refreshonly is enabled, then set things so we
@@ -92,10 +95,13 @@ module Puppet
def sync
olddir = nil
+ self.checkexe
+
# We need a dir to change to, even if it's just the cwd
dir = self.parent[:cwd] || Dir.pwd
tmppath = ENV["PATH"]
+ event = :executed_command
begin
# Do our chdir
Dir.chdir(dir) {
@@ -126,6 +132,7 @@ module Puppet
# if we've had a failure, up the log level
loglevel = :err
+ event = :failed_command
end
# and log
@@ -140,7 +147,7 @@ module Puppet
ENV["PATH"] = tmppath
end
- return :executed_command
+ return event
end
end
@@ -257,6 +264,24 @@ module Puppet
end
end
+ def initialize(*args)
+ super
+
+ # If the command is fully qualified and we're managing it, let's go
+ # ahead and auto-require it.
+ if self[:command] =~ /^#{File::SEPARATOR}/
+ cmd = self[:command].sub(/\s.+/,'')
+ if file = Puppet.type(:file)[cmd]
+ unless self.requires?(file)
+ self.info "Auto-requiring %s" % cmd
+ self[:require] = [:file, cmd]
+ #else
+ # self.info "Already require %s" % cmd
+ end
+ end
+ end
+ end
+
def output
if self.state(:returns).nil?
return nil