diff --git a/etc/initsystem/CMakeLists.txt b/etc/initsystem/CMakeLists.txt index 97341506a..4ad18fc27 100644 --- a/etc/initsystem/CMakeLists.txt +++ b/etc/initsystem/CMakeLists.txt @@ -29,7 +29,7 @@ if(NOT WIN32) ) install( - FILES prepare-dirs + FILES prepare-dirs safe-reload DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/icinga2 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) diff --git a/etc/initsystem/icinga2.init.d.cmake b/etc/initsystem/icinga2.init.d.cmake index 5d4b99174..204de135f 100644 --- a/etc/initsystem/icinga2.init.d.cmake +++ b/etc/initsystem/icinga2.init.d.cmake @@ -108,19 +108,7 @@ stop() { # Reload Icinga 2 reload() { - printf "Reloading Icinga 2: " - - if [ ! -e $ICINGA2_PID_FILE ]; then - exit 7 - fi - - pid=`cat $ICINGA2_PID_FILE` - if kill -HUP $pid >/dev/null 2>&1; then - echo "Done" - else - echo "Error: Icinga not running" - exit 7 - fi + exec @CMAKE_INSTALL_PREFIX@/lib/icinga2/safe-reload $SYSCONFIGFILE } # Check the Icinga 2 configuration diff --git a/etc/initsystem/icinga2.service.cmake b/etc/initsystem/icinga2.service.cmake index 4f63805be..e4e58c47b 100644 --- a/etc/initsystem/icinga2.service.cmake +++ b/etc/initsystem/icinga2.service.cmake @@ -8,7 +8,7 @@ EnvironmentFile=@ICINGA2_SYSCONFIGFILE@ ExecStartPre=@CMAKE_INSTALL_PREFIX@/lib/icinga2/prepare-dirs @ICINGA2_SYSCONFIGFILE@ ExecStart=@CMAKE_INSTALL_FULL_SBINDIR@/icinga2 daemon -d -e ${ICINGA2_ERROR_LOG} PIDFile=@ICINGA2_RUNDIR@/icinga2/icinga2.pid -ExecReload=/bin/kill -HUP $MAINPID +ExecReload=@CMAKE_INSTALL_PREFIX@/lib/icinga2/safe-reload @ICINGA2_SYSCONFIGFILE@ [Install] WantedBy=multi-user.target diff --git a/etc/initsystem/safe-reload b/etc/initsystem/safe-reload new file mode 100644 index 000000000..6927aec30 --- /dev/null +++ b/etc/initsystem/safe-reload @@ -0,0 +1,40 @@ +#!/bin/sh +# load system specific defines +SYSCONFIGFILE=$1 +if [ -f "$SYSCONFIGFILE" ]; then + . $SYSCONFIGFILE +else + echo "Error: You need to supply the path to the Icinga2 sysconfig file as parameter." + exit 1 +fi + +printf "Validating config files: " + +OUTPUTFILE=`mktemp` + +if ! $DAEMON daemon --validate --color > $OUTPUTFILE; then + echo "Failed" + + cat $OUTPUTFILE + rm -f $OUTPUTFILE + exit 1 +fi + +echo "Done" +rm -f $OUTPUTFILE + +printf "Reloading Icinga 2: " + +if [ ! -e $ICINGA2_PID_FILE ]; then + exit 7 +fi + +pid=`cat $ICINGA2_PID_FILE` +if kill -HUP $pid >/dev/null 2>&1; then + echo "Done" +else + echo "Error: Icinga not running" + exit 7 +fi + +exit 0 diff --git a/icinga2.spec b/icinga2.spec index b70d163e6..41432f5ec 100644 --- a/icinga2.spec +++ b/icinga2.spec @@ -489,6 +489,7 @@ exit 0 %config(noreplace) %{_sysconfdir}/%{name}/scripts/* %dir %{_libexecdir}/%{name} %{_libexecdir}/%{name}/prepare-dirs +%{_libexecdir}/%{name}/safe-reload %attr(0750,%{icinga_user},%{icinga_group}) %dir %{_localstatedir}/spool/%{name} %attr(0750,%{icinga_user},%{icinga_group}) %dir %{_localstatedir}/spool/%{name}/perfdata %attr(0750,%{icinga_user},%{icinga_group}) %dir %{_localstatedir}/spool/%{name}/tmp