#define ICINGA_INCLUDECONFDIR "${CMAKE_INSTALL_FULL_DATADIR}/icinga2/include"
#define ICINGA_USER "${ICINGA2_USER}"
#define ICINGA_GROUP "${ICINGA2_GROUP}"
-
+#define ICINGA_SYSCONFIGFILE "${ICINGA2_SYSCONFIGFILE}"
#define ICINGA_BUILD_HOST_NAME "${ICINGA2_BUILD_HOST_NAME}"
#define ICINGA_BUILD_COMPILER_NAME "${ICINGA2_BUILD_COMPILER_NAME}"
#define ICINGA_BUILD_COMPILER_VERSION "${ICINGA2_BUILD_COMPILER_VERSION}"
* configuration file (icinga2.conf) is processed.
*/
-const RunAsUser = "@ICINGA2_USER@"
-const RunAsGroup = "@ICINGA2_GROUP@"
#endif /* _WIN32 */
Application::DeclarePrefixDir(ICINGA_PREFIX);
+ Application::DeclareSysconfigFile(ICINGA_SYSCONFIGFILE);
Application::DeclareSysconfDir(ICINGA_SYSCONFDIR);
Application::DeclareRunDir(ICINGA_RUNDIR);
Application::DeclareLocalStateDir(ICINGA_LOCALSTATEDIR);
#endif /* _WIN32 */
Application::DeclareZonesDir(Application::GetSysconfDir() + "/icinga2/zones.d");
- Application::DeclareRunAsUser(ICINGA_USER);
- Application::DeclareRunAsGroup(ICINGA_GROUP);
+
+ String icinga_user = Utility::GetFromSysconfig("ICINGA2_USER");
+ if (icinga_user.IsEmpty())
+ icinga_user = ICINGA_USER;
+
+ String icinga_group = Utility::GetFromSysconfig("ICINGA2_GROUP");
+ if (icinga_group.IsEmpty())
+ icinga_group = ICINGA_GROUP;
+
+ Application::DeclareRunAsUser(icinga_user);
+ Application::DeclareRunAsGroup(icinga_group);
#ifdef __linux__
Application::DeclareRLimitFiles(Application::GetDefaultRLimitFiles());
Application::DeclareRLimitProcesses(Application::GetDefaultRLimitProcesses());
ScriptGlobal::Set("StatePath", path);
}
+/**
+ * Retrives the path of the sysconfig file.
+ *
+ * @returns The path.
+ */
+String Application::GetSysconfigFile(void)
+{
+ return ScriptGlobal::Get("SysconfigFile");
+}
+
+/**
+ * Sets the path of the sysconfig file.
+ *
+ * @param path The new path.
+ */
+void Application::DeclareSysconfigFile(const String& path)
+{
+ if (!ScriptGlobal::Exists("SysconfigFile"))
+ ScriptGlobal::Set("SysconfigFile", path);
+}
+
/**
* Retrieves the path for the modified attributes file.
*
static String GetIncludeConfDir();
static void DeclareIncludeConfDir(const String& path);
- static String GetStatePath();
+ static String GetSysconfigFile(void);
+ static void DeclareSysconfigFile(const String& path);
+
+ static String GetStatePath(void);
static void DeclareStatePath(const String& path);
static String GetModAttrPath();
}
#endif /* _WIN32 */
+
+String Utility::GetFromSysconfig(const String& env)
+{
+#ifndef _WIN32
+ String sysconf = Application::GetSysconfigFile();
+ if (sysconf.IsEmpty())
+ return "";
+
+ String cmdInner = ". " + EscapeShellArg(sysconf) + " 2>&1 >/dev/null;echo \"$" + env + "\"";
+ String cmd = "sh -c " + EscapeShellArg(cmdInner);
+
+ FILE *fp = popen(cmd.CStr(), "r");
+
+ if (!fp)
+ return "";
+
+ char line[1024];
+ String out;
+
+ if (fgets(line, sizeof(line), fp))
+ out = line;
+ else
+ return "";
+
+ pclose(fp);
+
+ return out.Trim();
+#else
+ //TODO: Figure out how to do this on windows
+ return "";
+#endif /* _WIN32 */
+}
static String GetIcingaDataPath();
#endif /* _WIN32 */
+ static String GetFromSysconfig(const String& env);
+
#ifdef I2_DEBUG
static void SetTime(double);
static void IncrementTime(double);