[icinga-checkins] icinga.org: icinga2/next: First try at a systemd service definition file, install it from CMake.

git at icinga.org git at icinga.org
Sun Jun 15 20:27:42 CEST 2014


Module: icinga2
Branch: next
Commit: 69c06115d2dd27f665bfe9955e9648580f52ef8b
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=69c06115d2dd27f665bfe9955e9648580f52ef8b

Author: Gerd von Egidy <gerd at egidy.de>
Date:   Thu May  1 01:48:01 2014 +0200

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

Native systemd support is enabled with cmake -DUSE_SYSTEMD=ON

Refs #4794

---

 etc/CMakeLists.txt                  |   33 +++++++++++++++++++++++++++------
 etc/systemd/icinga2.service.cmake   |   16 ++++++++++++++++
 etc/systemd/icinga2.sysconfig.cmake |    8 ++++++++
 3 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt
index b36d324..fc1f686 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 0000000..a0a570d
--- /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 0000000..2ea3bca
--- /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@



More information about the icinga-checkins mailing list