ignoring a service that doesn't exist

1,015 views
Skip to first unread message

Christopher Wood

unread,
Jan 17, 2012, 4:09:26 PM1/17/12
to puppet...@googlegroups.com
I definitely need some assistance in conceptualizing something.

If I want to configure syslog-ng instead of rsyslog, or configure rsyslog instead of sysklogd, the previous syslog daemon has to be stopped (and disabled) before the new one starts. De-configuring the previous one works just fine when the service (init script) exists on the system:

$disable = ['rsyslog', 'syslog']
service { $disable:
enable => false,
ensure => stopped,
}

But when the init script doesn't exist, I get something like this:

Jan 17 15:05:44 dpuppet-01 puppet-agent[4011]: (/Stage[main]/Sysklogd::Disable/Service[syslog]/ensure) change from running to stopped failed: Could not find init script for 'syslog'

How would I say "if it's there, disable it, if not, ignore it" in puppet DSL?

(For completeness, this is with puppet 2.6.2 on various platforms.)

Daniel Pittman

unread,
Jan 17, 2012, 4:32:28 PM1/17/12
to puppet...@googlegroups.com

exec { "damn!": … }

Sadly, there isn't any way to express this in the DSL. I suspect
there might be a feature request already, but I can't find one, so can
you file one? This seems like a useful thing to do, without thinking
too deeply about it.

--
Daniel Pittman
⎋ Puppet Labs Developer – http://puppetlabs.com
♲ Made with 100 percent post-consumer electrons

Nan Liu

unread,
Jan 17, 2012, 4:42:38 PM1/17/12
to puppet...@googlegroups.com

You can't use the init.d script (or hasstatus=true) to check for
service, so you fall back and specify the service command in this
case:

service { 'rsyslog':
ensure => stopped, # this is normally first attribute.
enable => false,
status => 'source /etc/init.d/functions; status rsyslogd', # provide
a way to check status regardless if the init.d script is available.
}

Thanks,

Nan

Stefan Schulte

unread,
May 9, 2013, 5:53:13 PM5/9/13
to puppet...@googlegroups.com
On Thu, 9 May 2013 13:58:45 -0700 (PDT)
John Simpson <jm...@voalte.com> wrote:

> I've done the following, it ended up being a bit simpler for me when
> I'm not sure what random services a new CentOS install has installed
> and/or enabled...
>
> define no_service ( ) {
> service { "${name}" :
> ensure => stopped ,
> enable => false ,
> status => "stat -t /etc/rc?.d/S??${name} > /dev/null 2>&1" ,
> }
> }
>
> You can then declare individual service names, or lists of service
> names, each of which will be disabled and shut down if the service is
> enabled. If a particular service doesn't exist, the puppet agent does
> nothing.
>
> no_service { 'ip6tables' : }
> no_service { [ 'nfslock' , 'portmap' , 'xyzzy' ] : }
>
> The only caveat is, if a service is disabled (i.e. "chkconfig service
> off") but the service is still running, the puppet agent won't stop
> it. Of course, if you have a service which is normally off and you've
> only enabled it to test something, this could be a good thing...
>

you should be able to just specify `hasstatus => false`. This way
puppet will check the process list in order to get the current status
and will not run the (absent) initscript to get the status.

-Stefan

Reply all
Reply to author
Forward
0 new messages