mirror of
				https://github.com/Icinga/icinga2.git
				synced 2025-10-30 18:53:54 +01:00 
			
		
		
		
	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
This commit is contained in:
		
							parent
							
								
									ef49658474
								
							
						
					
					
						commit
						4ebde46520
					
				| @ -76,15 +76,18 @@ else() | |||||||
| endif() | endif() | ||||||
| 
 | 
 | ||||||
| if(NOT WIN32) | if(NOT WIN32) | ||||||
|     configure_file(icinga2/sysdefines.conf.cmake ${CMAKE_CURRENT_BINARY_DIR}/icinga2/sysdefines.conf @ONLY) |   configure_file(icinga2/sysdefines.conf.cmake ${CMAKE_CURRENT_BINARY_DIR}/icinga2/sysdefines.conf @ONLY) | ||||||
|     install( |   install( | ||||||
|       FILES ${CMAKE_CURRENT_BINARY_DIR}/icinga2/sysdefines.conf |     FILES ${CMAKE_CURRENT_BINARY_DIR}/icinga2/sysdefines.conf | ||||||
|       DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/icinga2 |     DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/icinga2 | ||||||
|       PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ |     PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ | ||||||
|     ) |   ) | ||||||
| endif() |  | ||||||
| 
 | 
 | ||||||
| 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 |   option (USE_SYSTEMD | ||||||
|      "Configure icinga as native systemd service instead of a SysV initscript" OFF)  |      "Configure icinga as native systemd service instead of a SysV initscript" OFF)  | ||||||
|  | |||||||
							
								
								
									
										33
									
								
								etc/initsystem/icinga2-prepare-dirs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								etc/initsystem/icinga2-prepare-dirs
									
									
									
									
									
										Normal file
									
								
							| @ -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 | ||||||
| @ -16,10 +16,11 @@ | |||||||
| ### END INIT INFO | ### END INIT INFO | ||||||
| 
 | 
 | ||||||
| # load system specific defines | # load system specific defines | ||||||
| if [ -f @CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/sysdefines.conf ]; then | SYSDEFFILE=@CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/sysdefines.conf | ||||||
| 	. @CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/sysdefines.conf | if [ -f $SYSDEFFILE ]; then | ||||||
|  | 	. $SYSDEFFILE | ||||||
| else | 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 | 	exit 1 | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| @ -45,31 +46,10 @@ if [ -f /etc/default/icinga ]; then | |||||||
|         . /etc/default/icinga |         . /etc/default/icinga | ||||||
| fi | 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 $SYSDEFFILE | ||||||
| 
 | 
 | ||||||
| 	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." | ||||||
|  | |||||||
| @ -5,7 +5,7 @@ After=syslog.target postgresql.service mariadb.service | |||||||
| [Service] | [Service] | ||||||
| Type=forking | Type=forking | ||||||
| EnvironmentFile=@CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/sysdefines.conf | 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} | 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 | PIDFile=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/run/icinga2/icinga2.pid | ||||||
| ExecReload=/bin/kill -HUP $MAINPID | ExecReload=/bin/kill -HUP $MAINPID | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user