diff options
author | Luke Kanies <luke@reductivelabs.com> | 2010-01-18 17:26:06 -0800 |
---|---|---|
committer | Luke Kanies <luke@reductivelabs.com> | 2010-01-18 17:26:06 -0800 |
commit | cdcbdc78bc399a60afaf36b6267688e72081fb6e (patch) | |
tree | 1a2e3bf8bbe06631acdcf7d0f6acc0021dfaa048 /lib/puppet/configurer.rb | |
parent | 67216aa5637a0e134750103abb74b5c2e3db3eb6 (diff) | |
download | puppet-cdcbdc78bc399a60afaf36b6267688e72081fb6e.tar.gz puppet-cdcbdc78bc399a60afaf36b6267688e72081fb6e.tar.xz puppet-cdcbdc78bc399a60afaf36b6267688e72081fb6e.zip |
Fixing #2914 - pre/post hooks now work for transactions
This was built to be used with etckeeper to version control
files in /etc, but can be used for essentially anything.
This patch was built to be added to 0.25.4, so it's a least-modify
approach. A better approach would be to refactor application/puppet.rb
just a bit so it uses Configurer more.
This is a simple patch - it just defines 'prerun_command' and 'postrun_command'
settings, and runs the appropriate command around each transaction
if they're set.
Signed-off-by: Luke Kanies <luke@reductivelabs.com>
Diffstat (limited to 'lib/puppet/configurer.rb')
-rw-r--r-- | lib/puppet/configurer.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb index 3e72fa574..ec61272ef 100644 --- a/lib/puppet/configurer.rb +++ b/lib/puppet/configurer.rb @@ -5,6 +5,8 @@ require 'puppet/network/http_pool' require 'puppet/util' class Puppet::Configurer + class CommandHookError < RuntimeError; end + require 'puppet/configurer/fact_handler' require 'puppet/configurer/plugin_handler' @@ -39,6 +41,14 @@ class Puppet::Configurer @catalog = nil end + def execute_postrun_command + execute_from_setting(:postrun_command) + end + + def execute_prerun_command + execute_from_setting(:prerun_command) + end + # Initialize and load storage def dostorage begin @@ -75,6 +85,8 @@ class Puppet::Configurer download_plugins() download_fact_plugins() + + execute_prerun_command end # Get the remote catalog, yo. Returns nil if no catalog can be found. @@ -160,6 +172,8 @@ class Puppet::Configurer # Now close all of our existing http connections, since there's no # reason to leave them lying open. Puppet::Network::HttpPool.clear_http_instances + ensure + execute_postrun_command end private @@ -180,4 +194,14 @@ class Puppet::Configurer return timeout end + + def execute_from_setting(setting) + return if (command = Puppet[setting]) == "" + + begin + Puppet::Util.execute([command]) + rescue => detail + raise CommandHookError, "Could not run command from #{setting}: #{detail}" + end + end end |