]> granicus.if.org Git - icinga2/commitdiff
Validate configuration files during reload
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 11 Dec 2014 08:27:31 +0000 (09:27 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 11 Dec 2014 08:27:31 +0000 (09:27 +0100)
fixes #7045

etc/initsystem/CMakeLists.txt
etc/initsystem/icinga2.init.d.cmake
etc/initsystem/icinga2.service.cmake
etc/initsystem/safe-reload [new file with mode: 0644]
icinga2.spec

index 97341506a5ab50337ca834de7ca61d03fe0ddc47..4ad18fc2760761f7eba73699bcb15340185f4481 100644 (file)
@@ -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
   )
index 5d4b991747db69f6e9e1964277a265b66d3bbaf1..204de135fd4d32b3cb1f71e212f4b237994b16f6 100644 (file)
@@ -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
index 4f63805be15cdea94c0ae9ae455aa69f2fee226e..e4e58c47b73ae7aec696bdfdbafea7e49e2a5f7b 100644 (file)
@@ -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 (file)
index 0000000..6927aec
--- /dev/null
@@ -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
index b70d163e653bcf71a0b24df6e5c5ae3823d9b0a5..41432f5eca0870358d61199d4f85eb116606bffc 100644 (file)
@@ -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