Merge branch 'feature/systemd-4794-final' into next

fixes #4794
This commit is contained in:
Michael Friedrich 2014-06-15 20:27:15 +02:00
commit 61793a5dbb
9 changed files with 171 additions and 44 deletions

View File

@ -9,3 +9,4 @@ usr/share/icinga2
usr/share/man/man8/icinga2-*-feature.8 usr/share/man/man8/icinga2-*-feature.8
usr/share/man/man8/icinga2-build*.8 usr/share/man/man8/icinga2-build*.8
usr/share/man/man8/icinga2-sign-key.8 usr/share/man/man8/icinga2-sign-key.8
usr/share/man/man8/icinga2-prepare-dirs.8

View File

@ -19,7 +19,7 @@ file(GLOB DOCSRCS "*.md")
if(UNIX OR CYGWIN) if(UNIX OR CYGWIN)
install( install(
FILES icinga2.8 icinga2-enable-feature.8 icinga2-disable-feature.8 icinga2-build-ca.8 icinga2-build-key.8 icinga2-sign-key.8 FILES icinga2.8 icinga2-enable-feature.8 icinga2-disable-feature.8 icinga2-build-ca.8 icinga2-build-key.8 icinga2-sign-key.8 icinga2-prepare-dirs.8
DESTINATION ${CMAKE_INSTALL_MANDIR}/man8 DESTINATION ${CMAKE_INSTALL_MANDIR}/man8
) )
endif() endif()

View File

@ -0,0 +1,28 @@
.TH ICINGA2 "15" "June 2014" "icinga2 - The Icinga 2 network monitoring daemon." "System Administration Utilities"
.SH NAME
icinga2-prepare-dirs \- Prepare directories and their permissions for use by Icinga 2.
.SH DESCRIPTION
This script is used internally by the initscripts of Icinga 2 to prepare
prepare directories and their permissions. This script is not intended to be called by users.
.SH OPTIONS
.TP
\fB<sysconfig file>\fR
Absolute path to the sysconfig file of Icinga 2.
.SH AUTHOR
Icinga2 is maintained by the Icinga Project <info@icinga.org>.
.SH "REPORTING BUGS"
Report bugs at <https://dev.icinga.org/>
.br
Icinga home page: <http://www.icinga.org/>
.SH COPYRIGHT
Copyright \(co 2012\-2014 Icinga Development Team (http://www.icinga.org)
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl2.html>
.br
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

View File

@ -76,12 +76,45 @@ else()
endif() endif()
if(NOT WIN32) if(NOT WIN32)
configure_file(init.d/icinga2.cmake ${CMAKE_CURRENT_BINARY_DIR}/init.d/icinga2) if(NOT DEFINED ICINGA2_SYSCONFIGFILE)
set(ICINGA2_SYSCONFIGFILE "${CMAKE_INSTALL_SYSCONFDIR}/sysconfig/icinga2" CACHE PATH "where to store configuation for the init system, defaults to /etc/sysconfig/icinga2")
endif()
configure_file(initsystem/icinga2.sysconfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/initsystem/icinga2.sysconfig @ONLY)
get_filename_component(ICINGA2_SYSCONFIGFILE_NAME ${ICINGA2_SYSCONFIGFILE} NAME)
get_filename_component(ICINGA2_SYSCONFIGFILE_DIR ${ICINGA2_SYSCONFIGFILE} PATH)
install( install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/init.d/icinga2 FILES ${CMAKE_CURRENT_BINARY_DIR}/initsystem/icinga2.sysconfig
DESTINATION ${ICINGA2_SYSCONFIGFILE_DIR}
RENAME ${ICINGA2_SYSCONFIGFILE_NAME}
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
install(
FILES initsystem/icinga2-prepare-dirs
DESTINATION ${CMAKE_INSTALL_SBINDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
option (USE_SYSTEMD
"Configure icinga as native systemd service instead of a SysV initscript" OFF)
if (NOT USE_SYSTEMD)
configure_file(initsystem/icinga2.init.d.cmake ${CMAKE_CURRENT_BINARY_DIR}/initsystem/icinga2)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/initsystem/icinga2
DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/init.d DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/init.d
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
) )
else()
configure_file(initsystem/icinga2.service.cmake ${CMAKE_CURRENT_BINARY_DIR}/initsystem/icinga2.service @ONLY)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/initsystem/icinga2.service
DESTINATION ${DESTDIR}/usr/lib/systemd/system
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
endif()
endif() endif()
set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}" PARENT_SCOPE) set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}" PARENT_SCOPE)

View File

@ -0,0 +1,33 @@
#!/bin/sh
#
# This script prepares directories and files needed for running Icinga2
#
# 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
mkdir -p $(dirname -- $ICINGA2_PID_FILE)
chown $ICINGA2_USER:$ICINGA2_GROUP $(dirname -- $ICINGA2_PID_FILE)
if [ -f $ICINGA2_PID_FILE ]; then
chown $ICINGA2_USER:$ICINGA2_GROUP $ICINGA2_PID_FILE
fi
mkdir -p $(dirname -- $ICINGA2_ERROR_LOG)
chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $(dirname -- $ICINGA2_ERROR_LOG)
chmod 750 $(dirname -- $ICINGA2_ERROR_LOG)
if [ -f $ICINGA2_ERROR_LOG ]; then
chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_ERROR_LOG
fi
if [ -f $ICINGA2_LOG ]; then
chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_LOG
fi
mkdir -p $ICINGA2_STATE_DIR/run/icinga2/cmd
chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_STATE_DIR/run/icinga2/cmd
chmod 2755 $ICINGA2_STATE_DIR/run/icinga2/cmd

View File

@ -15,17 +15,14 @@
# Description: Icinga 2 is a monitoring and management system for hosts, services and networks. # Description: Icinga 2 is a monitoring and management system for hosts, services and networks.
### END INIT INFO ### END INIT INFO
DAEMON=@CMAKE_INSTALL_FULL_SBINDIR@/icinga2 # load system specific defines
ICINGA2_CONFIG_FILE=@CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/icinga2.conf SYSCONFIGFILE=@ICINGA2_SYSCONFIGFILE@
ICINGA2_STATE_DIR=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@ if [ -f $SYSCONFIGFILE ]; then
ICINGA2_PID_FILE=$ICINGA2_STATE_DIR/run/icinga2/icinga2.pid . $SYSCONFIGFILE
ICINGA2_ERROR_LOG=$ICINGA2_STATE_DIR/log/icinga2/error.log else
ICINGA2_STARTUP_LOG=$ICINGA2_STATE_DIR/log/icinga2/startup.log echo "Can't load system specific defines from $SYSCONFIGFILE."
ICINGA2_LOG=$ICINGA2_STATE_DIR/log/icinga2/icinga2.log exit 1
ICINGA2_USER=@ICINGA2_USER@ fi
ICINGA2_GROUP=@ICINGA2_GROUP@
ICINGA2_COMMAND_USER=@ICINGA2_COMMAND_USER@
ICINGA2_COMMAND_GROUP=@ICINGA2_COMMAND_GROUP@
test -x $DAEMON || exit 0 test -x $DAEMON || exit 0
@ -42,38 +39,14 @@ elif [ -f /etc/init.d/functions ]; then
fi fi
# Load extra environment variables # Load extra environment variables
if [ -f /etc/sysconfig/icinga ]; then if [ -f /etc/default/icinga2 ]; then
. /etc/sysconfig/icinga . /etc/default/icinga2
fi fi
if [ -f /etc/default/icinga ]; then
. /etc/default/icinga
fi
check_run() {
mkdir -p $(dirname -- $ICINGA2_PID_FILE)
chown $ICINGA2_USER:$ICINGA2_GROUP $(dirname -- $ICINGA2_PID_FILE)
if [ -f $ICINGA2_PID_FILE ]; then
chown $ICINGA2_USER:$ICINGA2_GROUP $ICINGA2_PID_FILE
fi
mkdir -p $(dirname -- $ICINGA2_ERROR_LOG)
chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $(dirname -- $ICINGA2_ERROR_LOG)
chmod 750 $(dirname -- $ICINGA2_ERROR_LOG)
if [ -f $ICINGA2_ERROR_LOG ]; then
chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_ERROR_LOG
fi
if [ -f $ICINGA2_LOG ]; then
chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_LOG
fi
mkdir -p $ICINGA2_STATE_DIR/run/icinga2/cmd
chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_STATE_DIR/run/icinga2/cmd
chmod 2755 $ICINGA2_STATE_DIR/run/icinga2/cmd
}
# Start Icinga 2 # Start Icinga 2
start() { start() {
printf "Starting Icinga 2: " printf "Starting Icinga 2: "
@CMAKE_INSTALL_FULL_SBINDIR@/icinga2-prepare-dirs $SYSCONFIGFILE
if ! $DAEMON -c $ICINGA2_CONFIG_FILE -d -e $ICINGA2_ERROR_LOG -u $ICINGA2_USER -g $ICINGA2_GROUP > $ICINGA2_STARTUP_LOG 2>&1; then if ! $DAEMON -c $ICINGA2_CONFIG_FILE -d -e $ICINGA2_ERROR_LOG -u $ICINGA2_USER -g $ICINGA2_GROUP > $ICINGA2_STARTUP_LOG 2>&1; then
echo "Error starting Icinga. Check '$ICINGA2_STARTUP_LOG' for details." echo "Error starting Icinga. Check '$ICINGA2_STARTUP_LOG' for details."
@ -167,8 +140,6 @@ status() {
fi fi
} }
check_run
### main logic ### ### main logic ###
case "$1" in case "$1" in
start) start)

View File

@ -0,0 +1,14 @@
[Unit]
Description=Host/service/network monitoring system
After=syslog.target postgresql.service mariadb.service
[Service]
Type=forking
EnvironmentFile=@ICINGA2_SYSCONFIGFILE@
ExecStartPre=@CMAKE_INSTALL_FULL_SBINDIR@/icinga2-prepare-dirs @ICINGA2_SYSCONFIGFILE@
ExecStart=@CMAKE_INSTALL_FULL_SBINDIR@/icinga2 -c ${ICINGA2_CONFIG_FILE} -d -e ${ICINGA2_ERROR_LOG} -u ${ICINGA2_USER} -g ${ICINGA2_GROUP}
PIDFile=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/run/icinga2/icinga2.pid
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,11 @@
DAEMON=@CMAKE_INSTALL_FULL_SBINDIR@/icinga2
ICINGA2_CONFIG_FILE=@CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/icinga2.conf
ICINGA2_STATE_DIR=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@
ICINGA2_PID_FILE=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/run/icinga2/icinga2.pid
ICINGA2_ERROR_LOG=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/log/icinga2/error.log
ICINGA2_STARTUP_LOG=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/log/icinga2/startup.log
ICINGA2_LOG=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/log/icinga2/icinga2.log
ICINGA2_USER=@ICINGA2_USER@
ICINGA2_GROUP=@ICINGA2_GROUP@
ICINGA2_COMMAND_USER=@ICINGA2_COMMAND_USER@
ICINGA2_COMMAND_GROUP=@ICINGA2_COMMAND_GROUP@

View File

@ -27,7 +27,14 @@
%define apacheconfdir %{_sysconfdir}/httpd/conf.d %define apacheconfdir %{_sysconfdir}/httpd/conf.d
%define apacheuser apache %define apacheuser apache
%define apachegroup apache %define apachegroup apache
%if 0%{?el5}%{?el6}
%define use_systemd 0
%else
# fedora and el>=7
%define use_systemd 1
%endif %endif
%endif
%if "%{_vendor}" == "suse" %if "%{_vendor}" == "suse"
# opensuse 13 # opensuse 13
%if 0%{?suse_version} >= 1310 %if 0%{?suse_version} >= 1310
@ -40,6 +47,7 @@
%define apacheconfdir %{_sysconfdir}/apache2/conf.d %define apacheconfdir %{_sysconfdir}/apache2/conf.d
%define apacheuser wwwrun %define apacheuser wwwrun
%define apachegroup www %define apachegroup www
%define use_systemd 0
%endif %endif
%define icinga_user icinga %define icinga_user icinga
@ -132,6 +140,11 @@ Requires: libboost_regex%{opensuse_boost_version}
%endif %endif
# suse # suse
%if 0%{?use_systemd}
BuildRequires: systemd
Requires: systemd
%endif
Requires: %{name}-common = %{version} Requires: %{name}-common = %{version}
%description bin %description bin
@ -243,6 +256,10 @@ CMAKE_OPTS="$CMAKE_OPTS -DBOOST_LIBRARYDIR=/usr/lib/boost141 \
%endif %endif
%endif %endif
%if 0%{?use_systemd}
CMAKE_OPTS="$CMAKE_OPTS -DUSE_SYSTEMD=ON"
%endif
cmake $CMAKE_OPTS . cmake $CMAKE_OPTS .
make %{?_smp_mflags} make %{?_smp_mflags}
@ -289,7 +306,11 @@ exit 0
%else %else
# rhel # rhel
%if 0%{?use_systemd}
%systemd_post %{name}.service
%else
/sbin/chkconfig --add %{name} /sbin/chkconfig --add %{name}
%endif
if [ ${1:-0} -eq 1 ] if [ ${1:-0} -eq 1 ]
then then
@ -319,9 +340,13 @@ exit 0
%else %else
# rhel # rhel
%if 0%{?use_systemd}
%systemd_postun_with_restart %{name}.service
%else
if [ "$1" -ge "1" ]; then if [ "$1" -ge "1" ]; then
/sbin/service %{name} condrestart >/dev/null 2>&1 || : /sbin/service %{name} condrestart >/dev/null 2>&1 || :
fi fi
%endif
if [ "$1" = "0" ]; then if [ "$1" = "0" ]; then
# deinstallation of the package - remove enabled features # deinstallation of the package - remove enabled features
@ -345,10 +370,14 @@ exit 0
%else %else
# rhel # rhel
%if 0%{?use_systemd}
%systemd_preun %{name}.service
%else
if [ "$1" = "0" ]; then if [ "$1" = "0" ]; then
/sbin/service %{name} stop > /dev/null 2>&1 || : /sbin/service %{name} stop > /dev/null 2>&1 || :
/sbin/chkconfig --del %{name} || : /sbin/chkconfig --del %{name} || :
fi fi
%endif
exit 0 exit 0
@ -413,7 +442,11 @@ exit 0
%files bin %files bin
%defattr(-,root,root,-) %defattr(-,root,root,-)
%doc COPYING COPYING.Exceptions README NEWS AUTHORS ChangeLog %doc COPYING COPYING.Exceptions README NEWS AUTHORS ChangeLog
%if 0%{?use_systemd}
%attr(644,-,0) %{_unitdir}/%{name}.service
%else
%attr(755,-,-) %{_sysconfdir}/init.d/%{name} %attr(755,-,-) %{_sysconfdir}/init.d/%{name}
%endif
%attr(0750,%{icinga_user},%{icinga_group}) %dir %{_sysconfdir}/%{name} %attr(0750,%{icinga_user},%{icinga_group}) %dir %{_sysconfdir}/%{name}
%attr(0750,%{icinga_user},%{icinga_group}) %dir %{_sysconfdir}/%{name}/conf.d %attr(0750,%{icinga_user},%{icinga_group}) %dir %{_sysconfdir}/%{name}/conf.d
%attr(0750,%{icinga_user},%{icinga_group}) %dir %{_sysconfdir}/%{name}/conf.d/hosts %attr(0750,%{icinga_user},%{icinga_group}) %dir %{_sysconfdir}/%{name}/conf.d/hosts
@ -431,12 +464,14 @@ exit 0
%config(noreplace) %attr(0640,%{icinga_user},%{icinga_group}) %{_sysconfdir}/%{name}/features-available/*.conf %config(noreplace) %attr(0640,%{icinga_user},%{icinga_group}) %{_sysconfdir}/%{name}/features-available/*.conf
%config(noreplace) %attr(0640,%{icinga_user},%{icinga_group}) %{_sysconfdir}/%{name}/zones.d/* %config(noreplace) %attr(0640,%{icinga_user},%{icinga_group}) %{_sysconfdir}/%{name}/zones.d/*
%config(noreplace) %{_sysconfdir}/%{name}/scripts/* %config(noreplace) %{_sysconfdir}/%{name}/scripts/*
%config(noreplace) %{_sysconfdir}/sysconfig/%{name}
%{_sbindir}/%{name} %{_sbindir}/%{name}
%{_bindir}/%{name}-build-ca %{_bindir}/%{name}-build-ca
%{_bindir}/%{name}-build-key %{_bindir}/%{name}-build-key
%{_bindir}/%{name}-sign-key %{_bindir}/%{name}-sign-key
%{_sbindir}/%{name}-enable-feature %{_sbindir}/%{name}-enable-feature
%{_sbindir}/%{name}-disable-feature %{_sbindir}/%{name}-disable-feature
%{_sbindir}/%{name}-prepare-dirs
%exclude %{_libdir}/%{name}/libdb_ido_mysql* %exclude %{_libdir}/%{name}/libdb_ido_mysql*
%exclude %{_libdir}/%{name}/libdb_ido_pgsql* %exclude %{_libdir}/%{name}/libdb_ido_pgsql*
%{_libdir}/%{name} %{_libdir}/%{name}
@ -448,6 +483,7 @@ exit 0
%{_mandir}/man8/%{name}-build-ca.8.gz %{_mandir}/man8/%{name}-build-ca.8.gz
%{_mandir}/man8/%{name}-build-key.8.gz %{_mandir}/man8/%{name}-build-key.8.gz
%{_mandir}/man8/%{name}-sign-key.8.gz %{_mandir}/man8/%{name}-sign-key.8.gz
%{_mandir}/man8/%{name}-prepare-dirs.8.gz
%attr(0755,%{icinga_user},%{icinga_group}) %{_localstatedir}/cache/%{name} %attr(0755,%{icinga_user},%{icinga_group}) %{_localstatedir}/cache/%{name}
%attr(0755,%{icinga_user},%{icinga_group}) %dir %{_localstatedir}/log/%{name} %attr(0755,%{icinga_user},%{icinga_group}) %dir %{_localstatedir}/log/%{name}