Set rlimits in the Application class (rather than in the init script).

Fixes #5260
This commit is contained in:
Gunnar Beutner 2013-12-05 11:04:47 +01:00
parent 02e0933e7c
commit 6714796ecd
5 changed files with 32 additions and 3 deletions

View 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"

View 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);

View 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;

View File

@ -51,6 +51,8 @@ public:
*/
virtual int Main(void) = 0;
static void SetResourceLimits(void);
static int GetArgC(void);
static void SetArgC(int argc);

View 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)