Notify service in one class from other class

179 views
Skip to first unread message

Denis Kot

unread,
Jan 13, 2014, 8:51:32 AM1/13/14
to puppet...@googlegroups.com
I have the following classes:
class zabbix-agent {
...
    package {'zabbix-agent':
        ensure => installed
    }
...
    service { "zabbix-agent":
        ensure     => running,
        start    => "/etc/init.d/zabbix-agent start",
        stop    => "/etc/init.d/zabbix-agent stop",
        status    => "/etc/init.d/zabbix-agent status",
        restart    => "/etc/init.d/zabbix-agent restart",
        require => Package['zabbix-agent']
    }
}

class redis {
...
    file {"/etc/zabbix/zabbix_agentd.conf.d/redis.conf":
        source  => "puppet:///modules/redis/redis_monitoring.conf",
        require => Package['zabbix-agent'],
        notify => Service['zabbix-agent']
    }
...
}

node /^data\d+\.example\.com$/ inherits 'prerun'
{
    class 'redis'
}


node 'prerun' {
...
   class {'zabbix-agent': stage => pre}
...
}

but that code produces error:

err: Could not apply complete catalog: Found dependency cycles in the following relationships: Service[zabbix-agent] => File[/etc/redis/redis.conf], Package[redis-server] => File[/etc/redis/redis.conf], Service[zabbix-agent] => Class[Settings], Service[zabbix-agent] => File[/etc/puppet/puppet.conf], File[/etc/zabbix/zabbix_agentd.conf.d/redis_monitoring.conf] => Service[zabbix-agent], Service[zabbix-agent] => File[/etc/zabbix/zabbix_agentd.conf.d/redis_monitoring.conf], Service[zabbix-agent] => File[/etc/puppet/auth.conf], Service[zabbix-agent] => Class[prerun], File[/etc/redis/redis.conf] => Service[redis-server], Service[zabbix-agent] => Service[redis-server], Service[zabbix-agent] => Package[redis-server], Service[zabbix-agent] => File[/etc/puppet/namespaceauth.conf], Service[zabbix-agent] => Class[datad.leaderboard.lvis.tv]; try using the '--graph' option and open the '.dot' files in OmniGraffle or GraphViz

what's wrong? if I comment out 'notify' puppet doesn't complain, but doesn't restart service too.

Joseph Swick

unread,
Jan 13, 2014, 10:10:40 AM1/13/14
to puppet...@googlegroups.com
On 01/13/2014 08:51 AM, Denis Kot wrote:
> I have the following classes:

<trim>

>
> node 'prerun' {
> ...
> class {'zabbix-agent': stage => pre}
> ...
> }
>
> but that code produces error:
>
> err: Could not apply complete catalog: Found dependency cycles in the
> following relationships: Service[zabbix-agent] =>

<cut>

>
> what's wrong? if I comment out 'notify' puppet doesn't complain, but
> doesn't restart service too.
>

From my quick look at it, it would appear that your 'pre' stage is the
cause of it. Judging by it's name, I'm assuming you have a

stage { 'pre': before => Stage['main'] }

Somewhere in your manifiests?

I've found that stages are very finicky about the order of items,
especially when doing relationships between items in different stages.
I try to avoid stages whenever possible and do resource ordering within
the main puppet stage to ensure items are created in the correct order.
The few places I do use stages, I have them run after main and I'll
eventually work to remove them.

Have you tried running it without the stage?

--
Joseph Swick <joseph...@meltwater.com>
Operations Engineer
Meltwater Group

signature.asc

Ramin K

unread,
Jan 13, 2014, 11:22:36 AM1/13/14
to puppet...@googlegroups.com
Stages should be treated as black boxes where you assume everything that
was suppose to happen in an earlier stage has already happened. You can
not notify to any resources from a resource in a later stage. And it's a
bad idea to refer to any resources between any stage as you're almost
guaranteed to cause dependency cycles. This is why stages are only used
for a small subset of problems.

In your case I don't see any reason for zabbix to be in a stage. No
point in monitoring being up before the services it needs to monitor.
Remove stage => when you declare it and you should be fine though you
might need to fix ordering afterwards.

Ramin

jcbollinger

unread,
Jan 13, 2014, 6:13:06 PM1/13/14
to puppet...@googlegroups.com


On Monday, January 13, 2014 10:22:36 AM UTC-6, Ramin K wrote:

Stages should be treated as black boxes where you assume everything that
was suppose to happen in an earlier stage has already happened.


That's a good description.

 
You can
not notify to any resources from a resource in a later stage.


Because that always forms a dependency cycle.  If one resource declares that it notifies another then the notifier must be applied first.  If the notifyee is in an earlier run stage then it must be applied first.  Voilà, a cycle.

 
And it's a
bad idea to refer to any resources between any stage as you're almost
guaranteed to cause dependency cycles.


Yes, as a generalization of the 'notify' case.  Any resource reference that crosses run stage boundaries is either redundant or cycle-inducing.

 
This is why stages are only used
for a small subset of problems.



I'm not much of a fan of run stages myself, though there are situations for which they do provide an advantage.  Overall, though, there is nothing run stages can do that you cannot also do via ordinary resource relationships.  At least in principle.

 
In your case I don't see any reason for zabbix to be in a stage. No
point in monitoring being up before the services it needs to monitor.
Remove stage => when you declare it and you should be fine though you
might need to fix ordering afterwards.



Alternatively, put Class['redis'] in stage 'pre', too.  Of course, that will just send you down a rabbit hole if there are other classes that need to be applied before Class['redis'].  Aaaannd we're back to me not caring much for stages.


John

Reply all
Reply to author
Forward
0 new messages