Skip to content

Commit

Permalink
Validate configuration files during reload
Browse files Browse the repository at this point in the history
fixes #7045
  • Loading branch information
gunnarbeutner committed Dec 11, 2014
1 parent 5ada74a commit ab14373
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 15 deletions.
2 changes: 1 addition & 1 deletion etc/initsystem/CMakeLists.txt
Expand Up @@ -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
)
Expand Down
14 changes: 1 addition & 13 deletions etc/initsystem/icinga2.init.d.cmake
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion etc/initsystem/icinga2.service.cmake
Expand Up @@ -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
40 changes: 40 additions & 0 deletions 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
1 change: 1 addition & 0 deletions icinga2.spec
Expand Up @@ -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
Expand Down

0 comments on commit ab14373

Please sign in to comment.