FreeBSD 14
Sponsored Link

Puppet : How to use [service Resource]2024/09/12

 

This is the examples for [service] resource.

[1] It manages the configuration to keep [apache24] is running.
root@dlp:~ #
vi /usr/local/etc/puppet/code/environments/production/manifests/svc01.pp
service { 'apache24':
  name   => 'apache24',
  ensure => running,
}
[2] It manages the configuration to keep [apache24] is running.
However, if [apache24] is not installed, [apache24] can not start of course, so it manages the configuration to keep [apache24] is installed with [require] parameter like follows.
root@dlp:~ #
vi /usr/local/etc/puppet/code/environments/production/manifests/pkg01.pp
package { 'apache24':
  provider => pkgng,
  ensure   => installed,
}

root@dlp:~ #
vi /usr/local/etc/puppet/code/environments/production/manifests/svc01.pp
service { 'apache24':
  name    => 'apache24',
  ensure  => running,
  require => Package['apache24'],
}
[3] It manages the configuration to keep sshd is not running. If running, it stops.
root@dlp:~ #
vi /usr/local/etc/puppet/code/environments/production/manifests/svc02.pp
service { 'sshd':
  name   => 'sshd',
  ensure => stopped,
}
[4] It restarts [apache24] when the file [/usr/local/etc/apache24/extra/security.conf] is updated.
root@dlp:~ #
vi /usr/local/etc/puppet/code/environments/production/manifests/svc03.pp
file { '/usr/local/etc/apache24/extra/security.conf':
  ensure => file,
  owner  => 'root',
  group  => 'wheel',
  mode   => '0644',
  source => 'puppet://dlp.srv.world/extra_files/security.conf',
  notify => Service['apache24'],
}

root@dlp:~ #
vi /usr/local/etc/puppet/files/security.conf
ServerTokens Prod
ServerSignature On
TraceEnable Off
Matched Content