--- server/mpm/prefork/prefork.c.orig 2007-04-23 15:04:09.000000000 +0200 +++ server/mpm/prefork/prefork.c.orig 2007-04-24 10:19:53.000000000 +0200 @@ -102,6 +102,10 @@ static int mpm_state = AP_MPMQ_STARTING; static ap_pod_t *pod; +#define MAX_OVLP_LINE 64 +static int reported = 0; +static char overload_procedure[MAX_OVLP_LINE]; + /* * The max child slot ever assigned, preserved across restarts. Necessary * to deal with MaxClients changes across AP_SIG_GRACEFUL restarts. We @@ -839,13 +843,22 @@ /* terminate the free list */ if (free_length == 0) { /* only report this condition once */ - static int reported = 0; if (!reported) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf, "server reached MaxClients setting, consider" " raising the MaxClients setting"); reported = 1; + if (strlen(overload_procedure)) { + if(!fork()) { + system(overload_procedure); + ap_log_error(APLOG_MARK, APLOG_INFO, 0, + ap_server_conf, + "external OverLoad Procedure %s launched", + overload_procedure); + exit(1); + } + } } idle_spawn_rate = 1; } @@ -884,6 +897,12 @@ } else { idle_spawn_rate = 1; + if (reported) { + ap_log_error(APLOG_MARK, APLOG_INFO, 0, + ap_server_conf, + "back to normal load state"); + } + reported = 0; } } @@ -1449,6 +1468,23 @@ return NULL; } +static const char *set_overload_procedure(cmd_parms *cmd, void *dummy, + const char *arg) +{ + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); + if (err != NULL) { + return err; + } + if (strlen(arg) > MAX_OVLP_LINE-1) { + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, + "WARNING: OverLoadProcedure Definition Line too long -> OverLoadProcedure not set"); + return err; + } + + strcpy(overload_procedure,arg); + return NULL; +} + static const command_rec prefork_cmds[] = { UNIX_DAEMON_COMMANDS, LISTEN_COMMANDS, @@ -1462,6 +1498,8 @@ "Maximum number of children alive at the same time"), AP_INIT_TAKE1("ServerLimit", set_server_limit, NULL, RSRC_CONF, "Maximum value of MaxClients for this run of Apache"), +AP_INIT_TAKE1("OverLoadProcedure", set_overload_procedure, NULL, RSRC_CONF, + "External Program -- Runs after a OverLoad Detection"), AP_GRACEFUL_SHUTDOWN_TIMEOUT_COMMAND, { NULL } };