Question - only if your configuration files are changed


#1

How do I restarting a service only if your configuration files are changed

Example: ntp service


#2

See here, from the opsocde ntp cookbook:

On Thu, Feb 7, 2013 at 6:50 AM, Alex Vitola alex.vitola@gmail.com wrote:

How do I restarting a service only if your configuration files are changed

Example: ntp service


#3

I’ve often wondered this myself. I currently keep one backup of the config and restart only if the current and the backup differ, but its incredibly hacky and doesn’t work if you put a “configured by chef” time stamp at the top.

It doesn’t appear that that recipe only restarts if the file is changed. Or am I missing something?

…spike
(Sent via handheld, please pardon spelling errors)

On Feb 7, 2013, at 8:18 AM, Mike miketheman@gmail.com wrote:

See here, from the opsocde ntp cookbook:
https://github.com/opscode-cookbooks/ntp/blob/master/recipes/default.rb#L44-L50

On Thu, Feb 7, 2013 at 6:50 AM, Alex Vitola alex.vitola@gmail.com wrote:

How do I restarting a service only if your configuration files are changed

Example: ntp service


#4

Perfect Mike

Tks

2013/2/7 Mike miketheman@gmail.com:

See here, from the opsocde ntp cookbook:
https://github.com/opscode-cookbooks/ntp/blob/master/recipes/default.rb#L44-L50

On Thu, Feb 7, 2013 at 6:50 AM, Alex Vitola alex.vitola@gmail.com wrote:

How do I restarting a service only if your configuration files are changed

Example: ntp service


#5

Yes, the link Mike gave is exactly how you achieve this.

Resources only “notify” when they needed to do something to get your system
into the state that they describe. So, in this example IF "/etc/ntp.conf"
is modified by Chef, then it will notify the ntp service resource to
perform its “restart” action.

More information on notifications here:
http://docs.opscode.com/chef/resources.html#notifications

-Matt Moretti

On Thu, Feb 7, 2013 at 8:33 AM, Spike Grobstein
spike@ticketevolution.comwrote:

I’ve often wondered this myself. I currently keep one backup of the config
and restart only if the current and the backup differ, but its incredibly
hacky and doesn’t work if you put a “configured by chef” time stamp at the
top.

It doesn’t appear that that recipe only restarts if the file is changed.
Or am I missing something?

…spike
(Sent via handheld, please pardon spelling errors)

On Feb 7, 2013, at 8:18 AM, Mike miketheman@gmail.com wrote:

See here, from the opsocde ntp cookbook:

https://github.com/opscode-cookbooks/ntp/blob/master/recipes/default.rb#L44-L50

On Thu, Feb 7, 2013 at 6:50 AM, Alex Vitola alex.vitola@gmail.com
wrote:

How do I restarting a service only if your configuration files are
changed

Example: ntp service


#6

note that if you put a timestamp in the template, you’ll get a notification
every time, since chef will update the timestamp every time it runs.

On Thu, Feb 7, 2013 at 1:33 PM, Spike Grobstein
spike@ticketevolution.comwrote:

I’ve often wondered this myself. I currently keep one backup of the config
and restart only if the current and the backup differ, but its incredibly
hacky and doesn’t work if you put a “configured by chef” time stamp at the
top.

It doesn’t appear that that recipe only restarts if the file is changed.
Or am I missing something?

…spike
(Sent via handheld, please pardon spelling errors)

On Feb 7, 2013, at 8:18 AM, Mike miketheman@gmail.com wrote:

See here, from the opsocde ntp cookbook:

https://github.com/opscode-cookbooks/ntp/blob/master/recipes/default.rb#L44-L50

On Thu, Feb 7, 2013 at 6:50 AM, Alex Vitola alex.vitola@gmail.com
wrote:

How do I restarting a service only if your configuration files are
changed

Example: ntp service


#7

+1 to Thom.

Spike - Since Chef keeps some backups around of previous version in
/var/cache/chef typically (you can also see the filename in a chef run
with debug where something changes), there’s no need to timestamp your
file.
Also, leveraging filesytem mtime to see when a file was changed is useful.

If you were statically entering a date/time of an Operator change -
say, add “2013-02-07 Mike added a new gadget” to your file as a
changelog, that might be useful, but also might be more effort than
it’s worth - that stuff typically lives in our source control history
anyways.

-M

On Thu, Feb 7, 2013 at 9:03 AM, Thom May thom@clearairturbulence.org wrote:

note that if you put a timestamp in the template, you’ll get a notification
every time, since chef will update the timestamp every time it runs.

On Thu, Feb 7, 2013 at 1:33 PM, Spike Grobstein spike@ticketevolution.com
wrote:

I’ve often wondered this myself. I currently keep one backup of the config
and restart only if the current and the backup differ, but its incredibly
hacky and doesn’t work if you put a “configured by chef” time stamp at the
top.

It doesn’t appear that that recipe only restarts if the file is changed.
Or am I missing something?

…spike
(Sent via handheld, please pardon spelling errors)

On Feb 7, 2013, at 8:18 AM, Mike miketheman@gmail.com wrote:

See here, from the opsocde ntp cookbook:

https://github.com/opscode-cookbooks/ntp/blob/master/recipes/default.rb#L44-L50

On Thu, Feb 7, 2013 at 6:50 AM, Alex Vitola alex.vitola@gmail.com
wrote:

How do I restarting a service only if your configuration files are
changed

Example: ntp service


#8

Interesting.

So how do the internals of this work? Does chef generate a new output file in a temp folder, compare the new file to the old file, then if they differ, update and notify?

I was always under the impression that this would notify every single time, so I was incredibly apprehensive about doing this on our postgres and redis production servers.

Thanks for the info. You’ve seriously just simplified my life.

…spike

On Feb 7, 2013, at 9:06 AM, Mike wrote:

+1 to Thom.

Spike - Since Chef keeps some backups around of previous version in
/var/cache/chef typically (you can also see the filename in a chef run
with debug where something changes), there’s no need to timestamp your
file.
Also, leveraging filesytem mtime to see when a file was changed is useful.

If you were statically entering a date/time of an Operator change -
say, add “2013-02-07 Mike added a new gadget” to your file as a
changelog, that might be useful, but also might be more effort than
it’s worth - that stuff typically lives in our source control history
anyways.

-M

On Thu, Feb 7, 2013 at 9:03 AM, Thom May thom@clearairturbulence.org wrote:

note that if you put a timestamp in the template, you’ll get a notification
every time, since chef will update the timestamp every time it runs.

On Thu, Feb 7, 2013 at 1:33 PM, Spike Grobstein spike@ticketevolution.com
wrote:

I’ve often wondered this myself. I currently keep one backup of the config
and restart only if the current and the backup differ, but its incredibly
hacky and doesn’t work if you put a “configured by chef” time stamp at the
top.

It doesn’t appear that that recipe only restarts if the file is changed.
Or am I missing something?

…spike
(Sent via handheld, please pardon spelling errors)

On Feb 7, 2013, at 8:18 AM, Mike miketheman@gmail.com wrote:

See here, from the opsocde ntp cookbook:

https://github.com/opscode-cookbooks/ntp/blob/master/recipes/default.rb#L44-L50

On Thu, Feb 7, 2013 at 6:50 AM, Alex Vitola alex.vitola@gmail.com
wrote:

How do I restarting a service only if your configuration files are
changed

Example: ntp service


#9

If you’re interested in the internals, here’s the code (for Chef 11,
although I don’t think it changed significantly since Chef 10).


The ‘template’ provider inherits the ‘file’ provider and uses the
’backup’ method from ‘file’.

-M

On Thu, Feb 7, 2013 at 9:19 AM, Spike Grobstein
spike@ticketevolution.com wrote:

Interesting.

So how do the internals of this work? Does chef generate a new output file in a temp folder, compare the new file to the old file, then if they differ, update and notify?

I was always under the impression that this would notify every single time, so I was incredibly apprehensive about doing this on our postgres and redis production servers.

Thanks for the info. You’ve seriously just simplified my life.

…spike

On Feb 7, 2013, at 9:06 AM, Mike wrote:

+1 to Thom.

Spike - Since Chef keeps some backups around of previous version in
/var/cache/chef typically (you can also see the filename in a chef run
with debug where something changes), there’s no need to timestamp your
file.
Also, leveraging filesytem mtime to see when a file was changed is useful.

If you were statically entering a date/time of an Operator change -
say, add “2013-02-07 Mike added a new gadget” to your file as a
changelog, that might be useful, but also might be more effort than
it’s worth - that stuff typically lives in our source control history
anyways.

-M

On Thu, Feb 7, 2013 at 9:03 AM, Thom May thom@clearairturbulence.org wrote:

note that if you put a timestamp in the template, you’ll get a notification
every time, since chef will update the timestamp every time it runs.

On Thu, Feb 7, 2013 at 1:33 PM, Spike Grobstein spike@ticketevolution.com
wrote:

I’ve often wondered this myself. I currently keep one backup of the config
and restart only if the current and the backup differ, but its incredibly
hacky and doesn’t work if you put a “configured by chef” time stamp at the
top.

It doesn’t appear that that recipe only restarts if the file is changed.
Or am I missing something?

…spike
(Sent via handheld, please pardon spelling errors)

On Feb 7, 2013, at 8:18 AM, Mike miketheman@gmail.com wrote:

See here, from the opsocde ntp cookbook:

https://github.com/opscode-cookbooks/ntp/blob/master/recipes/default.rb#L44-L50

On Thu, Feb 7, 2013 at 6:50 AM, Alex Vitola alex.vitola@gmail.com
wrote:

How do I restarting a service only if your configuration files are
changed

Example: ntp service


#10

essentially it generates a new file, generates an MD5-like hash of the
file, and compares that to the MD5-like hash of the existing file, and if
changed update and notify.

internally, it may generate the MD5-like hash against a raw string, rather
than writing it out to a file first, but that depends on which resource is
being used.
“remote_file”, for example, generally fetches the remote into a local
tempfile and takes the hash of that. “template” and “file” generally work
from the generated string, cookbook_file already knows the hash because it
was generated when uploading the cookbook to the chef server… there are
more.

On Thu, Feb 7, 2013 at 9:19 AM, Spike Grobstein
spike@ticketevolution.comwrote:

Interesting.

So how do the internals of this work? Does chef generate a new output file
in a temp folder, compare the new file to the old file, then if they
differ, update and notify?

I was always under the impression that this would notify every single
time, so I was incredibly apprehensive about doing this on our postgres and
redis production servers.

Thanks for the info. You’ve seriously just simplified my life.

…spike

On Feb 7, 2013, at 9:06 AM, Mike wrote:

+1 to Thom.

Spike - Since Chef keeps some backups around of previous version in
/var/cache/chef typically (you can also see the filename in a chef run
with debug where something changes), there’s no need to timestamp your
file.
Also, leveraging filesytem mtime to see when a file was changed is
useful.

If you were statically entering a date/time of an Operator change -
say, add “2013-02-07 Mike added a new gadget” to your file as a
changelog, that might be useful, but also might be more effort than
it’s worth - that stuff typically lives in our source control history
anyways.

-M

On Thu, Feb 7, 2013 at 9:03 AM, Thom May thom@clearairturbulence.org
wrote:

note that if you put a timestamp in the template, you’ll get a
notification

every time, since chef will update the timestamp every time it runs.

On Thu, Feb 7, 2013 at 1:33 PM, Spike Grobstein <
spike@ticketevolution.com>

wrote:

I’ve often wondered this myself. I currently keep one backup of the
config

and restart only if the current and the backup differ, but its
incredibly

hacky and doesn’t work if you put a “configured by chef” time stamp at
the

top.

It doesn’t appear that that recipe only restarts if the file is
changed.

Or am I missing something?

…spike
(Sent via handheld, please pardon spelling errors)

On Feb 7, 2013, at 8:18 AM, Mike miketheman@gmail.com wrote:

See here, from the opsocde ntp cookbook:

https://github.com/opscode-cookbooks/ntp/blob/master/recipes/default.rb#L44-L50

On Thu, Feb 7, 2013 at 6:50 AM, Alex Vitola alex.vitola@gmail.com
wrote:

How do I restarting a service only if your configuration files are
changed

Example: ntp service


#11

The checksum of the rendered file content and target file is SHA256, specifically.


Joshua Timberman

On Thursday, February 7, 2013 at 8:17, Jesse Campbell wrote:

essentially it generates a new file, generates an MD5-like hash of the file, and compares that to the MD5-like hash of the existing file, and if changed update and notify.

internally, it may generate the MD5-like hash against a raw string, rather than writing it out to a file first, but that depends on which resource is being used.
“remote_file”, for example, generally fetches the remote into a local tempfile and takes the hash of that. “template” and “file” generally work from the generated string, cookbook_file already knows the hash because it was generated when uploading the cookbook to the chef server… there are more.

On Thu, Feb 7, 2013 at 9:19 AM, Spike Grobstein <spike@ticketevolution.com (mailto:spike@ticketevolution.com)> wrote:

Interesting.

So how do the internals of this work? Does chef generate a new output file in a temp folder, compare the new file to the old file, then if they differ, update and notify?

I was always under the impression that this would notify every single time, so I was incredibly apprehensive about doing this on our postgres and redis production servers.

Thanks for the info. You’ve seriously just simplified my life.

…spike

On Feb 7, 2013, at 9:06 AM, Mike wrote:

+1 to Thom.

Spike - Since Chef keeps some backups around of previous version in
/var/cache/chef typically (you can also see the filename in a chef run
with debug where something changes), there’s no need to timestamp your
file.
Also, leveraging filesytem mtime to see when a file was changed is useful.

If you were statically entering a date/time of an Operator change -
say, add “2013-02-07 Mike added a new gadget” to your file as a
changelog, that might be useful, but also might be more effort than
it’s worth - that stuff typically lives in our source control history
anyways.

-M

On Thu, Feb 7, 2013 at 9:03 AM, Thom May <thom@clearairturbulence.org (mailto:thom@clearairturbulence.org)> wrote:

note that if you put a timestamp in the template, you’ll get a notification
every time, since chef will update the timestamp every time it runs.

On Thu, Feb 7, 2013 at 1:33 PM, Spike Grobstein <spike@ticketevolution.com (mailto:spike@ticketevolution.com)>
wrote:

I’ve often wondered this myself. I currently keep one backup of the config
and restart only if the current and the backup differ, but its incredibly
hacky and doesn’t work if you put a “configured by chef” time stamp at the
top.

It doesn’t appear that that recipe only restarts if the file is changed.
Or am I missing something?

…spike
(Sent via handheld, please pardon spelling errors)

On Feb 7, 2013, at 8:18 AM, Mike <miketheman@gmail.com (mailto:miketheman@gmail.com)> wrote:

See here, from the opsocde ntp cookbook:

https://github.com/opscode-cookbooks/ntp/blob/master/recipes/default.rb#L44-L50

On Thu, Feb 7, 2013 at 6:50 AM, Alex Vitola <alex.vitola@gmail.com (mailto:alex.vitola@gmail.com)>
wrote:

How do I restarting a service only if your configuration files are
changed

Example: ntp service