Skip to content

Fix restart with systemd #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 47 additions & 10 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,53 @@
# For the default email notifications to work
ensure_packages(['mailx'])

service { 'nagios':
ensure => 'running',
enable => true,
# "service nagios status" returns 0 when "nagios is not running" :-(
hasstatus => false,
# Don't get fooled by any process with "nagios" in its command line
pattern => '/usr/sbin/nagios',
# Work around files created root:root mode 600 (known issue)
restart => '/bin/chgrp nagios /etc/nagios/nagios_*.cfg && /bin/chmod 640 /etc/nagios/nagios_*.cfg && /bin/kill -HUP `cat /var/run/nagios/nagios.pid`',
require => Package['nagios'],
case $facts['service_provider'] {
'systemd': {
file { '/usr/bin/nagios-ensure-permissions':
ensure => present,
mode => '0755',
content => "#!/bin/sh\nchgrp nagios /etc/nagios/nagios_*.cfg\nchmod 640 /etc/nagios/nagios_*.cfg",
}

file { '/etc/systemd/system/nagios.service.d':
ensure => directory,
}

file { '/etc/systemd/system/nagios.service.d/permissions.conf':
ensure => present,
content => "[Service]\nExecStartPre=/usr/bin/nagios-ensure-permissions",
require => [
File['/etc/systemd/system/nagios.service.d'],
File['/usr/bin/nagios-ensure-permissions'],
],
}

exec { 'nagios: update systemd configuration':
command => '/usr/sbin/systemctl daemon-reload',
refreshonly => true,
subscribe => File['/etc/systemd/system/nagios.service.d/permissions.conf'],
before => Service['nagios'],
}

service { 'nagios':
ensure => 'running',
enable => true,
require => File['/etc/systemd/system/nagios.service.d/permissions.conf'],
}
}
default: {
service { 'nagios':
ensure => 'running',
enable => true,
# "service nagios status" returns 0 when "nagios is not running" :-(
hasstatus => false,
# Don't get fooled by any process with "nagios" in its command line
pattern => '/usr/sbin/nagios',
# Work around files created root:root mode 600 (known issue)
restart => '/bin/chgrp nagios /etc/nagios/nagios_*.cfg && /bin/chmod 640 /etc/nagios/nagios_*.cfg && /bin/kill -HUP `cat /var/run/nagios/nagios.pid`',
require => Package['nagios'],
}
}
}

if $apache_httpd {
Expand Down