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
<[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]>
>>
>> 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 <[EMAIL PROTECTED]>
>> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to