[icinga-checkins] icinga.org: icinga2/feature/systemd-4794-final: Move code preparing dirs and permissions to icinga2-prepare-dirs, use this for SysV-Init and systemd.

git at icinga.org git at icinga.org
Sun Jun 15 17:34:51 CEST 2014


Module: icinga2
Branch: feature/systemd-4794-final
Commit: 4ebde46520657ac90303fd3d61b0a2d0adf5e86c
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=4ebde46520657ac90303fd3d61b0a2d0adf5e86c

Author: Gerd von Egidy <gerd at egidy.de>
Date:   Sun May 18 23:14:30 2014 +0200

Move code preparing dirs and permissions to icinga2-prepare-dirs, use this for SysV-Init and systemd.

Refs #4794

Conflicts:
	etc/initsystem/icinga2.init.d.cmake

---

 etc/CMakeLists.txt                   |   19 +++++++++++--------
 etc/initsystem/icinga2-prepare-dirs  |   33 +++++++++++++++++++++++++++++++++
 etc/initsystem/icinga2.init.d.cmake  |   30 +++++-------------------------
 etc/initsystem/icinga2.service.cmake |    2 +-
 4 files changed, 50 insertions(+), 34 deletions(-)

diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt
index 7f87ba7..949da3a 100644
--- a/etc/CMakeLists.txt
+++ b/etc/CMakeLists.txt
@@ -76,15 +76,18 @@ else()
 endif()
 
 if(NOT WIN32)
-    configure_file(icinga2/sysdefines.conf.cmake ${CMAKE_CURRENT_BINARY_DIR}/icinga2/sysdefines.conf @ONLY)
-    install(
-      FILES ${CMAKE_CURRENT_BINARY_DIR}/icinga2/sysdefines.conf
-      DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/icinga2
-      PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
-    )
-endif()
+  configure_file(icinga2/sysdefines.conf.cmake ${CMAKE_CURRENT_BINARY_DIR}/icinga2/sysdefines.conf @ONLY)
+  install(
+    FILES ${CMAKE_CURRENT_BINARY_DIR}/icinga2/sysdefines.conf
+    DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/icinga2
+    PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+  )
 
-if(NOT WIN32)
+  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) 
diff --git a/etc/initsystem/icinga2-prepare-dirs b/etc/initsystem/icinga2-prepare-dirs
new file mode 100644
index 0000000..a0c1891
--- /dev/null
+++ b/etc/initsystem/icinga2-prepare-dirs
@@ -0,0 +1,33 @@
+#!/bin/sh
+#
+# This script prepares directories and files needed for running Icinga2
+#
+
+# load system specific defines
+SYSDEFFILE=$1
+if [ -f "$SYSDEFFILE" ]; then
+	. $SYSDEFFILE
+else
+	echo "Error: You need to supply the path to the Icinga2 sysdefines.conf 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
diff --git a/etc/initsystem/icinga2.init.d.cmake b/etc/initsystem/icinga2.init.d.cmake
index 99b41ee..50de2bf 100644
--- a/etc/initsystem/icinga2.init.d.cmake
+++ b/etc/initsystem/icinga2.init.d.cmake
@@ -16,10 +16,11 @@
 ### END INIT INFO
 
 # load system specific defines
-if [ -f @CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/sysdefines.conf ]; then
-	. @CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/sysdefines.conf
+SYSDEFFILE=@CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/sysdefines.conf
+if [ -f $SYSDEFFILE ]; then
+	. $SYSDEFFILE
 else
-	echo "Can't load system specific defines from @CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/sysdefines.conf."
+	echo "Can't load system specific defines from $SYSDEFFILE."
 	exit 1
 fi
 
@@ -45,31 +46,10 @@ 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() {
 	printf "Starting Icinga 2: "
+	@CMAKE_INSTALL_FULL_SBINDIR@/icinga2-prepare-dirs $SYSDEFFILE
 
 	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."
diff --git a/etc/initsystem/icinga2.service.cmake b/etc/initsystem/icinga2.service.cmake
index fb049f7..deac375 100644
--- a/etc/initsystem/icinga2.service.cmake
+++ b/etc/initsystem/icinga2.service.cmake
@@ -5,7 +5,7 @@ After=syslog.target postgresql.service mariadb.service
 [Service]
 Type=forking
 EnvironmentFile=@CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/sysdefines.conf
-# ExecStartPre=  TODO: execute the mkdir & chown/chmod stuff, ideally in a separate script, used by both init.d and systemd
+ExecStartPre=@CMAKE_INSTALL_FULL_SBINDIR@/icinga2-prepare-dirs @CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/sysdefines.conf
 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



More information about the icinga-checkins mailing list