Added master rlimit_files and rlimit_core in the global configuration settings

This commit is contained in:
Jérôme Loyet 2011-06-18 16:27:48 +00:00
parent eefbc4398a
commit 886cf1a318
4 changed files with 48 additions and 11 deletions

View File

@ -63,13 +63,15 @@ static char *ini_include = NULL;
#define WPO(field) offsetof(struct fpm_worker_pool_config_s, field)
static struct ini_value_parser_s ini_fpm_global_options[] = {
{ "emergency_restart_threshold", &fpm_conf_set_integer, GO(emergency_restart_threshold) },
{ "emergency_restart_interval", &fpm_conf_set_time, GO(emergency_restart_interval) },
{ "process_control_timeout", &fpm_conf_set_time, GO(process_control_timeout) },
{ "daemonize", &fpm_conf_set_boolean, GO(daemonize) },
{ "pid", &fpm_conf_set_string, GO(pid_file) },
{ "error_log", &fpm_conf_set_string, GO(error_log) },
{ "emergency_restart_threshold", &fpm_conf_set_integer, GO(emergency_restart_threshold) },
{ "emergency_restart_interval", &fpm_conf_set_time, GO(emergency_restart_interval) },
{ "process_control_timeout", &fpm_conf_set_time, GO(process_control_timeout) },
{ "daemonize", &fpm_conf_set_boolean, GO(daemonize) },
{ "pid", &fpm_conf_set_string, GO(pid_file) },
{ "error_log", &fpm_conf_set_string, GO(error_log) },
{ "log_level", &fpm_conf_set_log_level, 0 },
{ "rlimit_files", &fpm_conf_set_integer, GO(rlimit_files) },
{ "rlimit_core", &fpm_conf_set_rlimit_core,GO(rlimit_core) },
{ 0, 0, 0 }
};
@ -255,10 +257,10 @@ static char *fpm_conf_set_log_level(zval *value, void **config, intptr_t offset)
static char *fpm_conf_set_rlimit_core(zval *value, void **config, intptr_t offset) /* {{{ */
{
char *val = Z_STRVAL_P(value);
struct fpm_worker_pool_config_s *c = *config;
int *ptr = (int *) ((char *) *config + offset);
if (!strcasecmp(val, "unlimited")) {
c->rlimit_core = -1;
*ptr = -1;
} else {
int int_value;
void *subconf = &int_value;
@ -274,7 +276,7 @@ static char *fpm_conf_set_rlimit_core(zval *value, void **config, intptr_t offse
return "must be greater than zero or 'unlimited'";
}
c->rlimit_core = int_value;
*ptr = int_value;
}
return NULL;
@ -1117,6 +1119,8 @@ static void fpm_conf_dump() /* {{{ */
zlog(ZLOG_NOTICE, "\tprocess_control_timeout = %ds", fpm_global_config.process_control_timeout);
zlog(ZLOG_NOTICE, "\temergency_restart_interval = %ds", fpm_global_config.emergency_restart_interval);
zlog(ZLOG_NOTICE, "\temergency_restart_threshold = %d", fpm_global_config.emergency_restart_threshold);
zlog(ZLOG_NOTICE, "\trlimit_files = %d", fpm_global_config.rlimit_files);
zlog(ZLOG_NOTICE, "\trlimit_core = %d", fpm_global_config.rlimit_core);
zlog(ZLOG_NOTICE, " ");
for (wp = fpm_worker_all_pools; wp; wp = wp->next) {

View File

@ -29,6 +29,8 @@ struct fpm_global_config_s {
int daemonize;
char *pid_file;
char *error_log;
int rlimit_files;
int rlimit_core;
};
extern struct fpm_global_config_s fpm_global_config;

View File

@ -153,7 +153,7 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
r.rlim_max = r.rlim_cur = (rlim_t) wp->config->rlimit_files;
if (0 > setrlimit(RLIMIT_NOFILE, &r)) {
zlog(ZLOG_SYSERROR, "[pool %s] setrlimit(RLIMIT_NOFILE, %d) failed (%d)", wp->config->name, wp->config->rlimit_files, errno);
zlog(ZLOG_SYSERROR, "[pool %s] unable to set rlimit_files for this pool. Please check your system limits or decrease rlimit_files. setrlimit(RLIMIT_NOFILE, %d) failed (%d)", wp->config->name, wp->config->rlimit_files, errno);
}
}
@ -163,7 +163,7 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
r.rlim_max = r.rlim_cur = wp->config->rlimit_core == -1 ? (rlim_t) RLIM_INFINITY : (rlim_t) wp->config->rlimit_core;
if (0 > setrlimit(RLIMIT_CORE, &r)) {
zlog(ZLOG_SYSERROR, "[pool %s] setrlimit(RLIMIT_CORE, %d) failed (%d)", wp->config->name, wp->config->rlimit_core, errno);
zlog(ZLOG_SYSERROR, "[pool %s] unable to set rlimit_core for this pool. Please check your system limits or decrease rlimit_core. setrlimit(RLIMIT_CORE, %d) failed (%d)", wp->config->name, wp->config->rlimit_core, errno);
}
}
@ -220,6 +220,28 @@ int fpm_unix_init_main() /* {{{ */
{
struct fpm_worker_pool_s *wp;
if (fpm_global_config.rlimit_files) {
struct rlimit r;
r.rlim_max = r.rlim_cur = (rlim_t) fpm_global_config.rlimit_files;
if (0 > setrlimit(RLIMIT_NOFILE, &r)) {
zlog(ZLOG_SYSERROR, "unable to set rlimit_core for this pool. Please check your system limits or decrease rlimit_files. setrlimit(RLIMIT_NOFILE, %d) failed (%d)", fpm_global_config.rlimit_files, errno);
return -1;
}
}
if (fpm_global_config.rlimit_core) {
struct rlimit r;
r.rlim_max = r.rlim_cur = fpm_global_config.rlimit_core == -1 ? (rlim_t) RLIM_INFINITY : (rlim_t) fpm_global_config.rlimit_core;
if (0 > setrlimit(RLIMIT_CORE, &r)) {
zlog(ZLOG_SYSERROR, "unable to set rlimit_core for this pool. Please check your system limits or decrease rlimit_core. setrlimit(RLIMIT_CORE, %d) failed (%d)", fpm_global_config.rlimit_core, errno);
return -1;
}
}
fpm_pagesize = getpagesize();
if (fpm_global_config.daemonize) {
switch (fork()) {

View File

@ -57,6 +57,15 @@
; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
; Default Value: yes
;daemonize = yes
; Set open file descriptor rlimit for the master process.
; Default Value: system defined value
;rlimit_files = 1024
; Set max core size rlimit for the master process.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
;rlimit_core = 0
;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;