First try at a systemd service definition file, install it from CMake.

Native systemd support is enabled with cmake -DUSE_SYSTEMD=ON

Refs #4794
This commit is contained in:
Gerd von Egidy 2014-05-01 01:48:01 +02:00
parent 86a71aa0b3
commit 69c06115d2
3 changed files with 51 additions and 6 deletions

View File

@ -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)

View File

@ -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

View File

@ -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@