mirror of
				https://github.com/Icinga/icinga2.git
				synced 2025-11-03 21:25:56 +01:00 
			
		
		
		
	Merge pull request #6241 from Icinga/fix/sysconfig-location-ignored
Fix Sysconfig file detection for Icinga 2 settings
This commit is contained in:
		
						commit
						3c4085b1bb
					
				@ -57,6 +57,11 @@ set(ICINGA2_GIT_VERSION_INFO ON CACHE BOOL "Whether to use git describe")
 | 
				
			|||||||
set(ICINGA2_UNITY_BUILD ON CACHE BOOL "Whether to perform a unity build")
 | 
					set(ICINGA2_UNITY_BUILD ON CACHE BOOL "Whether to perform a unity build")
 | 
				
			||||||
set(ICINGA2_LTO_BUILD OFF CACHE BOOL "Whether to use LTO")
 | 
					set(ICINGA2_LTO_BUILD OFF CACHE BOOL "Whether to use LTO")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(NOT WIN32)
 | 
				
			||||||
 | 
					  set(ICINGA2_SYSCONFIGFILE "${CMAKE_INSTALL_FULL_SYSCONFDIR}/sysconfig/icinga2" CACHE PATH "where to store configuation for the init system, defaults to /etc/sysconfig/icinga2")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					endif()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
site_name(ICINGA2_BUILD_HOST_NAME)
 | 
					site_name(ICINGA2_BUILD_HOST_NAME)
 | 
				
			||||||
set(ICINGA2_BUILD_COMPILER_NAME "${CMAKE_CXX_COMPILER_ID}")
 | 
					set(ICINGA2_BUILD_COMPILER_NAME "${CMAKE_CXX_COMPILER_ID}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -16,8 +16,6 @@
 | 
				
			|||||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 | 
					# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if(NOT WIN32)
 | 
					if(NOT WIN32)
 | 
				
			||||||
  set(ICINGA2_SYSCONFIGFILE "${CMAKE_INSTALL_FULL_SYSCONFDIR}/sysconfig/icinga2" CACHE PATH "where to store configuation for the init system, defaults to /etc/sysconfig/icinga2")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  configure_file(icinga2.sysconfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/initsystem/icinga2.sysconfig @ONLY)
 | 
					  configure_file(icinga2.sysconfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/initsystem/icinga2.sysconfig @ONLY)
 | 
				
			||||||
  get_filename_component(ICINGA2_SYSCONFIGFILE_NAME ${ICINGA2_SYSCONFIGFILE} NAME)
 | 
					  get_filename_component(ICINGA2_SYSCONFIGFILE_NAME ${ICINGA2_SYSCONFIGFILE} NAME)
 | 
				
			||||||
  get_filename_component(ICINGA2_SYSCONFIGFILE_DIR ${ICINGA2_SYSCONFIGFILE} PATH)
 | 
					  get_filename_component(ICINGA2_SYSCONFIGFILE_DIR ${ICINGA2_SYSCONFIGFILE} PATH)
 | 
				
			||||||
 | 
				
			|||||||
@ -155,6 +155,13 @@ static int Main()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	Application::DeclareZonesDir(Application::GetSysconfDir() + "/icinga2/zones.d");
 | 
						Application::DeclareZonesDir(Application::GetSysconfDir() + "/icinga2/zones.d");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef _WIN32
 | 
				
			||||||
 | 
						if (!Utility::PathExists(Application::GetSysconfigFile())) {
 | 
				
			||||||
 | 
							Log(LogWarning, "icinga-app")
 | 
				
			||||||
 | 
								<< "Sysconfig file '" << Application::GetSysconfigFile() << "' cannot be read. Using default values.";
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					#endif /* _WIN32 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	String icingaUser = Utility::GetFromSysconfig("ICINGA2_USER");
 | 
						String icingaUser = Utility::GetFromSysconfig("ICINGA2_USER");
 | 
				
			||||||
	if (icingaUser.IsEmpty())
 | 
						if (icingaUser.IsEmpty())
 | 
				
			||||||
		icingaUser = ICINGA_USER;
 | 
							icingaUser = ICINGA_USER;
 | 
				
			||||||
@ -456,6 +463,7 @@ static int Main()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			std::cout << visibleDesc << std::endl
 | 
								std::cout << visibleDesc << std::endl
 | 
				
			||||||
				<< "Report bugs at <https://github.com/Icinga/icinga2>" << std::endl
 | 
									<< "Report bugs at <https://github.com/Icinga/icinga2>" << std::endl
 | 
				
			||||||
 | 
									<< "Get support: <https://www.icinga.com/support/>" << std::endl
 | 
				
			||||||
				<< "Icinga home page: <https://www.icinga.com/>" << std::endl;
 | 
									<< "Icinga home page: <https://www.icinga.com/>" << std::endl;
 | 
				
			||||||
			return EXIT_SUCCESS;
 | 
								return EXIT_SUCCESS;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -178,7 +178,8 @@ void Application::SetResourceLimits()
 | 
				
			|||||||
		rl.rlim_max = rl.rlim_cur;
 | 
							rl.rlim_max = rl.rlim_cur;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (setrlimit(RLIMIT_NOFILE, &rl) < 0)
 | 
							if (setrlimit(RLIMIT_NOFILE, &rl) < 0)
 | 
				
			||||||
			Log(LogNotice, "Application", "Could not adjust resource limit for open file handles (RLIMIT_NOFILE)");
 | 
								Log(LogWarning, "Application")
 | 
				
			||||||
 | 
								    << "Failed adjust resource limit for open file handles (RLIMIT_NOFILE) with error \"" << strerror(errno) << "\"";
 | 
				
			||||||
#	else /* RLIMIT_NOFILE */
 | 
					#	else /* RLIMIT_NOFILE */
 | 
				
			||||||
		Log(LogNotice, "Application", "System does not support adjusting the resource limit for open file handles (RLIMIT_NOFILE)");
 | 
							Log(LogNotice, "Application", "System does not support adjusting the resource limit for open file handles (RLIMIT_NOFILE)");
 | 
				
			||||||
#	endif /* RLIMIT_NOFILE */
 | 
					#	endif /* RLIMIT_NOFILE */
 | 
				
			||||||
@ -198,7 +199,8 @@ void Application::SetResourceLimits()
 | 
				
			|||||||
		rl.rlim_max = rl.rlim_cur;
 | 
							rl.rlim_max = rl.rlim_cur;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (setrlimit(RLIMIT_NPROC, &rl) < 0)
 | 
							if (setrlimit(RLIMIT_NPROC, &rl) < 0)
 | 
				
			||||||
			Log(LogNotice, "Application", "Could not adjust resource limit for number of processes (RLIMIT_NPROC)");
 | 
								Log(LogWarning, "Application")
 | 
				
			||||||
 | 
								    << "Failed adjust resource limit for number of processes (RLIMIT_NPROC) with error \"" << strerror(errno) << "\"";
 | 
				
			||||||
#	else /* RLIMIT_NPROC */
 | 
					#	else /* RLIMIT_NPROC */
 | 
				
			||||||
		Log(LogNotice, "Application", "System does not support adjusting the resource limit for number of processes (RLIMIT_NPROC)");
 | 
							Log(LogNotice, "Application", "System does not support adjusting the resource limit for number of processes (RLIMIT_NPROC)");
 | 
				
			||||||
#	endif /* RLIMIT_NPROC */
 | 
					#	endif /* RLIMIT_NPROC */
 | 
				
			||||||
@ -238,7 +240,8 @@ void Application::SetResourceLimits()
 | 
				
			|||||||
			rl.rlim_cur = rl.rlim_max;
 | 
								rl.rlim_cur = rl.rlim_max;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (setrlimit(RLIMIT_STACK, &rl) < 0) {
 | 
							if (setrlimit(RLIMIT_STACK, &rl) < 0) {
 | 
				
			||||||
			Log(LogNotice, "Application", "Could not adjust resource limit for stack size (RLIMIT_STACK)");
 | 
								Log(LogWarning, "Application")
 | 
				
			||||||
 | 
								    << "Failed adjust resource limit for stack size (RLIMIT_STACK) with error \"" << strerror(errno) << "\"";
 | 
				
			||||||
			if (set_stack_rlimit) {
 | 
								if (set_stack_rlimit) {
 | 
				
			||||||
				char **new_argv = static_cast<char **>(malloc(sizeof(char *) * (argc + 2)));
 | 
									char **new_argv = static_cast<char **>(malloc(sizeof(char *) * (argc + 2)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1943,6 +1943,9 @@ String Utility::GetFromSysconfig(const String& env)
 | 
				
			|||||||
	if (sysconf.IsEmpty())
 | 
						if (sysconf.IsEmpty())
 | 
				
			||||||
		return "";
 | 
							return "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!Utility::PathExists(sysconf))
 | 
				
			||||||
 | 
							return "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	String cmdInner = ". " + EscapeShellArg(sysconf) + " 2>&1 >/dev/null;echo \"$" + env + "\"";
 | 
						String cmdInner = ". " + EscapeShellArg(sysconf) + " 2>&1 >/dev/null;echo \"$" + env + "\"";
 | 
				
			||||||
	String cmd = "sh -c " + EscapeShellArg(cmdInner);
 | 
						String cmd = "sh -c " + EscapeShellArg(cmdInner);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user