summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-07-11 18:14:20 +0000
committerLuke Kanies <luke@madstop.com>2005-07-11 18:14:20 +0000
commit96f3980a57f8fd24aff801420a0813bad9bb20d7 (patch)
treecaffb500e987998c29fb773869b58c335d71d382 /lib
parent649d59a24cf03387e58fa1d4a151fcf34e409777 (diff)
downloadpuppet-96f3980a57f8fd24aff801420a0813bad9bb20d7.tar.gz
puppet-96f3980a57f8fd24aff801420a0813bad9bb20d7.tar.xz
puppet-96f3980a57f8fd24aff801420a0813bad9bb20d7.zip
adding Puppet#recmkdir utility function, and making sure Log and Storage create their own files and directories as necessary
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@354 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet.rb15
-rw-r--r--lib/puppet/log.rb36
-rw-r--r--lib/puppet/storage.rb15
-rw-r--r--lib/puppet/type.rb12
4 files changed, 72 insertions, 6 deletions
diff --git a/lib/puppet.rb b/lib/puppet.rb
index e227aab1f..ac7309da8 100644
--- a/lib/puppet.rb
+++ b/lib/puppet.rb
@@ -84,6 +84,21 @@ module Puppet
end
end
+ def Puppet.recmkdir(dir,mode = 0755)
+ tmp = dir.sub(/^\//,'')
+ path = [File::SEPARATOR]
+ tmp.split(File::SEPARATOR).each { |dir|
+ path.push dir
+ if ! FileTest.exist?(File.join(path))
+ Dir.mkdir(File.join(path), mode)
+ elsif FileTest.directory?(File.join(path))
+ next
+ else FileTest.exist?(File.join(path))
+ raise "Cannot create %s: basedir %s is a file" %
+ [dir, File.join(path)]
+ end
+ }
+ end
end
require 'puppet/storage'
diff --git a/lib/puppet/log.rb b/lib/puppet/log.rb
index 06d7a0650..20aaff003 100644
--- a/lib/puppet/log.rb
+++ b/lib/puppet/log.rb
@@ -44,6 +44,12 @@ module Puppet
end
end
+ def Log.flush
+ if defined? @@logfile
+ @@logfile.flush
+ end
+ end
+
def Log.create(level,*ary)
msg = ary.join(" ")
@@ -67,7 +73,7 @@ module Puppet
end
def Log.destination=(dest)
- if dest == "syslog" || dest == :syslog
+ if dest == "syslog" or dest == :syslog
unless defined? @@syslog
@@syslog = Syslog.open("puppet")
end
@@ -76,13 +82,37 @@ module Puppet
if defined? @@logfile
@@logfile.close
end
+
+ @@logpath = dest
+
+ # first make sure the directory exists
+ unless FileTest.exist?(File.dirname(dest))
+ begin
+ Puppet.recmkdir(File.dirname(dest))
+ Puppet.info "Creating log directory %s" %
+ File.dirname(dest)
+ rescue => detail
+ Log.destination = :console
+ Puppet.err "Could not create log directory: %s" %
+ detail
+ return
+ end
+ end
+
begin
- @@logfile = File.open(dest,"w")
+ # create the log file, if it doesn't already exist
+ @@logfile = File.open(dest,File::WRONLY|File::CREAT|File::APPEND)
rescue => detail
- raise
+ Log.destination = :console
+ Puppet.err "Could not create log file: %s" %
+ detail
+ return
end
@@logdest = :file
else
+ unless @@logdest == :console or @@logdest == "console"
+ Puppet.notice "Invalid log setting %s; setting log destination to 'console'" % @@logdest
+ end
@@logdest = :console
end
end
diff --git a/lib/puppet/storage.rb b/lib/puppet/storage.rb
index 53b3b5a6e..28d593db0 100644
--- a/lib/puppet/storage.rb
+++ b/lib/puppet/storage.rb
@@ -35,6 +35,21 @@ module Puppet
end
def Storage.store
+ unless FileTest.directory?(File.dirname(Puppet[:statefile]))
+ begin
+ Puppet.recmkdir(Puppet[:statefile])
+ Puppet.info "Creating state directory %s" %
+ File.basename(Puppet[:statefile])
+ rescue => detail
+ Puppet.err "Could not create state file: %s" % detail
+ return
+ end
+ end
+
+ unless FileTest.exist?(Puppet[:statefile])
+ Puppet.info "Creating state file %s" % Puppet[:statefile]
+ end
+
File.open(Puppet[:statefile], File::CREAT|File::WRONLY, 0600) { |file|
@@state.each { |klass, thash|
thash.each { |key,value|
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index eb3bc2e03..652366dcb 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -118,9 +118,15 @@ class Type < Puppet::Element
#---------------------------------------------------------------
#---------------------------------------------------------------
- #def debug(ary)
- # Puppet[:debug] = ary.shift
- #end
+ def debug(ary)
+ value = ary.shift
+ if value == "true" or value == true
+ value = true
+ else
+ value = value
+ end
+ Puppet[:debug] = value
+ end
#---------------------------------------------------------------
#---------------------------------------------------------------