user1074593
user1074593

Reputation: 630

How to provide a startup service file in Puppet

We have RedHat 7.2 Linux OS and use puppet to perform our tasks. I am using puppet to install some software, which has worked fine and now the final step is to create an OS level service. In earlier versions of RHEL, we used chkconfig but that has been replaced with systemctl. Of course, the recommended way of performing this task is using a service. Since this is a custom software, I have my own startup script that I usually copy over to /etc/init.d, run chkconfig and then startup the service. How do I perform these tasks via Puppet for RedHat 7.2 OS ? I only want to create the service (not start it up or anything). This way, when the server reboots, the service will startup the app.

EDIT :

@redstonemercury for RHEL 7 I would think the following would be required. But your suggestion definitely helps as I was thinking along the same lines.

https://serverfault.com/questions/814611/puppet-generated-systemd-unit-files

file { '/lib/systemd/system/myservice.service':
  mode    => '0644',
  owner   => 'root',
  group   => 'root',
  content => template('modulename/myservice.systemd.erb'),
}~>
exec { 'myservice-systemd-reload':
  command     => 'systemctl daemon-reload',
  path        => [ '/usr/bin', '/bin', '/usr/sbin' ],
  refreshonly => true,
}

Upvotes: 1

Views: 2076

Answers (1)

redstonemercury
redstonemercury

Reputation: 364

In puppet, use a package resource to install the package (assuming it's in repos that you're declaring already), then use a file resource to declare the /etc/init.d file, and put require => Package[<package_resource_name>] as a parameter in the file declaration to ensure the custom file gets created after the package has installed (so doesn't potentially get overwritten by the package's /etc/init.d file). E.g.:

package { 'mypackage':
    ensure => present,
}

file { '/etc/init.d/mypackage':
    ensure  => present,
    content => template('mypackage/myinitd'),
    require => Package['mypackage'],
}

This is if you want to use a template. For a file, instead of content use source: source => puppet://modules/mypackage/myinitd

Upvotes: 3

Related Questions