Ask Your Question
1

Is there a reasonable way to run a shell command when a file watched by puppet is changed or created?

asked 2013-06-18 14:15:25 -0500

ranceh gravatar image

When you upgrade web apps you often need to run a database script that alters the database to match the needs of the new version of the app.

We would like a way to regulate when this command is run by a puppet managed host.

We thought we could setup a file that puppet would watch and then if it was created/changed we could catch that and run the appropriate command when needed.

Now all file can do is notify a service.

I have to write a fake service to run the command when the service is notified.

Seems ... (more)

edit retag flag offensive close merge delete

Comments

I believe I do something similar for my DNS servers. Take a look at question I had asked a couple of months ago: https://ask.puppetlabs.com/question/919/how-to-cause-my-class-to-send-sighup-instead-of-doing-service-named-stop-service-named-start/

Red Cricket gravatar imageRed Cricket ( 2013-06-18 14:57:00 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
4

answered 2013-06-18 14:57:27 -0500

updated 2013-06-18 15:13:37 -0500

ramindk gravatar image

You could tie together exec and file, see an example and interesting discussion here :

http://grokbase.com/t/gg/puppet-users/131e2rm4vw/refresh-exec-resource-from-a-file-resource-without-source

in a nutshell :

file { "file1":
            recurse => true,
            owner   => "root",
            group   => "root",
            mode    => "700",
            source  => "puppet://server/file1",
            notify   => Exec["refresh_conf"],
 }


 exec { "refresh_conf":
            command     => "exec something",
            refreshonly => 'true', # only runs when notified.
 }

Note : if the file is not in puppet control, you might need the audit metaparameter

edit flag offensive delete link more

Comments

This looks like it should do the trick. Thanks.

ranceh gravatar imageranceh ( 2013-06-19 10:07:42 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-06-18 14:15:25 -0500

Seen: 467 times

Last updated: Jun 18 '13