Custom fact for linux service

18 views
Skip to first unread message

Dennis Labkovich

unread,
Feb 21, 2018, 5:00:06 PM2/21/18
to Puppet Users
Hello,

Trying to create a custom fact that will be created if there is existing Linux service.
I am using check for the file existence and it works. See below.
But it looks like a better way would be using Puppet resource "service".
If someone has idea on more elegant implementation, please, advise.

Facter.add(:service_test) do
        confine :osfamily => "RedHat"
        setcode do
                if File.exist? '/etc/init.d/service_test'
                'service_test'
                end
        end
end

Bill Sirinek

unread,
Feb 21, 2018, 5:09:38 PM2/21/18
to Puppet Users
I'm not sure you need a custom fact for this. Can you just check to see if, for example, Service['autofs']  or Service['autofs.service'] are defined?   

Bill

Dirk Heinrichs

unread,
Feb 22, 2018, 2:10:09 AM2/22/18
to puppet...@googlegroups.com
From: puppet...@googlegroups.com [mailto:puppet...@googlegroups.com] On Behalf Of Bill Sirinek

> I'm not sure you need a custom fact for this. Can you just check to see if,
> for example, Service['autofs']  or Service['autofs.service'] are defined?

Don't think so. Service is for *controlling* existing services, so using the fact seems ok to me in case the service
file doesn't come as part of a package, in which case one could simply assume that if that package is installed,
the service must also be there:

package { 'mypkg':
...
}

service { 'myservice':
...
require => Package['mypkg'],
}

OTOH, if it is a custom service, one could as well manage the service file with Puppet, so that you can be sure it
exists when you want to manage it, like

file { '/etc/init.d/myservice':
...
}

service { 'myservice':
...
require => File['/etc/init.d/myservice'],
}

HTH...

Dirk
Reply all
Reply to author
Forward
0 new messages