Hi. I''m hoping that someone can help me with a simple example. We are trying to use puppet to update a server binary to a group of machines. Here''s pseudocode for what I''m trying: if (server_binary has changed) { 1) stop the old server 2) overwrite the old server binary by fetching the new server binary from puppet 3) start the new server } Below is the puppet manifest I wrote to handle this, but it isn''t working properly. It is 1) downloading the new binary and then 2) stopping the server, which screws up our data. I''ve been looking through the documentation, and it isn''t clear which permutation of before, require, subscribe, or notify is necessary to accomplish this. Hope someone can enlighten me. - Mat file { "/usr/local/sbin/server_binary": source => "puppet:///files/server_binary", require => Exec["stop-server"], before => Exec["start-server"] } # Stops the server exec { "/usr/local/sbin/stop-server": alias => "stop-server", refreshonly => true } # Starts the server exec { "/usr/local/sbin/start-server": alias => "start-server", refreshonly => true } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Hi. I''m hoping that someone can help me with a simple example. We are trying to use puppet to update a server binary to a group of machines. Here''s pseudocode for what I''m trying: if (server_binary has changed) { 1) stop the old server 2) overwrite the old server binary by fetching the new server binary from puppet 3) start the new server } Here''s the puppet manifest I wrote to handle this, but it isn''t working properly. It is not working as intended, and is 1) downloading the new binary and then 2) stopping the server, which screws up our data. I''ve been looking through the documentation, and it isn''t clear which permutation of before, require, subscribe, or notify is necessary to accomplish this. Hope someone can enlighten me. - Mat file { "/usr/local/sbin/server_binary": source => "puppet:///files/server_binary", require => Exec["stop-server"], before => Exec["start-server"] } # Stops the server exec { "/usr/local/sbin/stop-server": alias => "stop-server", refreshonly => true } # Starts the server exec { "/usr/local/sbin/start-server": alias => "start-server", refreshonly => true } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
As I understand it, refreshonly ensures the command will only run when a dependent object is changed, hence only subscribe and notify trigger it, not require. So I don''t think either exec would be called in your manifest. I might be missing something there though. But regardless, I''m not sure how you could get the exec to run before the binary is changed. As I understand it, if you use require without refreshonly, the exec resource will just be applied before the file resource regardless of whether the file is being changed or not. To only run the exec when the file is being changed, you''d have to use refreshonly with notify or subscribe, or independently determine that the file is about to be changed (possibly with an onlyif command). And if you do use refreshonly, with notify, it will only notify after the file has changed I believe. Similarly a subscribe will only run the exec after the file has changed. I don''t think there''s any way to notify an object that something is about to change. Basically, notify is ''notify after'', and AFAIK there''s no ''notify before''. One option might be to stop and start the server every time regardless of whether the file is being updated or not, but that seems less than ideal. An expert may well be able to offer a better solution, but as a workaround I''d suggest managing a copy of the server binary rather than the binary itself. Then have an exec type subscribed to the copy that, upon changes, stops the server, copies the new binary over the old binary, and starts the server. It''s not particularly elegant, but it should definitely work and it''s probably simpler than trying to determine whether the file is about to change from within the stop-server exec. Rob Mathew Binkley wrote:> Hi. I''m hoping that someone can help me with a simple example. We > are trying to use puppet to update a server binary to a group of > machines. Here''s pseudocode for what I''m trying: > > if (server_binary has changed) { > 1) stop the old server > 2) overwrite the old server binary by > fetching the new server binary from puppet > 3) start the new server > } > > Below is the puppet manifest I wrote to handle this, but it isn''t > working properly. It is 1) downloading the new binary and then 2) > stopping the server, which screws up our data. I''ve been looking > through the documentation, and it isn''t clear which permutation of > before, require, subscribe, or notify is necessary to accomplish > this. Hope someone can enlighten me. - Mat > > > file { "/usr/local/sbin/server_binary": > source => "puppet:///files/server_binary", > require => Exec["stop-server"], > before => Exec["start-server"] > } > > # Stops the server > exec { "/usr/local/sbin/stop-server": > alias => "stop-server", > refreshonly => true > } > > # Starts the server > exec { "/usr/local/sbin/start-server": > alias => "start-server", > refreshonly => true > } > >-- Robert Fay fay@hep.ph.liv.ac.uk System Administrator office: 220 High Energy Physics Division tel (int): 43396 Oliver Lodge Laboratory tel (ext): +44 (0)151 794 3396 University of Liverpool http://www.liv.ac.uk/physics/hep/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Mat, This should work (untested): file { "/tmp/server_binary": source => "puppet:///files/server_binary", notify => Exec["stop-server"]; } file { "/usr/local/sbin/server_binary": source => "/tmp/server_binary", require => Exec["stop-server"], notify => Exec["start-server"] } # Stops the server exec { "/usr/local/sbin/stop-server": alias => "stop-server", refreshonly => true } # Starts the server exec { "/usr/local/sbin/start-server": alias => "start-server", refreshonly => true } --Paul On Tue, Dec 9, 2008 at 1:09 PM, Mathew Binkley <mathewbinkley@gmail.com> wrote:> > Hi. I''m hoping that someone can help me with a simple example. We are > trying to use puppet to update a server binary to a group of machines. > Here''s pseudocode for what I''m trying: > > if (server_binary has changed) { > 1) stop the old server > 2) overwrite the old server binary by > fetching the new server binary from puppet > 3) start the new server > } > > Here''s the puppet manifest I wrote to handle this, but it isn''t working > properly. It is not working as intended, and is 1) downloading the new > binary and then 2) stopping the server, which screws up our data. I''ve > been looking through the documentation, and it isn''t clear which > permutation of before, require, subscribe, or notify is necessary to > accomplish this. Hope someone can enlighten me. - Mat > > > file { "/usr/local/sbin/server_binary": > source => "puppet:///files/server_binary", > require => Exec["stop-server"], > before => Exec["start-server"] > } > > # Stops the server > exec { "/usr/local/sbin/stop-server": > alias => "stop-server", > refreshonly => true > } > > # Starts the server > exec { "/usr/local/sbin/start-server": > alias => "start-server", > refreshonly => true > } > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Like Matt I have been using "before=>" statements as opposed to "notify=>" to try and ensure dependency order. Could someone highlight the distinction as both seem to ensure a task is run and completed before the next step is called. Thanks Paul 2008/12/10 Paul Lathrop <paul@tertiusfamily.net>> > Mat, > > This should work (untested): > > file { "/tmp/server_binary": > source => "puppet:///files/server_binary", > notify => Exec["stop-server"]; > } > > file { "/usr/local/sbin/server_binary": > source => "/tmp/server_binary", > require => Exec["stop-server"], > notify => Exec["start-server"] > } > > # Stops the server > exec { "/usr/local/sbin/stop-server": > alias => "stop-server", > refreshonly => true > } > > # Starts the server > exec { "/usr/local/sbin/start-server": > alias => "start-server", > refreshonly => true > } > > --Paul > > On Tue, Dec 9, 2008 at 1:09 PM, Mathew Binkley <mathewbinkley@gmail.com> > wrote: > > > > Hi. I''m hoping that someone can help me with a simple example. We are > > trying to use puppet to update a server binary to a group of machines. > > Here''s pseudocode for what I''m trying: > > > > if (server_binary has changed) { > > 1) stop the old server > > 2) overwrite the old server binary by > > fetching the new server binary from puppet > > 3) start the new server > > } > > > > Here''s the puppet manifest I wrote to handle this, but it isn''t working > > properly. It is not working as intended, and is 1) downloading the new > > binary and then 2) stopping the server, which screws up our data. I''ve > > been looking through the documentation, and it isn''t clear which > > permutation of before, require, subscribe, or notify is necessary to > > accomplish this. Hope someone can enlighten me. - Mat > > > > > > file { "/usr/local/sbin/server_binary": > > source => "puppet:///files/server_binary", > > require => Exec["stop-server"], > > before => Exec["start-server"] > > } > > > > # Stops the server > > exec { "/usr/local/sbin/stop-server": > > alias => "stop-server", > > refreshonly => true > > } > > > > # Starts the server > > exec { "/usr/local/sbin/start-server": > > alias => "start-server", > > refreshonly => true > > } > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Paul, ''subscribe'' and ''notify'' are supersets of ''require'' and ''before,'' respectively. While ''require'' and ''before'' simply insist that the resource ordering occurs in a certain fashion, ''subscribe'' and ''notify'' make use of "events". An "event" occurs whenever a resource changes, and some resources behave differently when they receive an "event". For example, say you have the following: file { "/etc/apache/apache.conf": source => "puppet:///apache/apache.conf", before => Service["apache"]; } service { "apache": enable => true, ensure => running; } When you run puppet on a new machine, it will copy the apache.conf from the puppetmaster first, then enable and start apache. When the file changes, the puppetmaster will fetch the new file, but *nothing will happen to apache*. This is the use case for subscribe/notify: file { "/etc/apache/apache.conf": source => "puppet:///apache/apache.conf", notify => Service["apache"]; } service { "apache": enable => true, ensure => running; } With this manifest, puppet will notice that the file has changed, and will generate an "event" which it will send to the "apache" service. Service resources are restarted when they receive events. Note that ''subscribe'' is a superset of ''require'' so the resources will still be applied in the correct order. Does this make more sense now? --Paul On Wed, Dec 10, 2008 at 2:12 PM, paul matthews <paulsmatthews@googlemail.com> wrote:> Like Matt I have been using "before=>" statements as opposed to "notify=>" > to try and ensure dependency order. Could someone highlight the distinction > as both seem to ensure a task is run and completed before the next step is > called. > > Thanks > Paul > > 2008/12/10 Paul Lathrop <paul@tertiusfamily.net> >> >> Mat, >> >> This should work (untested): >> >> file { "/tmp/server_binary": >> source => "puppet:///files/server_binary", >> notify => Exec["stop-server"]; >> } >> >> file { "/usr/local/sbin/server_binary": >> source => "/tmp/server_binary", >> require => Exec["stop-server"], >> notify => Exec["start-server"] >> } >> >> # Stops the server >> exec { "/usr/local/sbin/stop-server": >> alias => "stop-server", >> refreshonly => true >> } >> >> # Starts the server >> exec { "/usr/local/sbin/start-server": >> alias => "start-server", >> refreshonly => true >> } >> >> --Paul >> >> On Tue, Dec 9, 2008 at 1:09 PM, Mathew Binkley <mathewbinkley@gmail.com> >> wrote: >> > >> > Hi. I''m hoping that someone can help me with a simple example. We are >> > trying to use puppet to update a server binary to a group of machines. >> > Here''s pseudocode for what I''m trying: >> > >> > if (server_binary has changed) { >> > 1) stop the old server >> > 2) overwrite the old server binary by >> > fetching the new server binary from puppet >> > 3) start the new server >> > } >> > >> > Here''s the puppet manifest I wrote to handle this, but it isn''t working >> > properly. It is not working as intended, and is 1) downloading the new >> > binary and then 2) stopping the server, which screws up our data. I''ve >> > been looking through the documentation, and it isn''t clear which >> > permutation of before, require, subscribe, or notify is necessary to >> > accomplish this. Hope someone can enlighten me. - Mat >> > >> > >> > file { "/usr/local/sbin/server_binary": >> > source => "puppet:///files/server_binary", >> > require => Exec["stop-server"], >> > before => Exec["start-server"] >> > } >> > >> > # Stops the server >> > exec { "/usr/local/sbin/stop-server": >> > alias => "stop-server", >> > refreshonly => true >> > } >> > >> > # Starts the server >> > exec { "/usr/local/sbin/start-server": >> > alias => "start-server", >> > refreshonly => true >> > } >> > >> > > >> > >> >> > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Hallo! paul matthews <paulsmatthews@googlemail.com>:>Like Matt I have been using "before=>" statements as opposed to "notify=>" >to try and ensure dependency order. Could someone highlight the distinction >as both seem to ensure a task is run and completed before the next step is >called.''before'' and ''require'' just specify the ordering: If you want A to be ensured before B, you can either say "before => B" on A or "require => A" on B. It is just a matter of where the ordering hint if placed. ''notify'' and ''subscribe'' are stronger versions of ''before'' and ''require'': They specify ordering but also generate events. This means that if a dependent resource was acted upon, the current resource is re-evaluated. This comes handy if you want for example an exec to be performed each time a file has been modified. All of this is documented at <http://reductivelabs.com/trac/puppet/wiki/TypeReference#available-metaparameters>. Regards Christian -- Dipl.-Inf. Christian Kauhaus <>< · kc@gocept.com · systems administration gocept gmbh & co. kg · forsterstraße 29 · 06112 halle (saale) · germany http://gocept.com · tel +49 345 1229889 11 · fax +49 345 1229889 1 Zope and Plone consulting and development
Paul, Thanks very much for yor explanation - that''s cleared things up and also accounted for why some things had not been running as expected Cheers Paul 2008/12/10 Paul Lathrop <paul@tertiusfamily.net>> > Paul, > > ''subscribe'' and ''notify'' are supersets of ''require'' and ''before,'' > respectively. While ''require'' and ''before'' simply insist that the > resource ordering occurs in a certain fashion, ''subscribe'' and > ''notify'' make use of "events". An "event" occurs whenever a resource > changes, and some resources behave differently when they receive an > "event". For example, say you have the following: > > file { "/etc/apache/apache.conf": > source => "puppet:///apache/apache.conf", > before => Service["apache"]; > } > > service { "apache": > enable => true, > ensure => running; > } > > When you run puppet on a new machine, it will copy the apache.conf > from the puppetmaster first, then enable and start apache. When the > file changes, the puppetmaster will fetch the new file, but *nothing > will happen to apache*. This is the use case for subscribe/notify: > > file { "/etc/apache/apache.conf": > source => "puppet:///apache/apache.conf", > notify => Service["apache"]; > } > > service { "apache": > enable => true, > ensure => running; > } > > With this manifest, puppet will notice that the file has changed, and > will generate an "event" which it will send to the "apache" service. > Service resources are restarted when they receive events. > > Note that ''subscribe'' is a superset of ''require'' so the resources will > still be applied in the correct order. > > Does this make more sense now? > > --Paul > > On Wed, Dec 10, 2008 at 2:12 PM, paul matthews > <paulsmatthews@googlemail.com> wrote: > > Like Matt I have been using "before=>" statements as opposed to > "notify=>" > > to try and ensure dependency order. Could someone highlight the > distinction > > as both seem to ensure a task is run and completed before the next step > is > > called. > > > > Thanks > > Paul > > > > 2008/12/10 Paul Lathrop <paul@tertiusfamily.net> > >> > >> Mat, > >> > >> This should work (untested): > >> > >> file { "/tmp/server_binary": > >> source => "puppet:///files/server_binary", > >> notify => Exec["stop-server"]; > >> } > >> > >> file { "/usr/local/sbin/server_binary": > >> source => "/tmp/server_binary", > >> require => Exec["stop-server"], > >> notify => Exec["start-server"] > >> } > >> > >> # Stops the server > >> exec { "/usr/local/sbin/stop-server": > >> alias => "stop-server", > >> refreshonly => true > >> } > >> > >> # Starts the server > >> exec { "/usr/local/sbin/start-server": > >> alias => "start-server", > >> refreshonly => true > >> } > >> > >> --Paul > >> > >> On Tue, Dec 9, 2008 at 1:09 PM, Mathew Binkley <mathewbinkley@gmail.com > > > >> wrote: > >> > > >> > Hi. I''m hoping that someone can help me with a simple example. We > are > >> > trying to use puppet to update a server binary to a group of machines. > >> > Here''s pseudocode for what I''m trying: > >> > > >> > if (server_binary has changed) { > >> > 1) stop the old server > >> > 2) overwrite the old server binary by > >> > fetching the new server binary from puppet > >> > 3) start the new server > >> > } > >> > > >> > Here''s the puppet manifest I wrote to handle this, but it isn''t > working > >> > properly. It is not working as intended, and is 1) downloading the > new > >> > binary and then 2) stopping the server, which screws up our data. > I''ve > >> > been looking through the documentation, and it isn''t clear which > >> > permutation of before, require, subscribe, or notify is necessary to > >> > accomplish this. Hope someone can enlighten me. - Mat > >> > > >> > > >> > file { "/usr/local/sbin/server_binary": > >> > source => "puppet:///files/server_binary", > >> > require => Exec["stop-server"], > >> > before => Exec["start-server"] > >> > } > >> > > >> > # Stops the server > >> > exec { "/usr/local/sbin/stop-server": > >> > alias => "stop-server", > >> > refreshonly => true > >> > } > >> > > >> > # Starts the server > >> > exec { "/usr/local/sbin/start-server": > >> > alias => "start-server", > >> > refreshonly => true > >> > } > >> > > >> > > > >> > > >> > >> > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks to everyone in this thread for the help. I ended up using Paul Lathrop''s manifest and it worked beautifully. On Dec 11, 3:07 am, "paul matthews" <paulsmatth...@googlemail.com> wrote:> Paul, > > Thanks very much for yor explanation - that''s cleared things up and also > accounted for why some things had not been running as expected > > Cheers > Paul > > 2008/12/10 Paul Lathrop <p...@tertiusfamily.net> > > > > > Paul, > > > ''subscribe'' and ''notify'' are supersets of ''require'' and ''before,'' > > respectively. While ''require'' and ''before'' simply insist that the > > resource ordering occurs in a certain fashion, ''subscribe'' and > > ''notify'' make use of "events". An "event" occurs whenever a resource > > changes, and some resources behave differently when they receive an > > "event". For example, say you have the following: > > > file { "/etc/apache/apache.conf": > > source => "puppet:///apache/apache.conf", > > before => Service["apache"]; > > } > > > service { "apache": > > enable => true, > > ensure => running; > > } > > > When you run puppet on a new machine, it will copy the apache.conf > > from the puppetmaster first, then enable and start apache. When the > > file changes, the puppetmaster will fetch the new file, but *nothing > > will happen to apache*. This is the use case for subscribe/notify: > > > file { "/etc/apache/apache.conf": > > source => "puppet:///apache/apache.conf", > > notify => Service["apache"]; > > } > > > service { "apache": > > enable => true, > > ensure => running; > > } > > > With this manifest, puppet will notice that the file has changed, and > > will generate an "event" which it will send to the "apache" service. > > Service resources are restarted when they receive events. > > > Note that ''subscribe'' is a superset of ''require'' so the resources will > > still be applied in the correct order. > > > Does this make more sense now? > > > --Paul > > > On Wed, Dec 10, 2008 at 2:12 PM, paul matthews > > <paulsmatth...@googlemail.com> wrote: > > > Like Matt I have been using "before=>" statements as opposed to > > "notify=>" > > > to try and ensure dependency order. Could someone highlight the > > distinction > > > as both seem to ensure a task is run and completed before the next step > > is > > > called. > > > > Thanks > > > Paul > > > > 2008/12/10 Paul Lathrop <p...@tertiusfamily.net> > > > >> Mat, > > > >> This should work (untested): > > > >> file { "/tmp/server_binary": > > >> source => "puppet:///files/server_binary", > > >> notify => Exec["stop-server"]; > > >> } > > > >> file { "/usr/local/sbin/server_binary": > > >> source => "/tmp/server_binary", > > >> require => Exec["stop-server"], > > >> notify => Exec["start-server"] > > >> } > > > >> # Stops the server > > >> exec { "/usr/local/sbin/stop-server": > > >> alias => "stop-server", > > >> refreshonly => true > > >> } > > > >> # Starts the server > > >> exec { "/usr/local/sbin/start-server": > > >> alias => "start-server", > > >> refreshonly => true > > >> } > > > >> --Paul > > > >> On Tue, Dec 9, 2008 at 1:09 PM, Mathew Binkley <mathewbink...@gmail.com > > > >> wrote: > > > >> > Hi. I''m hoping that someone can help me with a simple example. We > > are > > >> > trying to use puppet to update a server binary to a group of machines. > > >> > Here''s pseudocode for what I''m trying: > > > >> > if (server_binary has changed) { > > >> > 1) stop the old server > > >> > 2) overwrite the old server binary by > > >> > fetching the new server binary from puppet > > >> > 3) start the new server > > >> > } > > > >> > Here''s the puppet manifest I wrote to handle this, but it isn''t > > working > > >> > properly. It is not working as intended, and is 1) downloading the > > new > > >> > binary and then 2) stopping the server, which screws up our data. > > I''ve > > >> > been looking through the documentation, and it isn''t clear which > > >> > permutation of before, require, subscribe, or notify is necessary to > > >> > accomplish this. Hope someone can enlighten me. - Mat > > > >> > file { "/usr/local/sbin/server_binary": > > >> > source => "puppet:///files/server_binary", > > >> > require => Exec["stop-server"], > > >> > before => Exec["start-server"] > > >> > } > > > >> > # Stops the server > > >> > exec { "/usr/local/sbin/stop-server": > > >> > alias => "stop-server", > > >> > refreshonly => true > > >> > } > > > >> > # Starts the server > > >> > exec { "/usr/local/sbin/start-server": > > >> > alias => "start-server", > > >> > refreshonly => true > > >> > }--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---