diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt index b36d324ea..fc1f6865d 100644 --- a/etc/CMakeLists.txt +++ b/etc/CMakeLists.txt @@ -76,12 +76,33 @@ else() endif() if(NOT WIN32) - configure_file(init.d/icinga2.cmake ${CMAKE_CURRENT_BINARY_DIR}/init.d/icinga2) - install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/init.d/icinga2 - DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/init.d - 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(init.d/icinga2.cmake ${CMAKE_CURRENT_BINARY_DIR}/init.d/icinga2) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/init.d/icinga2 + DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/init.d + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE + ) + else() + configure_file(systemd/icinga2.service.cmake ${CMAKE_CURRENT_BINARY_DIR}/systemd/icinga2.service) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/systemd/icinga2.service + DESTINATION ${DESTDIR}/usr/lib/systemd/system + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_EXECUTE WORLD_READ + ) + + configure_file(systemd/icinga2.sysconfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/systemd/icinga2) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/systemd/icinga2 + DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/sysconfig + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_EXECUTE WORLD_READ + ) + endif() endif() set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}" PARENT_SCOPE) diff --git a/etc/systemd/icinga2.service.cmake b/etc/systemd/icinga2.service.cmake new file mode 100644 index 000000000..a0a570d68 --- /dev/null +++ b/etc/systemd/icinga2.service.cmake @@ -0,0 +1,16 @@ +[Unit] +Description=Icinga host/service/network monitoring system +After=syslog.target postgresql.service mariadb.service + +[Service] +Type=forking +EnvironmentFile=/etc/sysconfig/icinga2 +# ExecStartPre= TODO: execute the mkdir & chown/chmod stuff, ideally in a separate script, used by both init.d and systemd +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 + +# TODO: reload not working, seems like systemd kills the newly forked daemon process +#ExecReload=/bin/kill -HUP $MAINPID + +[Install] +WantedBy=multi-user.target diff --git a/etc/systemd/icinga2.sysconfig.cmake b/etc/systemd/icinga2.sysconfig.cmake new file mode 100644 index 000000000..2ea3bca39 --- /dev/null +++ b/etc/systemd/icinga2.sysconfig.cmake @@ -0,0 +1,8 @@ +ICINGA2_CONFIG_FILE=@CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/icinga2.conf +ICINGA2_STATE_DIR=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@ +ICINGA2_ERROR_LOG=$ICINGA2_STATE_DIR/log/icinga2/error.log +ICINGA2_LOG=$ICINGA2_STATE_DIR/log/icinga2/icinga2.log +ICINGA2_USER=@ICINGA2_USER@ +ICINGA2_GROUP=@ICINGA2_GROUP@ +ICINGA2_COMMAND_USER=@ICINGA2_COMMAND_USER@ +ICINGA2_COMMAND_GROUP=@ICINGA2_COMMAND_GROUP@