]> granicus.if.org Git - icinga2/commitdiff
Set rlimits in the Application class (rather than in the init script).
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 5 Dec 2013 10:04:47 +0000 (11:04 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 5 Dec 2013 10:11:03 +0000 (11:11 +0100)
Fixes #5260

etc/init.d/icinga2.cmake
icinga-app/icinga.cpp
lib/base/application.cpp
lib/base/application.h
lib/base/unix.h

index 6f9c93349c00d0770bea17e5e099a0ab921aa9ff..d70d0f9cc5bb6bb6a9b60f40b0064799bd753dff 100644 (file)
@@ -65,9 +65,6 @@ start() {
         fi
 
         echo "Starting Icinga 2: "
-        ulimit -n 32768
-       ulimit -s 512
-       ulimit -u 16384
         $DAEMON -c $ICINGA2_CONFIG_FILE -d -e $ICINGA2_ERROR_LOG -u $ICINGA2_USER -g $ICINGA2_GROUP
 
         echo "Done"
index f41db959d0a90ecf75a77364071154ea076af3ce..01313ead6294a2b4f36e654248b00a4e525feb5e 100644 (file)
@@ -187,6 +187,8 @@ int main(int argc, char **argv)
 {
        Application::SetStartTime(Utility::GetTime());
 
+       Application::SetResourceLimits();
+
        /* Set thread title. */
        Utility::SetThreadName("Main Thread", false);
 
index 7a8564875af66f6d9d764cd27f0af444474de99e..a18e35aa13a6587d015448c4cad5048a11cc36d8 100644 (file)
@@ -112,6 +112,32 @@ Application::Ptr Application::GetInstance(void)
        return m_Instance->GetSelf();
 }
 
+void Application::SetResourceLimits(void)
+{
+#ifndef _WIN32
+#      ifdef RLIMIT_NOFILE
+       rlimit rl;
+       rl.rlim_cur = 16 * 1024;
+       rl.rlim_max = rl.rlim_cur;
+
+       if (setrlimit(RLIMIT_NOFILE, &rl) < 0)
+               Log(LogCritical, "base", "Could not adjust resource limit for open file handles (RLIMIT_NOFILE)");
+#      else /* RLIMIT_NOFILE */
+       Log(LogCritical, "base", "System does not support adjusting the resource limit for open file handles (RLIMIT_NOFILE)");
+#      endif /* RLIMIT_NOFILE */
+
+#      ifdef RLIMIT_NPROC
+       rl.rlim_cur = 16 * 1024;
+       rl.rlim_max = rl.rlim_cur;
+
+       if (setrlimit(RLIMIT_NPROC, &rl) < 0)
+               Log(LogCritical, "base", "Could not adjust resource limit for number of processes (RLIMIT_NPROC)");
+#      else /* RLIMIT_NPROC */
+       Log(LogCritical, "base", "System does not support adjusting the resource limit for number of processes (RLIMIT_NPROC)");
+#      endif /* RLIMIT_NPROC */
+#endif /* _WIN32 */
+}
+
 int Application::GetArgC(void)
 {
        return m_ArgC;
index 583980c3559e2301289839ea82c9f1139e7a7a01..1c61aa35a2bc2c840f561977c5c006b20a110da4 100644 (file)
@@ -51,6 +51,8 @@ public:
         */
        virtual int Main(void) = 0;
 
+       static void SetResourceLimits(void);
+
        static int GetArgC(void);
        static void SetArgC(int argc);
 
index 0f6cf9a12383ea040c8c4564ef10426d2d62c566..03be340e66d76d727dabb368bbc3983a2ea78c46 100644 (file)
@@ -39,6 +39,8 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <dirent.h>
+#include <sys/time.h>
+#include <sys/resource.h>
 
 typedef int SOCKET;
 #define INVALID_SOCKET (-1)