ender.qa
ender.qa

Reputation: 129

In puppet, how to I determine if computer is using systemd or sysvinit?

I have a custom puppet module which installs a daemon/service: a small ruby Webrick. I have both a systemd script to start/stop the daemon. I also now have a Sysvinit script. I would like to install the appropriate script for either one.

My ideal puppet-flow would be:

Is this possible?

We are running puppet 4.4.2.

Upvotes: 0

Views: 1241

Answers (1)

Alex Harvey
Alex Harvey

Reputation: 15502

The usual way to handle it is using facts and conditionals, e.g. (from the Elasticsearch Approved module):

params.pp:

case $::operatingsystem {
  'RedHat', 'CentOS', 'Fedora', 'Scientific', 'OracleLinux', 'SLC': {
    $service_name       = 'elasticsearch'
    $service_hasrestart = true
    $service_hasstatus  = true
    $service_pattern    = $service_name
    $defaults_location  = '/etc/sysconfig'
    $pid_dir            = '/var/run/elasticsearch'

    if versioncmp($::operatingsystemmajrelease, '7') >= 0 {
      $init_template        = 'elasticsearch.systemd.erb'
      $service_providers    = 'systemd'
      $systemd_service_path = '/lib/systemd/system'
    } else {
      $init_template        = 'elasticsearch.RedHat.erb'
      $service_providers    = 'init'
      $systemd_service_path = undef
    }

  }

Note that this is Puppet 3 compatible code; look into current best practices with respect to facter facts and $facts Hash if you want Puppet 4 best practices and you don't need to support Puppet 3.

If you don't like assuming the availability of Systemd based on the OS version, you could also make a custom fact to report Systemd's available.

Upvotes: 1

Related Questions