|
Packit |
90a5c9 |
/* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
* contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
* this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
* (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
* the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
* See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
* limitations under the License.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Load balancer module for Apache proxy */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "mod_proxy.h"
|
|
Packit |
90a5c9 |
#include "scoreboard.h"
|
|
Packit |
90a5c9 |
#include "ap_mpm.h"
|
|
Packit |
90a5c9 |
#include "apr_version.h"
|
|
Packit |
90a5c9 |
#include "ap_hooks.h"
|
|
Packit |
90a5c9 |
#include "apr_date.h"
|
|
Packit |
90a5c9 |
#include "util_md5.h"
|
|
Packit |
90a5c9 |
#include "mod_watchdog.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *balancer_mutex_type = "proxy-balancer-shm";
|
|
Packit |
90a5c9 |
ap_slotmem_provider_t *storage = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
module AP_MODULE_DECLARE_DATA proxy_balancer_module;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static APR_OPTIONAL_FN_TYPE(set_worker_hc_param) *set_worker_hc_param_f = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int (*ap_proxy_retry_worker_fn)(const char *proxy_function,
|
|
Packit |
90a5c9 |
proxy_worker *worker, server_rec *s) = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static APR_OPTIONAL_FN_TYPE(hc_show_exprs) *hc_show_exprs_f = NULL;
|
|
Packit |
90a5c9 |
static APR_OPTIONAL_FN_TYPE(hc_select_exprs) *hc_select_exprs_f = NULL;
|
|
Packit |
90a5c9 |
static APR_OPTIONAL_FN_TYPE(hc_valid_expr) *hc_valid_expr_f = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Register our mutex type before the config is read so we
|
|
Packit |
90a5c9 |
* can adjust the mutex settings using the Mutex directive.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static int balancer_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rv = ap_mutex_register(pconf, balancer_mutex_type, NULL,
|
|
Packit |
90a5c9 |
APR_LOCK_DEFAULT, 0);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
set_worker_hc_param_f = APR_RETRIEVE_OPTIONAL_FN(set_worker_hc_param);
|
|
Packit |
90a5c9 |
hc_show_exprs_f = APR_RETRIEVE_OPTIONAL_FN(hc_show_exprs);
|
|
Packit |
90a5c9 |
hc_select_exprs_f = APR_RETRIEVE_OPTIONAL_FN(hc_select_exprs);
|
|
Packit |
90a5c9 |
hc_valid_expr_f = APR_RETRIEVE_OPTIONAL_FN(hc_valid_expr);
|
|
Packit |
90a5c9 |
return OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if 0
|
|
Packit |
90a5c9 |
extern void proxy_update_members(proxy_balancer **balancer, request_rec *r,
|
|
Packit |
90a5c9 |
proxy_server_conf *conf);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int proxy_balancer_canon(request_rec *r, char *url)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char *host, *path;
|
|
Packit |
90a5c9 |
char *search = NULL;
|
|
Packit |
90a5c9 |
const char *err;
|
|
Packit |
90a5c9 |
apr_port_t port = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* TODO: offset of BALANCER_PREFIX ?? */
|
|
Packit |
90a5c9 |
if (strncasecmp(url, "balancer:", 9) == 0) {
|
|
Packit |
90a5c9 |
url += 9;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
return DECLINED;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "canonicalising URL %s", url);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* do syntatic check.
|
|
Packit |
90a5c9 |
* We break the URL into host, port, path, search
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
|
|
Packit |
90a5c9 |
if (err) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01157)
|
|
Packit |
90a5c9 |
"error parsing URL %s: %s",
|
|
Packit |
90a5c9 |
url, err);
|
|
Packit |
90a5c9 |
return HTTP_BAD_REQUEST;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* now parse path/search args, according to rfc1738:
|
|
Packit |
90a5c9 |
* process the path. With proxy-noncanon set (by
|
|
Packit |
90a5c9 |
* mod_proxy) we use the raw, unparsed uri
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (apr_table_get(r->notes, "proxy-nocanon")) {
|
|
Packit |
90a5c9 |
path = url; /* this is the raw path */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
path = ap_proxy_canonenc(r->pool, url, strlen(url), enc_path, 0,
|
|
Packit |
90a5c9 |
r->proxyreq);
|
|
Packit |
90a5c9 |
search = r->args;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (path == NULL)
|
|
Packit |
90a5c9 |
return HTTP_BAD_REQUEST;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
r->filename = apr_pstrcat(r->pool, "proxy:" BALANCER_PREFIX, host,
|
|
Packit |
90a5c9 |
"/", path, (search) ? "?" : "", (search) ? search : "", NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
r->path_info = apr_pstrcat(r->pool, "/", path, NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void init_balancer_members(apr_pool_t *p, server_rec *s,
|
|
Packit |
90a5c9 |
proxy_balancer *balancer)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
proxy_worker **workers;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
workers = (proxy_worker **)balancer->workers->elts;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (i = 0; i < balancer->workers->nelts; i++) {
|
|
Packit |
90a5c9 |
int worker_is_initialized;
|
|
Packit |
90a5c9 |
proxy_worker *worker = *workers;
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01158)
|
|
Packit |
90a5c9 |
"Looking at %s -> %s initialized?", balancer->s->name,
|
|
Packit |
90a5c9 |
ap_proxy_worker_name(p, worker));
|
|
Packit |
90a5c9 |
worker_is_initialized = PROXY_WORKER_IS_INITIALIZED(worker);
|
|
Packit |
90a5c9 |
if (!worker_is_initialized) {
|
|
Packit |
90a5c9 |
ap_proxy_initialize_worker(worker, s, p);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
++workers;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Set default number of attempts to the number of
|
|
Packit |
90a5c9 |
* workers.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (!balancer->s->max_attempts_set && balancer->workers->nelts > 1) {
|
|
Packit |
90a5c9 |
balancer->s->max_attempts = balancer->workers->nelts - 1;
|
|
Packit |
90a5c9 |
balancer->s->max_attempts_set = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Retrieve the parameter with the given name
|
|
Packit |
90a5c9 |
* Something like 'JSESSIONID=12345...N'
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static char *get_path_param(apr_pool_t *pool, char *url,
|
|
Packit |
90a5c9 |
const char *name, int scolon_sep)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char *path = NULL;
|
|
Packit |
90a5c9 |
char *pathdelims = "?&";
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (scolon_sep) {
|
|
Packit |
90a5c9 |
pathdelims = ";?&";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
for (path = strstr(url, name); path; path = strstr(path + 1, name)) {
|
|
Packit |
90a5c9 |
path += strlen(name);
|
|
Packit |
90a5c9 |
if (*path == '=') {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Session path was found, get its value
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
++path;
|
|
Packit |
90a5c9 |
if (*path) {
|
|
Packit |
90a5c9 |
char *q;
|
|
Packit |
90a5c9 |
path = apr_strtok(apr_pstrdup(pool, path), pathdelims, &q);
|
|
Packit |
90a5c9 |
return path;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static char *get_cookie_param(request_rec *r, const char *name)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
const char *cookies;
|
|
Packit |
90a5c9 |
const char *start_cookie;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((cookies = apr_table_get(r->headers_in, "Cookie"))) {
|
|
Packit |
90a5c9 |
for (start_cookie = ap_strstr_c(cookies, name); start_cookie;
|
|
Packit |
90a5c9 |
start_cookie = ap_strstr_c(start_cookie + 1, name)) {
|
|
Packit |
90a5c9 |
if (start_cookie == cookies ||
|
|
Packit |
90a5c9 |
start_cookie[-1] == ';' ||
|
|
Packit |
90a5c9 |
start_cookie[-1] == ',' ||
|
|
Packit |
90a5c9 |
isspace(start_cookie[-1])) {
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
start_cookie += strlen(name);
|
|
Packit |
90a5c9 |
while(*start_cookie && isspace(*start_cookie))
|
|
Packit |
90a5c9 |
++start_cookie;
|
|
Packit |
90a5c9 |
if (*start_cookie++ == '=' && *start_cookie) {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Session cookie was found, get its value
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
char *end_cookie, *cookie;
|
|
Packit |
90a5c9 |
cookie = apr_pstrdup(r->pool, start_cookie);
|
|
Packit |
90a5c9 |
if ((end_cookie = strchr(cookie, ';')) != NULL)
|
|
Packit |
90a5c9 |
*end_cookie = '\0';
|
|
Packit |
90a5c9 |
if((end_cookie = strchr(cookie, ',')) != NULL)
|
|
Packit |
90a5c9 |
*end_cookie = '\0';
|
|
Packit |
90a5c9 |
return cookie;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Find the worker that has the 'route' defined
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static proxy_worker *find_route_worker(proxy_balancer *balancer,
|
|
Packit |
90a5c9 |
const char *route, request_rec *r,
|
|
Packit |
90a5c9 |
int recursion)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
int checking_standby;
|
|
Packit |
90a5c9 |
int checked_standby;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
proxy_worker **workers;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
checking_standby = checked_standby = 0;
|
|
Packit |
90a5c9 |
while (!checked_standby) {
|
|
Packit |
90a5c9 |
workers = (proxy_worker **)balancer->workers->elts;
|
|
Packit |
90a5c9 |
for (i = 0; i < balancer->workers->nelts; i++, workers++) {
|
|
Packit |
90a5c9 |
proxy_worker *worker = *workers;
|
|
Packit |
90a5c9 |
if ( (checking_standby ? !PROXY_WORKER_IS_STANDBY(worker) : PROXY_WORKER_IS_STANDBY(worker)) )
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
if (*(worker->s->route) && strcmp(worker->s->route, route) == 0) {
|
|
Packit |
90a5c9 |
if (PROXY_WORKER_IS_USABLE(worker)) {
|
|
Packit |
90a5c9 |
return worker;
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* If the worker is in error state run
|
|
Packit |
90a5c9 |
* retry on that worker. It will be marked as
|
|
Packit |
90a5c9 |
* operational if the retry timeout is elapsed.
|
|
Packit |
90a5c9 |
* The worker might still be unusable, but we try
|
|
Packit |
90a5c9 |
* anyway.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ap_proxy_retry_worker_fn("BALANCER", worker, r->server);
|
|
Packit |
90a5c9 |
if (PROXY_WORKER_IS_USABLE(worker)) {
|
|
Packit |
90a5c9 |
return worker;
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* We have a worker that is unusable.
|
|
Packit |
90a5c9 |
* It can be in error or disabled, but in case
|
|
Packit |
90a5c9 |
* it has a redirection set use that redirection worker.
|
|
Packit |
90a5c9 |
* This enables to safely remove the member from the
|
|
Packit |
90a5c9 |
* balancer. Of course you will need some kind of
|
|
Packit |
90a5c9 |
* session replication between those two remote.
|
|
Packit |
90a5c9 |
* Also check that we haven't gone thru all the
|
|
Packit |
90a5c9 |
* balancer members by means of redirects.
|
|
Packit |
90a5c9 |
* This should avoid redirect cycles.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if ((*worker->s->redirect)
|
|
Packit |
90a5c9 |
&& (recursion < balancer->workers->nelts)) {
|
|
Packit |
90a5c9 |
proxy_worker *rworker = NULL;
|
|
Packit |
90a5c9 |
rworker = find_route_worker(balancer, worker->s->redirect,
|
|
Packit |
90a5c9 |
r, recursion + 1);
|
|
Packit |
90a5c9 |
/* Check if the redirect worker is usable */
|
|
Packit |
90a5c9 |
if (rworker && !PROXY_WORKER_IS_USABLE(rworker)) {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* If the worker is in error state run
|
|
Packit |
90a5c9 |
* retry on that worker. It will be marked as
|
|
Packit |
90a5c9 |
* operational if the retry timeout is elapsed.
|
|
Packit |
90a5c9 |
* The worker might still be unusable, but we try
|
|
Packit |
90a5c9 |
* anyway.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ap_proxy_retry_worker_fn("BALANCER", rworker, r->server);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (rworker && PROXY_WORKER_IS_USABLE(rworker))
|
|
Packit |
90a5c9 |
return rworker;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
checked_standby = checking_standby++;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static proxy_worker *find_session_route(proxy_balancer *balancer,
|
|
Packit |
90a5c9 |
request_rec *r,
|
|
Packit |
90a5c9 |
char **route,
|
|
Packit |
90a5c9 |
const char **sticky_used,
|
|
Packit |
90a5c9 |
char **url)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
proxy_worker *worker = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!*balancer->s->sticky)
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
/* Try to find the sticky route inside url */
|
|
Packit |
90a5c9 |
*route = get_path_param(r->pool, *url, balancer->s->sticky_path, balancer->s->scolonsep);
|
|
Packit |
90a5c9 |
if (*route) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01159)
|
|
Packit |
90a5c9 |
"Found value %s for stickysession %s",
|
|
Packit |
90a5c9 |
*route, balancer->s->sticky_path);
|
|
Packit |
90a5c9 |
*sticky_used = balancer->s->sticky_path;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
*route = get_cookie_param(r, balancer->s->sticky);
|
|
Packit |
90a5c9 |
if (*route) {
|
|
Packit |
90a5c9 |
*sticky_used = balancer->s->sticky;
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01160)
|
|
Packit |
90a5c9 |
"Found value %s for stickysession %s",
|
|
Packit |
90a5c9 |
*route, balancer->s->sticky);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* If we found a value for stickysession, find the first '.' (or whatever
|
|
Packit |
90a5c9 |
* sticky_separator is set to) within. Everything after '.' (if present)
|
|
Packit |
90a5c9 |
* is our route.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if ((*route) && (balancer->s->sticky_separator != 0) && ((*route = strchr(*route, balancer->s->sticky_separator)) != NULL ))
|
|
Packit |
90a5c9 |
(*route)++;
|
|
Packit |
90a5c9 |
if ((*route) && (**route)) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01161) "Found route %s", *route);
|
|
Packit |
90a5c9 |
/* We have a route in path or in cookie
|
|
Packit |
90a5c9 |
* Find the worker that has this route defined.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
worker = find_route_worker(balancer, *route, r, 1);
|
|
Packit |
90a5c9 |
if (worker && strcmp(*route, worker->s->route)) {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Notice that the route of the worker chosen is different from
|
|
Packit |
90a5c9 |
* the route supplied by the client.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_table_setn(r->subprocess_env, "BALANCER_ROUTE_CHANGED", "1");
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01162)
|
|
Packit |
90a5c9 |
"Route changed from %s to %s",
|
|
Packit |
90a5c9 |
*route, worker->s->route);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return worker;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static proxy_worker *find_best_worker(proxy_balancer *balancer,
|
|
Packit |
90a5c9 |
request_rec *r)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
proxy_worker *candidate = NULL;
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01163)
|
|
Packit |
90a5c9 |
"%s: Lock failed for find_best_worker()",
|
|
Packit |
90a5c9 |
balancer->s->name);
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
candidate = (*balancer->lbmethod->finder)(balancer, r);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (candidate)
|
|
Packit |
90a5c9 |
candidate->s->elected++;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01164)
|
|
Packit |
90a5c9 |
"%s: Unlock failed for find_best_worker()",
|
|
Packit |
90a5c9 |
balancer->s->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (candidate == NULL) {
|
|
Packit |
90a5c9 |
/* All the workers are in error state or disabled.
|
|
Packit |
90a5c9 |
* If the balancer has a timeout sleep for a while
|
|
Packit |
90a5c9 |
* and try again to find the worker. The chances are
|
|
Packit |
90a5c9 |
* that some other thread will release a connection.
|
|
Packit |
90a5c9 |
* By default the timeout is not set, and the server
|
|
Packit |
90a5c9 |
* returns SERVER_BUSY.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (balancer->s->timeout) {
|
|
Packit |
90a5c9 |
/* XXX: This can perhaps be build using some
|
|
Packit |
90a5c9 |
* smarter mechanism, like tread_cond.
|
|
Packit |
90a5c9 |
* But since the statuses can came from
|
|
Packit |
90a5c9 |
* different childs, use the provided algo.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_interval_time_t timeout = balancer->s->timeout;
|
|
Packit |
90a5c9 |
apr_interval_time_t step, tval = 0;
|
|
Packit |
90a5c9 |
/* Set the timeout to 0 so that we don't
|
|
Packit |
90a5c9 |
* end in infinite loop
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
balancer->s->timeout = 0;
|
|
Packit |
90a5c9 |
step = timeout / 100;
|
|
Packit |
90a5c9 |
while (tval < timeout) {
|
|
Packit |
90a5c9 |
apr_sleep(step);
|
|
Packit |
90a5c9 |
/* Try again */
|
|
Packit |
90a5c9 |
if ((candidate = find_best_worker(balancer, r)))
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
tval += step;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* restore the timeout */
|
|
Packit |
90a5c9 |
balancer->s->timeout = timeout;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return candidate;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int rewrite_url(request_rec *r, proxy_worker *worker,
|
|
Packit |
90a5c9 |
char **url)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
const char *scheme = strstr(*url, "://");
|
|
Packit |
90a5c9 |
const char *path = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (scheme)
|
|
Packit |
90a5c9 |
path = ap_strchr_c(scheme + 3, '/');
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* we break the URL into host, port, uri */
|
|
Packit |
90a5c9 |
if (!worker) {
|
|
Packit |
90a5c9 |
return ap_proxyerror(r, HTTP_BAD_REQUEST, apr_pstrcat(r->pool,
|
|
Packit |
90a5c9 |
"missing worker. URI cannot be parsed: ", *url,
|
|
Packit |
90a5c9 |
NULL));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
*url = apr_pstrcat(r->pool, worker->s->name, path, NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void force_recovery(proxy_balancer *balancer, server_rec *s)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
int ok = 0;
|
|
Packit |
90a5c9 |
proxy_worker **worker;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
worker = (proxy_worker **)balancer->workers->elts;
|
|
Packit |
90a5c9 |
for (i = 0; i < balancer->workers->nelts; i++, worker++) {
|
|
Packit |
90a5c9 |
if (!((*worker)->s->status & PROXY_WORKER_IN_ERROR)) {
|
|
Packit |
90a5c9 |
ok = 1;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* Try if we can recover */
|
|
Packit |
90a5c9 |
ap_proxy_retry_worker_fn("BALANCER", *worker, s);
|
|
Packit |
90a5c9 |
if (!((*worker)->s->status & PROXY_WORKER_IN_ERROR)) {
|
|
Packit |
90a5c9 |
ok = 1;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!ok && balancer->s->forcerecovery) {
|
|
Packit |
90a5c9 |
/* If all workers are in error state force the recovery.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
worker = (proxy_worker **)balancer->workers->elts;
|
|
Packit |
90a5c9 |
for (i = 0; i < balancer->workers->nelts; i++, worker++) {
|
|
Packit |
90a5c9 |
++(*worker)->s->retries;
|
|
Packit |
90a5c9 |
(*worker)->s->status &= ~PROXY_WORKER_IN_ERROR;
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01165)
|
|
Packit |
90a5c9 |
"%s: Forcing recovery for worker (%s)",
|
|
Packit |
90a5c9 |
balancer->s->name, (*worker)->s->hostname_ex);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t decrement_busy_count(void *worker_)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
proxy_worker *worker = worker_;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (worker->s->busy) {
|
|
Packit |
90a5c9 |
worker->s->busy--;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int proxy_balancer_pre_request(proxy_worker **worker,
|
|
Packit |
90a5c9 |
proxy_balancer **balancer,
|
|
Packit |
90a5c9 |
request_rec *r,
|
|
Packit |
90a5c9 |
proxy_server_conf *conf, char **url)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int access_status;
|
|
Packit |
90a5c9 |
proxy_worker *runtime;
|
|
Packit |
90a5c9 |
char *route = NULL;
|
|
Packit |
90a5c9 |
const char *sticky = NULL;
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
*worker = NULL;
|
|
Packit |
90a5c9 |
/* Step 1: check if the url is for us
|
|
Packit |
90a5c9 |
* The url we can handle starts with 'balancer://'
|
|
Packit |
90a5c9 |
* If balancer is already provided skip the search
|
|
Packit |
90a5c9 |
* for balancer, because this is failover attempt.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (!*balancer &&
|
|
Packit |
90a5c9 |
!(*balancer = ap_proxy_get_balancer(r->pool, conf, *url, 1)))
|
|
Packit |
90a5c9 |
return DECLINED;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Step 2: Lock the LoadBalancer
|
|
Packit |
90a5c9 |
* XXX: perhaps we need the process lock here
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if ((rv = PROXY_THREAD_LOCK(*balancer)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01166)
|
|
Packit |
90a5c9 |
"%s: Lock failed for pre_request", (*balancer)->s->name);
|
|
Packit |
90a5c9 |
return DECLINED;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Step 3: force recovery */
|
|
Packit |
90a5c9 |
force_recovery(*balancer, r->server);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Step 3.5: Update member list for the balancer */
|
|
Packit |
90a5c9 |
/* TODO: Implement as provider! */
|
|
Packit |
90a5c9 |
ap_proxy_sync_balancer(*balancer, r->server, conf);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Step 4: find the session route */
|
|
Packit |
90a5c9 |
runtime = find_session_route(*balancer, r, &route, &sticky, url);
|
|
Packit |
90a5c9 |
if (runtime) {
|
|
Packit |
90a5c9 |
if ((*balancer)->lbmethod && (*balancer)->lbmethod->updatelbstatus) {
|
|
Packit |
90a5c9 |
/* Call the LB implementation */
|
|
Packit |
90a5c9 |
(*balancer)->lbmethod->updatelbstatus(*balancer, runtime, r->server);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else { /* Use the default one */
|
|
Packit |
90a5c9 |
int i, total_factor = 0;
|
|
Packit |
90a5c9 |
proxy_worker **workers;
|
|
Packit |
90a5c9 |
/* We have a sticky load balancer
|
|
Packit |
90a5c9 |
* Update the workers status
|
|
Packit |
90a5c9 |
* so that even session routes get
|
|
Packit |
90a5c9 |
* into account.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
workers = (proxy_worker **)(*balancer)->workers->elts;
|
|
Packit |
90a5c9 |
for (i = 0; i < (*balancer)->workers->nelts; i++) {
|
|
Packit |
90a5c9 |
/* Take into calculation only the workers that are
|
|
Packit |
90a5c9 |
* not in error state or not disabled.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (PROXY_WORKER_IS_USABLE(*workers)) {
|
|
Packit |
90a5c9 |
(*workers)->s->lbstatus += (*workers)->s->lbfactor;
|
|
Packit |
90a5c9 |
total_factor += (*workers)->s->lbfactor;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
workers++;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
runtime->s->lbstatus -= total_factor;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
runtime->s->elected++;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
*worker = runtime;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (route && (*balancer)->s->sticky_force) {
|
|
Packit |
90a5c9 |
int i, member_of = 0;
|
|
Packit |
90a5c9 |
proxy_worker **workers;
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* We have a route provided that doesn't match the
|
|
Packit |
90a5c9 |
* balancer name. See if the provider route is the
|
|
Packit |
90a5c9 |
* member of the same balancer in which case return 503
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
workers = (proxy_worker **)(*balancer)->workers->elts;
|
|
Packit |
90a5c9 |
for (i = 0; i < (*balancer)->workers->nelts; i++) {
|
|
Packit |
90a5c9 |
if (*((*workers)->s->route) && strcmp((*workers)->s->route, route) == 0) {
|
|
Packit |
90a5c9 |
member_of = 1;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
workers++;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (member_of) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01167)
|
|
Packit |
90a5c9 |
"%s: All workers are in error state for route (%s)",
|
|
Packit |
90a5c9 |
(*balancer)->s->name, route);
|
|
Packit |
90a5c9 |
if ((rv = PROXY_THREAD_UNLOCK(*balancer)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01168)
|
|
Packit |
90a5c9 |
"%s: Unlock failed for pre_request",
|
|
Packit |
90a5c9 |
(*balancer)->s->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return HTTP_SERVICE_UNAVAILABLE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((rv = PROXY_THREAD_UNLOCK(*balancer)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01169)
|
|
Packit |
90a5c9 |
"%s: Unlock failed for pre_request",
|
|
Packit |
90a5c9 |
(*balancer)->s->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!*worker) {
|
|
Packit |
90a5c9 |
runtime = find_best_worker(*balancer, r);
|
|
Packit |
90a5c9 |
if (!runtime) {
|
|
Packit |
90a5c9 |
if ((*balancer)->workers->nelts) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01170)
|
|
Packit |
90a5c9 |
"%s: All workers are in error state",
|
|
Packit |
90a5c9 |
(*balancer)->s->name);
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01171)
|
|
Packit |
90a5c9 |
"%s: No workers in balancer",
|
|
Packit |
90a5c9 |
(*balancer)->s->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return HTTP_SERVICE_UNAVAILABLE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (*(*balancer)->s->sticky && runtime) {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* This balancer has sticky sessions and the client either has not
|
|
Packit |
90a5c9 |
* supplied any routing information or all workers for this route
|
|
Packit |
90a5c9 |
* including possible redirect and hotstandby workers are in error
|
|
Packit |
90a5c9 |
* state, but we have found another working worker for this
|
|
Packit |
90a5c9 |
* balancer where we can send the request. Thus notice that we have
|
|
Packit |
90a5c9 |
* changed the route to the backend.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_table_setn(r->subprocess_env, "BALANCER_ROUTE_CHANGED", "1");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
*worker = runtime;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
(*worker)->s->busy++;
|
|
Packit |
90a5c9 |
apr_pool_cleanup_register(r->pool, *worker, decrement_busy_count,
|
|
Packit |
90a5c9 |
apr_pool_cleanup_null);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Add balancer/worker info to env. */
|
|
Packit |
90a5c9 |
apr_table_setn(r->subprocess_env,
|
|
Packit |
90a5c9 |
"BALANCER_NAME", (*balancer)->s->name);
|
|
Packit |
90a5c9 |
apr_table_setn(r->subprocess_env,
|
|
Packit |
90a5c9 |
"BALANCER_WORKER_NAME", (*worker)->s->name);
|
|
Packit |
90a5c9 |
apr_table_setn(r->subprocess_env,
|
|
Packit |
90a5c9 |
"BALANCER_WORKER_ROUTE", (*worker)->s->route);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Rewrite the url from 'balancer://url'
|
|
Packit |
90a5c9 |
* to the 'worker_scheme://worker_hostname[:worker_port]/url'
|
|
Packit |
90a5c9 |
* This replaces the balancers fictional name with the
|
|
Packit |
90a5c9 |
* real hostname of the elected worker.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
access_status = rewrite_url(r, *worker, url);
|
|
Packit |
90a5c9 |
/* Add the session route to request notes if present */
|
|
Packit |
90a5c9 |
if (route) {
|
|
Packit |
90a5c9 |
apr_table_setn(r->notes, "session-sticky", sticky);
|
|
Packit |
90a5c9 |
apr_table_setn(r->notes, "session-route", route);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Add session info to env. */
|
|
Packit |
90a5c9 |
apr_table_setn(r->subprocess_env,
|
|
Packit |
90a5c9 |
"BALANCER_SESSION_STICKY", sticky);
|
|
Packit |
90a5c9 |
apr_table_setn(r->subprocess_env,
|
|
Packit |
90a5c9 |
"BALANCER_SESSION_ROUTE", route);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01172)
|
|
Packit |
90a5c9 |
"%s: worker (%s) rewritten to %s",
|
|
Packit |
90a5c9 |
(*balancer)->s->name, (*worker)->s->name, *url);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return access_status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int proxy_balancer_post_request(proxy_worker *worker,
|
|
Packit |
90a5c9 |
proxy_balancer *balancer,
|
|
Packit |
90a5c9 |
request_rec *r,
|
|
Packit |
90a5c9 |
proxy_server_conf *conf)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01173)
|
|
Packit |
90a5c9 |
"%s: Lock failed for post_request",
|
|
Packit |
90a5c9 |
balancer->s->name);
|
|
Packit |
90a5c9 |
return HTTP_INTERNAL_SERVER_ERROR;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!apr_is_empty_array(balancer->errstatuses)
|
|
Packit |
90a5c9 |
&& !(worker->s->status & PROXY_WORKER_IGNORE_ERRORS)) {
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
for (i = 0; i < balancer->errstatuses->nelts; i++) {
|
|
Packit |
90a5c9 |
int val = ((int *)balancer->errstatuses->elts)[i];
|
|
Packit |
90a5c9 |
if (r->status == val) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01174)
|
|
Packit |
90a5c9 |
"%s: Forcing worker (%s) into error state "
|
|
Packit |
90a5c9 |
"due to status code %d matching 'failonstatus' "
|
|
Packit |
90a5c9 |
"balancer parameter",
|
|
Packit |
90a5c9 |
balancer->s->name, ap_proxy_worker_name(r->pool, worker),
|
|
Packit |
90a5c9 |
val);
|
|
Packit |
90a5c9 |
worker->s->status |= PROXY_WORKER_IN_ERROR;
|
|
Packit |
90a5c9 |
worker->s->error_time = apr_time_now();
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (balancer->failontimeout
|
|
Packit |
90a5c9 |
&& !(worker->s->status & PROXY_WORKER_IGNORE_ERRORS)
|
|
Packit |
90a5c9 |
&& (apr_table_get(r->notes, "proxy_timedout")) != NULL) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(02460)
|
|
Packit |
90a5c9 |
"%s: Forcing worker (%s) into error state "
|
|
Packit |
90a5c9 |
"due to timeout and 'failontimeout' parameter being set",
|
|
Packit |
90a5c9 |
balancer->s->name, ap_proxy_worker_name(r->pool, worker));
|
|
Packit |
90a5c9 |
worker->s->status |= PROXY_WORKER_IN_ERROR;
|
|
Packit |
90a5c9 |
worker->s->error_time = apr_time_now();
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01175)
|
|
Packit |
90a5c9 |
"%s: Unlock failed for post_request", balancer->s->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01176)
|
|
Packit |
90a5c9 |
"proxy_balancer_post_request for (%s)", balancer->s->name);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void recalc_factors(proxy_balancer *balancer)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
proxy_worker **workers;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Recalculate lbfactors */
|
|
Packit |
90a5c9 |
workers = (proxy_worker **)balancer->workers->elts;
|
|
Packit |
90a5c9 |
/* Special case if there is only one worker its
|
|
Packit |
90a5c9 |
* load factor will always be 100
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (balancer->workers->nelts == 1) {
|
|
Packit |
90a5c9 |
(*workers)->s->lbstatus = (*workers)->s->lbfactor = 100;
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
for (i = 0; i < balancer->workers->nelts; i++) {
|
|
Packit |
90a5c9 |
/* Update the status entries */
|
|
Packit |
90a5c9 |
workers[i]->s->lbstatus = workers[i]->s->lbfactor;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t lock_remove(void *data)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
proxy_balancer *balancer;
|
|
Packit |
90a5c9 |
server_rec *s = data;
|
|
Packit |
90a5c9 |
void *sconf = s->module_config;
|
|
Packit |
90a5c9 |
proxy_server_conf *conf = (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
balancer = (proxy_balancer *)conf->balancers->elts;
|
|
Packit |
90a5c9 |
for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
|
|
Packit |
90a5c9 |
if (balancer->gmutex) {
|
|
Packit |
90a5c9 |
apr_global_mutex_destroy(balancer->gmutex);
|
|
Packit |
90a5c9 |
balancer->gmutex = NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return(0);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Compute an ID for a vhost based on what makes it selected by requests.
|
|
Packit |
90a5c9 |
* The second and more Host(s)/IP(s):port(s), and the ServerAlias(es) are
|
|
Packit |
90a5c9 |
* optional (see make_servers_ids() below).
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static const char *make_server_id(server_rec *s, apr_pool_t *p, int full)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_md5_ctx_t md5_ctx;
|
|
Packit |
90a5c9 |
unsigned char md5[APR_MD5_DIGESTSIZE];
|
|
Packit |
90a5c9 |
char id[2 * APR_MD5_DIGESTSIZE + 1];
|
|
Packit |
90a5c9 |
char host_ip[64]; /* for any IPv[46] string */
|
|
Packit |
90a5c9 |
server_addr_rec *sar;
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_md5_init(&md5_ctx);
|
|
Packit |
90a5c9 |
for (sar = s->addrs; sar; sar = sar->next) {
|
|
Packit |
90a5c9 |
host_ip[0] = '\0';
|
|
Packit |
90a5c9 |
apr_sockaddr_ip_getbuf(host_ip, sizeof host_ip, sar->host_addr);
|
|
Packit |
90a5c9 |
apr_md5_update(&md5_ctx, (void *)sar->virthost, strlen(sar->virthost));
|
|
Packit |
90a5c9 |
apr_md5_update(&md5_ctx, (void *)host_ip, strlen(host_ip));
|
|
Packit |
90a5c9 |
apr_md5_update(&md5_ctx, (void *)&sar->host_port,
|
|
Packit |
90a5c9 |
sizeof(sar->host_port));
|
|
Packit |
90a5c9 |
if (!full) {
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (s->server_hostname) {
|
|
Packit |
90a5c9 |
apr_md5_update(&md5_ctx, (void *)s->server_hostname,
|
|
Packit |
90a5c9 |
strlen(s->server_hostname));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (full) {
|
|
Packit |
90a5c9 |
if (s->names) {
|
|
Packit |
90a5c9 |
for (i = 0; i < s->names->nelts; ++i) {
|
|
Packit |
90a5c9 |
const char *name = APR_ARRAY_IDX(s->names, i, char *);
|
|
Packit |
90a5c9 |
apr_md5_update(&md5_ctx, (void *)name, strlen(name));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (s->wild_names) {
|
|
Packit |
90a5c9 |
for (i = 0; i < s->wild_names->nelts; ++i) {
|
|
Packit |
90a5c9 |
const char *name = APR_ARRAY_IDX(s->wild_names, i, char *);
|
|
Packit |
90a5c9 |
apr_md5_update(&md5_ctx, (void *)name, strlen(name));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
apr_md5_final(md5, &md5_ctx);
|
|
Packit |
90a5c9 |
ap_bin2hex(md5, APR_MD5_DIGESTSIZE, id);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return apr_pstrmemdup(p, id, sizeof(id) - 1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* First try to compute an unique ID for each vhost with minimal criteria,
|
|
Packit |
90a5c9 |
* that is the first Host/IP:port and ServerName. For most cases this should
|
|
Packit |
90a5c9 |
* be enough and avoids changing the ID unnecessarily accross restart (or
|
|
Packit |
90a5c9 |
* stop/start w.r.t. persisted files) for things that this module does not
|
|
Packit |
90a5c9 |
* care about.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* But if it's not enough (collisions) do a second pass for the full monty,
|
|
Packit |
90a5c9 |
* that is additionally the other Host(s)/IP(s):port(s) and ServerAlias(es).
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Finally, for pathological configs where this is still not enough, let's
|
|
Packit |
90a5c9 |
* append a counter to duplicates, because we really want that ID to be unique
|
|
Packit |
90a5c9 |
* even if the vhost will never be selected to handle requests at run time, at
|
|
Packit |
90a5c9 |
* load time a duplicate may steal the original slotmems (depending on its
|
|
Packit |
90a5c9 |
* balancers' configurations), see how mod_slotmem_shm reuses slots/files based
|
|
Packit |
90a5c9 |
* solely on this ID and resets them if the sizes don't match.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static apr_array_header_t *make_servers_ids(server_rec *main_s, apr_pool_t *p)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
server_rec *s = main_s;
|
|
Packit |
90a5c9 |
apr_array_header_t *ids = apr_array_make(p, 10, sizeof(const char *));
|
|
Packit |
90a5c9 |
apr_hash_t *dups = apr_hash_make(p);
|
|
Packit |
90a5c9 |
int idx, *dup, full_monty = 0;
|
|
Packit |
90a5c9 |
const char *id;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (idx = 0, s = main_s; s; s = s->next, ++idx) {
|
|
Packit |
90a5c9 |
id = make_server_id(s, p, 0);
|
|
Packit |
90a5c9 |
dup = apr_hash_get(dups, id, APR_HASH_KEY_STRING);
|
|
Packit |
90a5c9 |
apr_hash_set(dups, id, APR_HASH_KEY_STRING,
|
|
Packit |
90a5c9 |
apr_pmemdup(p, &idx, sizeof(int)));
|
|
Packit |
90a5c9 |
if (dup) {
|
|
Packit |
90a5c9 |
full_monty = 1;
|
|
Packit |
90a5c9 |
APR_ARRAY_IDX(ids, *dup, const char *) = NULL;
|
|
Packit |
90a5c9 |
APR_ARRAY_PUSH(ids, const char *) = NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
APR_ARRAY_PUSH(ids, const char *) = id;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (full_monty) {
|
|
Packit |
90a5c9 |
apr_hash_clear(dups);
|
|
Packit |
90a5c9 |
for (idx = 0, s = main_s; s; s = s->next, ++idx) {
|
|
Packit |
90a5c9 |
id = APR_ARRAY_IDX(ids, idx, const char *);
|
|
Packit |
90a5c9 |
if (id) {
|
|
Packit |
90a5c9 |
/* Preserve non-duplicates */
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
id = make_server_id(s, p, 1);
|
|
Packit |
90a5c9 |
if (apr_hash_get(dups, id, APR_HASH_KEY_STRING)) {
|
|
Packit |
90a5c9 |
id = apr_psprintf(p, "%s_%x", id, idx);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
apr_hash_set(dups, id, APR_HASH_KEY_STRING, (void *)-1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
APR_ARRAY_IDX(ids, idx, const char *) = id;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return ids;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* post_config hook: */
|
|
Packit |
90a5c9 |
static int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp, server_rec *s)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
proxy_server_conf *conf;
|
|
Packit |
90a5c9 |
ap_slotmem_instance_t *new = NULL;
|
|
Packit |
90a5c9 |
apr_time_t tstamp;
|
|
Packit |
90a5c9 |
apr_array_header_t *ids;
|
|
Packit |
90a5c9 |
int idx;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* balancer_post_config() will be called twice during startup. So, don't
|
|
Packit |
90a5c9 |
* set up the static data the 1st time through. */
|
|
Packit |
90a5c9 |
if (ap_state_query(AP_SQ_MAIN_STATE) == AP_SQ_MS_CREATE_PRE_CONFIG) {
|
|
Packit |
90a5c9 |
return OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_proxy_retry_worker_fn =
|
|
Packit |
90a5c9 |
APR_RETRIEVE_OPTIONAL_FN(ap_proxy_retry_worker);
|
|
Packit |
90a5c9 |
if (!ap_proxy_retry_worker_fn) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(02230)
|
|
Packit |
90a5c9 |
"mod_proxy must be loaded for mod_proxy_balancer");
|
|
Packit |
90a5c9 |
return !OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Get slotmem setups
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
storage = ap_lookup_provider(AP_SLOTMEM_PROVIDER_GROUP, "shm",
|
|
Packit |
90a5c9 |
AP_SLOTMEM_PROVIDER_VERSION);
|
|
Packit |
90a5c9 |
if (!storage) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01177)
|
|
Packit |
90a5c9 |
"Failed to lookup provider 'shm' for '%s': is "
|
|
Packit |
90a5c9 |
"mod_slotmem_shm loaded??",
|
|
Packit |
90a5c9 |
AP_SLOTMEM_PROVIDER_GROUP);
|
|
Packit |
90a5c9 |
return !OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ids = make_servers_ids(s, ptemp);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
tstamp = apr_time_now();
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Go thru each Vhost and create the shared mem slotmem for
|
|
Packit |
90a5c9 |
* each balancer's workers
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
for (idx = 0; s; ++idx) {
|
|
Packit |
90a5c9 |
int i,j;
|
|
Packit |
90a5c9 |
const char *id;
|
|
Packit |
90a5c9 |
proxy_balancer *balancer;
|
|
Packit |
90a5c9 |
ap_slotmem_type_t type;
|
|
Packit |
90a5c9 |
void *sconf = s->module_config;
|
|
Packit |
90a5c9 |
conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* During create_proxy_config() we created a dummy id. Now that
|
|
Packit |
90a5c9 |
* we have identifying info, we can create the real id
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
id = APR_ARRAY_IDX(ids, idx, const char *);
|
|
Packit |
90a5c9 |
conf->id = apr_psprintf(pconf, "p%x",
|
|
Packit |
90a5c9 |
ap_proxy_hashfunc(id, PROXY_HASHFUNC_DEFAULT));
|
|
Packit |
90a5c9 |
if (conf->bslot) {
|
|
Packit |
90a5c9 |
/* Shared memory already created for this proxy_server_conf.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
s = s->next;
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (conf->bal_persist) {
|
|
Packit |
90a5c9 |
type = AP_SLOTMEM_TYPE_PERSIST | AP_SLOTMEM_TYPE_CLEARINUSE;
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
type = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (conf->balancers->nelts) {
|
|
Packit |
90a5c9 |
conf->max_balancers = conf->balancers->nelts + conf->bgrowth;
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01178) "Doing balancers create: %d, %d (%d)",
|
|
Packit |
90a5c9 |
(int)ALIGNED_PROXY_BALANCER_SHARED_SIZE,
|
|
Packit |
90a5c9 |
(int)conf->balancers->nelts, conf->max_balancers);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rv = storage->create(&new, conf->id,
|
|
Packit |
90a5c9 |
ALIGNED_PROXY_BALANCER_SHARED_SIZE,
|
|
Packit |
90a5c9 |
conf->max_balancers, type, pconf);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01179) "balancer slotmem_create failed");
|
|
Packit |
90a5c9 |
return !OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
conf->bslot = new;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
conf->storage = storage;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Initialize shared scoreboard data */
|
|
Packit |
90a5c9 |
balancer = (proxy_balancer *)conf->balancers->elts;
|
|
Packit |
90a5c9 |
for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
|
|
Packit |
90a5c9 |
proxy_worker **workers;
|
|
Packit |
90a5c9 |
proxy_worker *worker;
|
|
Packit |
90a5c9 |
proxy_balancer_shared *bshm;
|
|
Packit |
90a5c9 |
const char *sname;
|
|
Packit |
90a5c9 |
unsigned int index;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* now that we have the right id, we need to redo the sname field */
|
|
Packit |
90a5c9 |
ap_pstr2_alnum(pconf, balancer->s->name + sizeof(BALANCER_PREFIX) - 1,
|
|
Packit |
90a5c9 |
&sname);
|
|
Packit |
90a5c9 |
sname = apr_pstrcat(pconf, conf->id, "_", sname, NULL);
|
|
Packit |
90a5c9 |
PROXY_STRNCPY(balancer->s->sname, sname); /* We know this will succeed */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
balancer->max_workers = balancer->workers->nelts + balancer->growth;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Create global mutex */
|
|
Packit |
90a5c9 |
rv = ap_global_mutex_create(&(balancer->gmutex), NULL, balancer_mutex_type,
|
|
Packit |
90a5c9 |
balancer->s->sname, s, pconf, 0);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS || !balancer->gmutex) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01180)
|
|
Packit |
90a5c9 |
"mutex creation of %s : %s failed", balancer_mutex_type,
|
|
Packit |
90a5c9 |
balancer->s->sname);
|
|
Packit |
90a5c9 |
return HTTP_INTERNAL_SERVER_ERROR;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_pool_cleanup_register(pconf, (void *)s, lock_remove,
|
|
Packit |
90a5c9 |
apr_pool_cleanup_null);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* setup shm for balancers */
|
|
Packit |
90a5c9 |
bshm = ap_proxy_find_balancershm(storage, conf->bslot, balancer, &index);
|
|
Packit |
90a5c9 |
if (bshm) {
|
|
Packit |
90a5c9 |
if ((rv = storage->fgrab(conf->bslot, index)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(02408) "balancer slotmem_fgrab failed");
|
|
Packit |
90a5c9 |
return !OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
if ((rv = storage->grab(conf->bslot, &index)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01181) "balancer slotmem_grab failed");
|
|
Packit |
90a5c9 |
return !OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((rv = storage->dptr(conf->bslot, index, (void *)&bshm)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01182) "balancer slotmem_dptr failed");
|
|
Packit |
90a5c9 |
return !OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((rv = ap_proxy_share_balancer(balancer, bshm, index)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01183) "Cannot share balancer");
|
|
Packit |
90a5c9 |
return !OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* create slotmem slots for workers */
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01184) "Doing workers create: %s (%s), %d, %d [%u]",
|
|
Packit |
90a5c9 |
balancer->s->name, balancer->s->sname,
|
|
Packit |
90a5c9 |
(int)ALIGNED_PROXY_WORKER_SHARED_SIZE,
|
|
Packit |
90a5c9 |
(int)balancer->max_workers, i);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rv = storage->create(&new, balancer->s->sname,
|
|
Packit |
90a5c9 |
ALIGNED_PROXY_WORKER_SHARED_SIZE,
|
|
Packit |
90a5c9 |
balancer->max_workers, type, pconf);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01185) "worker slotmem_create failed");
|
|
Packit |
90a5c9 |
return !OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
balancer->wslot = new;
|
|
Packit |
90a5c9 |
balancer->storage = storage;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* sync all timestamps */
|
|
Packit |
90a5c9 |
balancer->wupdated = balancer->s->wupdated = tstamp;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* now go thru each worker */
|
|
Packit |
90a5c9 |
workers = (proxy_worker **)balancer->workers->elts;
|
|
Packit |
90a5c9 |
for (j = 0; j < balancer->workers->nelts; j++, workers++) {
|
|
Packit |
90a5c9 |
proxy_worker_shared *shm;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
worker = *workers;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
shm = ap_proxy_find_workershm(storage, balancer->wslot, worker, &index);
|
|
Packit |
90a5c9 |
if (shm) {
|
|
Packit |
90a5c9 |
if ((rv = storage->fgrab(balancer->wslot, index)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(02409) "worker slotmem_fgrab failed");
|
|
Packit |
90a5c9 |
return !OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
if ((rv = storage->grab(balancer->wslot, &index)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01186) "worker slotmem_grab failed");
|
|
Packit |
90a5c9 |
return !OK;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((rv = storage->dptr(balancer->wslot, index, (void *)&shm)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01187) "worker slotmem_dptr failed");
|
|
Packit |
90a5c9 |
return !OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((rv = ap_proxy_share_worker(worker, shm, index)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01188) "Cannot share worker");
|
|
Packit |
90a5c9 |
return !OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
worker->s->updated = tstamp;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (conf->bal_persist) {
|
|
Packit |
90a5c9 |
/* We could have just read-in a persisted config. Force a sync. */
|
|
Packit |
90a5c9 |
balancer->wupdated--;
|
|
Packit |
90a5c9 |
ap_proxy_sync_balancer(balancer, s, conf);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
s = s->next;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void create_radio(const char *name, unsigned int flag, request_rec *r)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
ap_rvputs(r, "<label for='", name, "1'>On</label>
|
|
Packit |
90a5c9 |
if (flag)
|
|
Packit |
90a5c9 |
ap_rputs(" checked", r);
|
|
Packit |
90a5c9 |
ap_rvputs(r, "> <label for='", name, "0'>Off</label>
|
|
Packit |
90a5c9 |
if (!flag)
|
|
Packit |
90a5c9 |
ap_rputs(" checked", r);
|
|
Packit |
90a5c9 |
ap_rputs(">\n", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void push2table(const char *input, apr_table_t *params,
|
|
Packit |
90a5c9 |
const char *allowed[], apr_pool_t *p)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char *args;
|
|
Packit |
90a5c9 |
char *tok, *val;
|
|
Packit |
90a5c9 |
char *key;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (input == NULL) {
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
args = apr_pstrdup(p, input);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
key = apr_strtok(args, "&", &tok;;
|
|
Packit |
90a5c9 |
while (key) {
|
|
Packit |
90a5c9 |
val = strchr(key, '=');
|
|
Packit |
90a5c9 |
if (val) {
|
|
Packit |
90a5c9 |
*val++ = '\0';
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
val = "";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_unescape_url(key);
|
|
Packit |
90a5c9 |
ap_unescape_url(val);
|
|
Packit |
90a5c9 |
if (allowed == NULL) { /* allow all */
|
|
Packit |
90a5c9 |
apr_table_set(params, key, val);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
const char **ok = allowed;
|
|
Packit |
90a5c9 |
while (*ok) {
|
|
Packit |
90a5c9 |
if (strcmp(*ok, key) == 0) {
|
|
Packit |
90a5c9 |
apr_table_set(params, key, val);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ok++;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
key = apr_strtok(NULL, "&", &tok;;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Manages the loadfactors and member status
|
|
Packit |
90a5c9 |
* The balancer, worker and nonce are obtained from
|
|
Packit |
90a5c9 |
* the request args (?b=...&w=...&nonce=....).
|
|
Packit |
90a5c9 |
* All other params are pulled from any POST
|
|
Packit |
90a5c9 |
* data that exists.
|
|
Packit |
90a5c9 |
* TODO:
|
|
Packit |
90a5c9 |
* /.../<whatever>/balancer/worker/nonce
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static int balancer_handler(request_rec *r)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
void *sconf;
|
|
Packit |
90a5c9 |
proxy_server_conf *conf;
|
|
Packit |
90a5c9 |
proxy_balancer *balancer, *bsel = NULL;
|
|
Packit |
90a5c9 |
proxy_worker *worker, *wsel = NULL;
|
|
Packit |
90a5c9 |
proxy_worker **workers = NULL;
|
|
Packit |
90a5c9 |
apr_table_t *params;
|
|
Packit |
90a5c9 |
int i, n;
|
|
Packit |
90a5c9 |
int ok2change = 1;
|
|
Packit |
90a5c9 |
const char *name;
|
|
Packit |
90a5c9 |
const char *action;
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* is this for us? */
|
|
Packit |
90a5c9 |
if (strcmp(r->handler, "balancer-manager")) {
|
|
Packit |
90a5c9 |
return DECLINED;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
r->allowed = 0
|
|
Packit |
90a5c9 |
| (AP_METHOD_BIT << M_GET)
|
|
Packit |
90a5c9 |
| (AP_METHOD_BIT << M_POST);
|
|
Packit |
90a5c9 |
if ((r->method_number != M_GET) && (r->method_number != M_POST)) {
|
|
Packit |
90a5c9 |
return DECLINED;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
sconf = r->server->module_config;
|
|
Packit |
90a5c9 |
conf = (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
|
|
Packit |
90a5c9 |
params = apr_table_make(r->pool, 10);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
balancer = (proxy_balancer *)conf->balancers->elts;
|
|
Packit |
90a5c9 |
for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
|
|
Packit |
90a5c9 |
if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01189)
|
|
Packit |
90a5c9 |
"%s: Lock failed for balancer_handler",
|
|
Packit |
90a5c9 |
balancer->s->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_proxy_sync_balancer(balancer, r->server, conf);
|
|
Packit |
90a5c9 |
if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01190)
|
|
Packit |
90a5c9 |
"%s: Unlock failed for balancer_handler",
|
|
Packit |
90a5c9 |
balancer->s->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (r->args && (r->method_number == M_GET)) {
|
|
Packit |
90a5c9 |
const char *allowed[] = { "w", "b", "nonce", "xml", NULL };
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01191) "parsing r->args");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
push2table(r->args, params, allowed, r->pool);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (r->method_number == M_POST) {
|
|
Packit |
90a5c9 |
apr_bucket_brigade *ib;
|
|
Packit |
90a5c9 |
apr_size_t len = 1024;
|
|
Packit |
90a5c9 |
char *buf = apr_pcalloc(r->pool, len+1);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ib = apr_brigade_create(r->connection->pool, r->connection->bucket_alloc);
|
|
Packit |
90a5c9 |
rv = ap_get_brigade(r->input_filters, ib, AP_MODE_READBYTES,
|
|
Packit |
90a5c9 |
APR_BLOCK_READ, len);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return ap_map_http_request_error(rv, HTTP_BAD_REQUEST);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
apr_brigade_flatten(ib, buf, &len;;
|
|
Packit |
90a5c9 |
buf[len] = '\0';
|
|
Packit |
90a5c9 |
push2table(buf, params, NULL, r->pool);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((name = apr_table_get(params, "b")))
|
|
Packit |
90a5c9 |
bsel = ap_proxy_get_balancer(r->pool, conf,
|
|
Packit |
90a5c9 |
apr_pstrcat(r->pool, BALANCER_PREFIX, name, NULL), 0);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((name = apr_table_get(params, "w"))) {
|
|
Packit |
90a5c9 |
wsel = ap_proxy_get_worker(r->pool, bsel, conf, name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Check that the supplied nonce matches this server's nonce;
|
|
Packit |
90a5c9 |
* otherwise ignore all parameters, to prevent a CSRF attack. */
|
|
Packit |
90a5c9 |
if (!bsel ||
|
|
Packit |
90a5c9 |
(*bsel->s->nonce &&
|
|
Packit |
90a5c9 |
(
|
|
Packit |
90a5c9 |
(name = apr_table_get(params, "nonce")) == NULL ||
|
|
Packit |
90a5c9 |
strcmp(bsel->s->nonce, name) != 0
|
|
Packit |
90a5c9 |
)
|
|
Packit |
90a5c9 |
)
|
|
Packit |
90a5c9 |
) {
|
|
Packit |
90a5c9 |
apr_table_clear(params);
|
|
Packit |
90a5c9 |
ok2change = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* First set the params */
|
|
Packit |
90a5c9 |
if (wsel && ok2change) {
|
|
Packit |
90a5c9 |
const char *val;
|
|
Packit |
90a5c9 |
int was_usable = PROXY_WORKER_IS_USABLE(wsel);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01192) "settings worker params");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "w_lf"))) {
|
|
Packit |
90a5c9 |
int ival;
|
|
Packit |
90a5c9 |
double fval = atof(val);
|
|
Packit |
90a5c9 |
ival = fval * 100.0;
|
|
Packit |
90a5c9 |
if (ival >= 100 && ival <= 10000) {
|
|
Packit |
90a5c9 |
wsel->s->lbfactor = ival;
|
|
Packit |
90a5c9 |
if (bsel)
|
|
Packit |
90a5c9 |
recalc_factors(bsel);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "w_wr"))) {
|
|
Packit |
90a5c9 |
if (strlen(val) && strlen(val) < sizeof(wsel->s->route))
|
|
Packit |
90a5c9 |
strcpy(wsel->s->route, val);
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
*wsel->s->route = '\0';
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "w_rr"))) {
|
|
Packit |
90a5c9 |
if (strlen(val) && strlen(val) < sizeof(wsel->s->redirect))
|
|
Packit |
90a5c9 |
strcpy(wsel->s->redirect, val);
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
*wsel->s->redirect = '\0';
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* TODO: Look for all 'w_status_#' keys and then loop thru
|
|
Packit |
90a5c9 |
* on that # character, since the character == the flag
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "w_status_I"))) {
|
|
Packit |
90a5c9 |
ap_proxy_set_wstatus(PROXY_WORKER_IGNORE_ERRORS_FLAG, atoi(val), wsel);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "w_status_N"))) {
|
|
Packit |
90a5c9 |
ap_proxy_set_wstatus(PROXY_WORKER_DRAIN_FLAG, atoi(val), wsel);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "w_status_D"))) {
|
|
Packit |
90a5c9 |
ap_proxy_set_wstatus(PROXY_WORKER_DISABLED_FLAG, atoi(val), wsel);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "w_status_H"))) {
|
|
Packit |
90a5c9 |
ap_proxy_set_wstatus(PROXY_WORKER_HOT_STANDBY_FLAG, atoi(val), wsel);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "w_status_R"))) {
|
|
Packit |
90a5c9 |
ap_proxy_set_wstatus(PROXY_WORKER_HOT_SPARE_FLAG, atoi(val), wsel);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "w_status_S"))) {
|
|
Packit |
90a5c9 |
ap_proxy_set_wstatus(PROXY_WORKER_STOPPED_FLAG, atoi(val), wsel);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "w_status_C"))) {
|
|
Packit |
90a5c9 |
ap_proxy_set_wstatus(PROXY_WORKER_HC_FAIL_FLAG, atoi(val), wsel);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "w_ls"))) {
|
|
Packit |
90a5c9 |
int ival = atoi(val);
|
|
Packit |
90a5c9 |
if (ival >= 0 && ival <= 99) {
|
|
Packit |
90a5c9 |
wsel->s->lbset = ival;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "w_hi"))) {
|
|
Packit |
90a5c9 |
apr_interval_time_t hci;
|
|
Packit |
90a5c9 |
if (ap_timeout_parameter_parse(val, &hci, "ms") == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
if (hci >= AP_WD_TM_SLICE) {
|
|
Packit |
90a5c9 |
wsel->s->interval = hci;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "w_hp"))) {
|
|
Packit |
90a5c9 |
int ival = atoi(val);
|
|
Packit |
90a5c9 |
if (ival >= 1) {
|
|
Packit |
90a5c9 |
wsel->s->passes = ival;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "w_hf"))) {
|
|
Packit |
90a5c9 |
int ival = atoi(val);
|
|
Packit |
90a5c9 |
if (ival >= 1) {
|
|
Packit |
90a5c9 |
wsel->s->fails = ival;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "w_hm"))) {
|
|
Packit |
90a5c9 |
proxy_hcmethods_t *method = proxy_hcmethods;
|
|
Packit |
90a5c9 |
for (; method->name; method++) {
|
|
Packit |
90a5c9 |
if (!strcasecmp(method->name, val) && method->implemented)
|
|
Packit |
90a5c9 |
wsel->s->method = method->method;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "w_hu"))) {
|
|
Packit |
90a5c9 |
if (strlen(val) && strlen(val) < sizeof(wsel->s->hcuri))
|
|
Packit |
90a5c9 |
strcpy(wsel->s->hcuri, val);
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
*wsel->s->hcuri = '\0';
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (hc_valid_expr_f && (val = apr_table_get(params, "w_he"))) {
|
|
Packit |
90a5c9 |
if (strlen(val) && hc_valid_expr_f(r, val) && strlen(val) < sizeof(wsel->s->hcexpr))
|
|
Packit |
90a5c9 |
strcpy(wsel->s->hcexpr, val);
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
*wsel->s->hcexpr = '\0';
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* If the health check method doesn't support an expr, then null it */
|
|
Packit |
90a5c9 |
if (wsel->s->method == NONE || wsel->s->method == TCP) {
|
|
Packit |
90a5c9 |
*wsel->s->hcexpr = '\0';
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* if enabling, we need to reset all lb params */
|
|
Packit |
90a5c9 |
if (bsel && !was_usable && PROXY_WORKER_IS_USABLE(wsel)) {
|
|
Packit |
90a5c9 |
bsel->s->need_reset = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (bsel && ok2change) {
|
|
Packit |
90a5c9 |
const char *val;
|
|
Packit |
90a5c9 |
int ival;
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01193)
|
|
Packit |
90a5c9 |
"settings balancer params");
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "b_lbm"))) {
|
|
Packit |
90a5c9 |
if ((strlen(val) < (sizeof(bsel->s->lbpname)-1)) &&
|
|
Packit |
90a5c9 |
strcmp(val, bsel->s->lbpname)) {
|
|
Packit |
90a5c9 |
proxy_balancer_method *lbmethod;
|
|
Packit |
90a5c9 |
lbmethod = ap_lookup_provider(PROXY_LBMETHOD, val, "0");
|
|
Packit |
90a5c9 |
if (lbmethod) {
|
|
Packit |
90a5c9 |
PROXY_STRNCPY(bsel->s->lbpname, val);
|
|
Packit |
90a5c9 |
bsel->lbmethod = lbmethod;
|
|
Packit |
90a5c9 |
bsel->s->wupdated = apr_time_now();
|
|
Packit |
90a5c9 |
bsel->s->need_reset = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "b_tmo"))) {
|
|
Packit |
90a5c9 |
ival = atoi(val);
|
|
Packit |
90a5c9 |
if (ival >= 0 && ival <= 7200) { /* 2 hrs enuff? */
|
|
Packit |
90a5c9 |
bsel->s->timeout = apr_time_from_sec(ival);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "b_max"))) {
|
|
Packit |
90a5c9 |
ival = atoi(val);
|
|
Packit |
90a5c9 |
if (ival >= 0 && ival <= 99) {
|
|
Packit |
90a5c9 |
bsel->s->max_attempts = ival;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "b_sforce"))) {
|
|
Packit |
90a5c9 |
ival = atoi(val);
|
|
Packit |
90a5c9 |
bsel->s->sticky_force = (ival != 0);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "b_ss")) && *val) {
|
|
Packit |
90a5c9 |
if (strlen(val) < (sizeof(bsel->s->sticky_path)-1)) {
|
|
Packit |
90a5c9 |
if (*val == '-' && *(val+1) == '\0')
|
|
Packit |
90a5c9 |
*bsel->s->sticky_path = *bsel->s->sticky = '\0';
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
char *path;
|
|
Packit |
90a5c9 |
PROXY_STRNCPY(bsel->s->sticky_path, val);
|
|
Packit |
90a5c9 |
PROXY_STRNCPY(bsel->s->sticky, val);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((path = strchr((char *)bsel->s->sticky, '|'))) {
|
|
Packit |
90a5c9 |
*path++ = '\0';
|
|
Packit |
90a5c9 |
PROXY_STRNCPY(bsel->s->sticky_path, path);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((val = apr_table_get(params, "b_wyes")) &&
|
|
Packit |
90a5c9 |
(*val == '1' && *(val+1) == '\0') &&
|
|
Packit |
90a5c9 |
(val = apr_table_get(params, "b_nwrkr"))) {
|
|
Packit |
90a5c9 |
char *ret;
|
|
Packit |
90a5c9 |
proxy_worker *nworker;
|
|
Packit |
90a5c9 |
nworker = ap_proxy_get_worker(r->pool, bsel, conf, val);
|
|
Packit |
90a5c9 |
if (!nworker && storage->num_free_slots(bsel->wslot)) {
|
|
Packit |
90a5c9 |
if ((rv = PROXY_GLOBAL_LOCK(bsel)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01194)
|
|
Packit |
90a5c9 |
"%s: Lock failed for adding worker",
|
|
Packit |
90a5c9 |
bsel->s->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ret = ap_proxy_define_worker(conf->pool, &nworker, bsel, conf, val, 0);
|
|
Packit |
90a5c9 |
if (!ret) {
|
|
Packit |
90a5c9 |
unsigned int index;
|
|
Packit |
90a5c9 |
proxy_worker_shared *shm;
|
|
Packit |
90a5c9 |
PROXY_COPY_CONF_PARAMS(nworker, conf);
|
|
Packit |
90a5c9 |
if ((rv = storage->grab(bsel->wslot, &index)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01195)
|
|
Packit |
90a5c9 |
"worker slotmem_grab failed");
|
|
Packit |
90a5c9 |
if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01196)
|
|
Packit |
90a5c9 |
"%s: Unlock failed for adding worker",
|
|
Packit |
90a5c9 |
bsel->s->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return HTTP_BAD_REQUEST;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((rv = storage->dptr(bsel->wslot, index, (void *)&shm)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01197)
|
|
Packit |
90a5c9 |
"worker slotmem_dptr failed");
|
|
Packit |
90a5c9 |
if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01198)
|
|
Packit |
90a5c9 |
"%s: Unlock failed for adding worker",
|
|
Packit |
90a5c9 |
bsel->s->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return HTTP_BAD_REQUEST;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((rv = ap_proxy_share_worker(nworker, shm, index)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01199)
|
|
Packit |
90a5c9 |
"Cannot share worker");
|
|
Packit |
90a5c9 |
if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01200)
|
|
Packit |
90a5c9 |
"%s: Unlock failed for adding worker",
|
|
Packit |
90a5c9 |
bsel->s->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return HTTP_BAD_REQUEST;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((rv = ap_proxy_initialize_worker(nworker, r->server, conf->pool)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01201)
|
|
Packit |
90a5c9 |
"Cannot init worker");
|
|
Packit |
90a5c9 |
if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01202)
|
|
Packit |
90a5c9 |
"%s: Unlock failed for adding worker",
|
|
Packit |
90a5c9 |
bsel->s->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return HTTP_BAD_REQUEST;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* sync all timestamps */
|
|
Packit |
90a5c9 |
bsel->wupdated = bsel->s->wupdated = nworker->s->updated = apr_time_now();
|
|
Packit |
90a5c9 |
/* by default, all new workers are disabled */
|
|
Packit |
90a5c9 |
ap_proxy_set_wstatus(PROXY_WORKER_DISABLED_FLAG, 1, nworker);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01203)
|
|
Packit |
90a5c9 |
"%s: Unlock failed for adding worker",
|
|
Packit |
90a5c9 |
bsel->s->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
action = ap_construct_url(r->pool, r->uri, r);
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01204) "genning page");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (apr_table_get(params, "xml")) {
|
|
Packit |
90a5c9 |
char date[APR_RFC822_DATE_LEN];
|
|
Packit |
90a5c9 |
ap_set_content_type(r, "text/xml");
|
|
Packit |
90a5c9 |
ap_rputs("\n", r);
|
|
Packit |
90a5c9 |
ap_rputs("<httpd:manager xmlns:httpd='http://httpd.apache.org'>\n", r);
|
|
Packit |
90a5c9 |
ap_rputs(" <httpd:balancers>\n", r);
|
|
Packit |
90a5c9 |
balancer = (proxy_balancer *)conf->balancers->elts;
|
|
Packit |
90a5c9 |
for (i = 0; i < conf->balancers->nelts; i++) {
|
|
Packit |
90a5c9 |
ap_rputs(" <httpd:balancer>\n", r);
|
|
Packit |
90a5c9 |
/* Start proxy_balancer */
|
|
Packit |
90a5c9 |
ap_rvputs(r, " <httpd:name>", balancer->s->name, "</httpd:name>\n", NULL);
|
|
Packit |
90a5c9 |
if (*balancer->s->sticky) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, " <httpd:stickysession>", balancer->s->sticky,
|
|
Packit |
90a5c9 |
"</httpd:stickysession>\n", NULL);
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:nofailover>%s</httpd:nofailover>\n",
|
|
Packit |
90a5c9 |
(balancer->s->sticky_force ? "On" : "Off"));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:timeout>%" APR_TIME_T_FMT "</httpd:timeout>",
|
|
Packit |
90a5c9 |
apr_time_sec(balancer->s->timeout));
|
|
Packit |
90a5c9 |
if (balancer->s->max_attempts_set) {
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:maxattempts>%d</httpd:maxattempts>\n",
|
|
Packit |
90a5c9 |
balancer->s->max_attempts);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rvputs(r, " <httpd:lbmethod>", balancer->lbmethod->name,
|
|
Packit |
90a5c9 |
"</httpd:lbmethod>\n", NULL);
|
|
Packit |
90a5c9 |
if (*balancer->s->sticky) {
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:scolonpathdelim>%s</httpd:scolonpathdelim>\n",
|
|
Packit |
90a5c9 |
(balancer->s->scolonsep ? "On" : "Off"));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* End proxy_balancer */
|
|
Packit |
90a5c9 |
ap_rputs(" <httpd:workers>\n", r);
|
|
Packit |
90a5c9 |
workers = (proxy_worker **)balancer->workers->elts;
|
|
Packit |
90a5c9 |
for (n = 0; n < balancer->workers->nelts; n++) {
|
|
Packit |
90a5c9 |
worker = *workers;
|
|
Packit |
90a5c9 |
/* Start proxy_worker */
|
|
Packit |
90a5c9 |
ap_rputs(" <httpd:worker>\n", r);
|
|
Packit |
90a5c9 |
ap_rvputs(r, " <httpd:name>", ap_proxy_worker_name(r->pool, worker),
|
|
Packit |
90a5c9 |
"</httpd:name>\n", NULL);
|
|
Packit |
90a5c9 |
ap_rvputs(r, " <httpd:scheme>", worker->s->scheme,
|
|
Packit |
90a5c9 |
"</httpd:scheme>\n", NULL);
|
|
Packit |
90a5c9 |
ap_rvputs(r, " <httpd:hostname>", worker->s->hostname_ex,
|
|
Packit |
90a5c9 |
"</httpd:hostname>\n", NULL);
|
|
Packit |
90a5c9 |
ap_rprintf(r, " <httpd:loadfactor>%.2f</httpd:loadfactor>\n",
|
|
Packit |
90a5c9 |
(float)(worker->s->lbfactor)/100.0);
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:port>%d</httpd:port>\n",
|
|
Packit |
90a5c9 |
worker->s->port);
|
|
Packit |
90a5c9 |
ap_rprintf(r, " <httpd:min>%d</httpd:min>\n",
|
|
Packit |
90a5c9 |
worker->s->min);
|
|
Packit |
90a5c9 |
ap_rprintf(r, " <httpd:smax>%d</httpd:smax>\n",
|
|
Packit |
90a5c9 |
worker->s->smax);
|
|
Packit |
90a5c9 |
ap_rprintf(r, " <httpd:max>%d</httpd:max>\n",
|
|
Packit |
90a5c9 |
worker->s->hmax);
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:ttl>%" APR_TIME_T_FMT "</httpd:ttl>\n",
|
|
Packit |
90a5c9 |
apr_time_sec(worker->s->ttl));
|
|
Packit |
90a5c9 |
if (worker->s->timeout_set) {
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:timeout>%" APR_TIME_T_FMT "</httpd:timeout>\n",
|
|
Packit |
90a5c9 |
apr_time_sec(worker->s->timeout));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (worker->s->acquire_set) {
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:acquire>%" APR_TIME_T_FMT "</httpd:acquire>\n",
|
|
Packit |
90a5c9 |
apr_time_msec(worker->s->acquire));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (worker->s->recv_buffer_size_set) {
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:recv_buffer_size>%" APR_SIZE_T_FMT "</httpd:recv_buffer_size>\n",
|
|
Packit |
90a5c9 |
worker->s->recv_buffer_size);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (worker->s->io_buffer_size_set) {
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:io_buffer_size>%" APR_SIZE_T_FMT "</httpd:io_buffer_size>\n",
|
|
Packit |
90a5c9 |
worker->s->io_buffer_size);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (worker->s->keepalive_set) {
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:keepalive>%s</httpd:keepalive>\n",
|
|
Packit |
90a5c9 |
(worker->s->keepalive ? "On" : "Off"));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* Begin proxy_worker_stat */
|
|
Packit |
90a5c9 |
ap_rputs(" <httpd:status>", r);
|
|
Packit |
90a5c9 |
ap_rputs(ap_proxy_parse_wstatus(r->pool, worker), r);
|
|
Packit |
90a5c9 |
ap_rputs("</httpd:status>\n", r);
|
|
Packit |
90a5c9 |
if ((worker->s->error_time > 0) && apr_rfc822_date(date, worker->s->error_time) == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, " <httpd:error_time>", date,
|
|
Packit |
90a5c9 |
"</httpd:error_time>\n", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:retries>%d</httpd:retries>\n",
|
|
Packit |
90a5c9 |
worker->s->retries);
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:lbstatus>%d</httpd:lbstatus>\n",
|
|
Packit |
90a5c9 |
worker->s->lbstatus);
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:loadfactor>%.2f</httpd:loadfactor>\n",
|
|
Packit |
90a5c9 |
(float)(worker->s->lbfactor)/100.0);
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:transferred>%" APR_OFF_T_FMT "</httpd:transferred>\n",
|
|
Packit |
90a5c9 |
worker->s->transferred);
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:read>%" APR_OFF_T_FMT "</httpd:read>\n",
|
|
Packit |
90a5c9 |
worker->s->read);
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:elected>%" APR_SIZE_T_FMT "</httpd:elected>\n",
|
|
Packit |
90a5c9 |
worker->s->elected);
|
|
Packit |
90a5c9 |
ap_rvputs(r, " <httpd:route>",
|
|
Packit |
90a5c9 |
ap_escape_html(r->pool, worker->s->route),
|
|
Packit |
90a5c9 |
"</httpd:route>\n", NULL);
|
|
Packit |
90a5c9 |
ap_rvputs(r, " <httpd:redirect>",
|
|
Packit |
90a5c9 |
ap_escape_html(r->pool, worker->s->redirect),
|
|
Packit |
90a5c9 |
"</httpd:redirect>\n", NULL);
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:busy>%" APR_SIZE_T_FMT "</httpd:busy>\n",
|
|
Packit |
90a5c9 |
worker->s->busy);
|
|
Packit |
90a5c9 |
ap_rprintf(r, " <httpd:lbset>%d</httpd:lbset>\n",
|
|
Packit |
90a5c9 |
worker->s->lbset);
|
|
Packit |
90a5c9 |
/* End proxy_worker_stat */
|
|
Packit |
90a5c9 |
if (!strcasecmp(worker->s->scheme, "ajp")) {
|
|
Packit |
90a5c9 |
ap_rputs(" <httpd:flushpackets>", r);
|
|
Packit |
90a5c9 |
switch (worker->s->flush_packets) {
|
|
Packit |
90a5c9 |
case flush_off:
|
|
Packit |
90a5c9 |
ap_rputs("Off", r);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case flush_on:
|
|
Packit |
90a5c9 |
ap_rputs("On", r);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case flush_auto:
|
|
Packit |
90a5c9 |
ap_rputs("Auto", r);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs("</httpd:flushpackets>\n", r);
|
|
Packit |
90a5c9 |
if (worker->s->flush_packets == flush_auto) {
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:flushwait>%d</httpd:flushwait>\n",
|
|
Packit |
90a5c9 |
worker->s->flush_wait);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (worker->s->ping_timeout_set) {
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:ping>%" APR_TIME_T_FMT "</httpd:ping>",
|
|
Packit |
90a5c9 |
apr_time_msec(worker->s->ping_timeout));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (worker->s->disablereuse_set) {
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:disablereuse>%s</httpd:disablereuse>\n",
|
|
Packit |
90a5c9 |
(worker->s->disablereuse ? "On" : "Off"));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (worker->s->conn_timeout_set) {
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:connectiontimeout>%" APR_TIME_T_FMT "</httpd:connectiontimeout>\n",
|
|
Packit |
90a5c9 |
apr_time_msec(worker->s->conn_timeout));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (worker->s->retry_set) {
|
|
Packit |
90a5c9 |
ap_rprintf(r,
|
|
Packit |
90a5c9 |
" <httpd:retry>%" APR_TIME_T_FMT "</httpd:retry>\n",
|
|
Packit |
90a5c9 |
apr_time_sec(worker->s->retry));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs(" </httpd:worker>\n", r);
|
|
Packit |
90a5c9 |
++workers;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs(" </httpd:workers>\n", r);
|
|
Packit |
90a5c9 |
ap_rputs(" </httpd:balancer>\n", r);
|
|
Packit |
90a5c9 |
++balancer;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs(" </httpd:balancers>\n", r);
|
|
Packit |
90a5c9 |
ap_rputs("</httpd:manager>", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_set_content_type(r, "text/html; charset=ISO-8859-1");
|
|
Packit |
90a5c9 |
ap_rputs(DOCTYPE_HTML_3_2
|
|
Packit |
90a5c9 |
"<html><head><title>Balancer Manager</title>\n", r);
|
|
Packit |
90a5c9 |
ap_rputs("<style type='text/css'>\n"
|
|
Packit |
90a5c9 |
"table {\n"
|
|
Packit |
90a5c9 |
" border-width: 1px;\n"
|
|
Packit |
90a5c9 |
" border-spacing: 3px;\n"
|
|
Packit |
90a5c9 |
" border-style: solid;\n"
|
|
Packit |
90a5c9 |
" border-color: gray;\n"
|
|
Packit |
90a5c9 |
" border-collapse: collapse;\n"
|
|
Packit |
90a5c9 |
" background-color: white;\n"
|
|
Packit |
90a5c9 |
" text-align: center;\n"
|
|
Packit |
90a5c9 |
"}\n"
|
|
Packit |
90a5c9 |
"th {\n"
|
|
Packit |
90a5c9 |
" border-width: 1px;\n"
|
|
Packit |
90a5c9 |
" padding: 2px;\n"
|
|
Packit |
90a5c9 |
" border-style: dotted;\n"
|
|
Packit |
90a5c9 |
" border-color: gray;\n"
|
|
Packit |
90a5c9 |
" background-color: lightgray;\n"
|
|
Packit |
90a5c9 |
" text-align: center;\n"
|
|
Packit |
90a5c9 |
"}\n"
|
|
Packit |
90a5c9 |
"td {\n"
|
|
Packit |
90a5c9 |
" border-width: 1px;\n"
|
|
Packit |
90a5c9 |
" padding: 2px;\n"
|
|
Packit |
90a5c9 |
" border-style: dotted;\n"
|
|
Packit |
90a5c9 |
" border-color: gray;\n"
|
|
Packit |
90a5c9 |
" background-color: white;\n"
|
|
Packit |
90a5c9 |
" text-align: center;\n"
|
|
Packit |
90a5c9 |
"}\n"
|
|
Packit |
90a5c9 |
"</style>\n</head>\n", r);
|
|
Packit |
90a5c9 |
ap_rputs("<body>Load Balancer Manager for ", r);
|
|
Packit |
90a5c9 |
ap_rvputs(r, ap_escape_html(r->pool, ap_get_server_name(r)),
|
|
Packit |
90a5c9 |
"\n\n", NULL);
|
|
Packit |
90a5c9 |
ap_rvputs(r, "- Server Version: ",
|
|
Packit |
90a5c9 |
ap_get_server_description(), "\n", NULL);
|
|
Packit |
90a5c9 |
ap_rvputs(r, "Server Built: ",
|
|
Packit |
90a5c9 |
ap_get_server_built(), "\n", NULL);
|
|
Packit |
90a5c9 |
ap_rvputs(r, "Balancer changes will ", conf->bal_persist ? "" : "NOT ",
|
|
Packit |
90a5c9 |
"be persisted on restart.", NULL);
|
|
Packit |
90a5c9 |
ap_rvputs(r, "Balancers are ", conf->inherit ? "" : "NOT ",
|
|
Packit |
90a5c9 |
"inherited from main server.", NULL);
|
|
Packit |
90a5c9 |
ap_rvputs(r, "ProxyPass settings are ", conf->ppinherit ? "" : "NOT ",
|
|
Packit |
90a5c9 |
"inherited from main server.", NULL);
|
|
Packit |
90a5c9 |
ap_rputs("\n", r);
|
|
Packit |
90a5c9 |
balancer = (proxy_balancer *)conf->balancers->elts;
|
|
Packit |
90a5c9 |
for (i = 0; i < conf->balancers->nelts; i++) {
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_rputs(" \nLoadBalancer Status for ", r);
|
|
Packit |
90a5c9 |
ap_rvputs(r, "
|
|
Packit |
90a5c9 |
balancer->s->name + sizeof(BALANCER_PREFIX) - 1,
|
|
Packit |
90a5c9 |
"&nonce=", balancer->s->nonce,
|
|
Packit |
90a5c9 |
"'>", NULL);
|
|
Packit |
90a5c9 |
ap_rvputs(r, balancer->s->name, " [",balancer->s->sname, "]\n", NULL);
|
|
Packit |
90a5c9 |
ap_rputs("\n\n"
|
|
Packit |
90a5c9 |
"MaxMembersStickySessionDisableFailoverTimeoutFailoverAttemptsMethod"
|
|
Packit |
90a5c9 |
"PathActive\n", r);
|
|
Packit |
90a5c9 |
/* the below is a safe cast, since the number of slots total will
|
|
Packit |
90a5c9 |
* never be more than max_workers, which is restricted to int */
|
|
Packit |
90a5c9 |
ap_rprintf(r, "%d [%d Used]\n", balancer->max_workers,
|
|
Packit |
90a5c9 |
balancer->max_workers - (int)storage->num_free_slots(balancer->wslot));
|
|
Packit |
90a5c9 |
if (*balancer->s->sticky) {
|
|
Packit |
90a5c9 |
if (strcmp(balancer->s->sticky, balancer->s->sticky_path)) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "", balancer->s->sticky, " | ",
|
|
Packit |
90a5c9 |
balancer->s->sticky_path, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "", balancer->s->sticky, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_rputs(" (None) ", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rprintf(r, "%s\n",
|
|
Packit |
90a5c9 |
balancer->s->sticky_force ? "On" : "Off");
|
|
Packit |
90a5c9 |
ap_rprintf(r, "%" APR_TIME_T_FMT "",
|
|
Packit |
90a5c9 |
apr_time_sec(balancer->s->timeout));
|
|
Packit |
90a5c9 |
ap_rprintf(r, "%d\n", balancer->s->max_attempts);
|
|
Packit |
90a5c9 |
ap_rprintf(r, "%s\n",
|
|
Packit |
90a5c9 |
balancer->s->lbpname);
|
|
Packit |
90a5c9 |
ap_rputs("", r);
|
|
Packit |
90a5c9 |
if (*balancer->s->vhost) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, balancer->s->vhost, " -> ", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rvputs(r, balancer->s->vpath, "\n", NULL);
|
|
Packit |
90a5c9 |
ap_rprintf(r, "%s\n",
|
|
Packit |
90a5c9 |
!balancer->s->inactive ? "Yes" : "No");
|
|
Packit |
90a5c9 |
ap_rputs("\n ", r);
|
|
Packit |
90a5c9 |
ap_rputs("\n\n"
|
|
Packit |
90a5c9 |
"Worker URL"
|
|
Packit |
90a5c9 |
"RouteRouteRedir"
|
|
Packit |
90a5c9 |
"FactorSetStatus"
|
|
Packit |
90a5c9 |
"ElectedBusyLoadToFrom", r);
|
|
Packit |
90a5c9 |
if (set_worker_hc_param_f) {
|
|
Packit |
90a5c9 |
ap_rputs("HC MethodHC IntervalPassesFailsHC uriHC Expr", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs("\n", r);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
workers = (proxy_worker **)balancer->workers->elts;
|
|
Packit |
90a5c9 |
for (n = 0; n < balancer->workers->nelts; n++) {
|
|
Packit |
90a5c9 |
char fbuf[50];
|
|
Packit |
90a5c9 |
worker = *workers;
|
|
Packit |
90a5c9 |
ap_rvputs(r, "\n
|
|
Packit |
90a5c9 |
ap_escape_uri(r->pool, r->uri), "?b=",
|
|
Packit |
90a5c9 |
balancer->s->name + sizeof(BALANCER_PREFIX) - 1, "&w=",
|
|
Packit |
90a5c9 |
ap_escape_uri(r->pool, worker->s->name),
|
|
Packit |
90a5c9 |
"&nonce=", balancer->s->nonce,
|
|
Packit |
90a5c9 |
"'>", NULL);
|
|
Packit |
90a5c9 |
ap_rvputs(r, (*worker->s->uds_path ? "" : ""), ap_proxy_worker_name(r->pool, worker),
|
|
Packit |
90a5c9 |
(*worker->s->uds_path ? "" : ""), "", NULL);
|
|
Packit |
90a5c9 |
ap_rvputs(r, "", ap_escape_html(r->pool, worker->s->route),
|
|
Packit |
90a5c9 |
NULL);
|
|
Packit |
90a5c9 |
ap_rvputs(r, "",
|
|
Packit |
90a5c9 |
ap_escape_html(r->pool, worker->s->redirect), NULL);
|
|
Packit |
90a5c9 |
ap_rprintf(r, "%.2f", (float)(worker->s->lbfactor)/100.0);
|
|
Packit |
90a5c9 |
ap_rprintf(r, "%d", worker->s->lbset);
|
|
Packit |
90a5c9 |
ap_rvputs(r, ap_proxy_parse_wstatus(r->pool, worker), NULL);
|
|
Packit |
90a5c9 |
ap_rputs("", r);
|
|
Packit |
90a5c9 |
ap_rprintf(r, "%" APR_SIZE_T_FMT "", worker->s->elected);
|
|
Packit |
90a5c9 |
ap_rprintf(r, "%" APR_SIZE_T_FMT "", worker->s->busy);
|
|
Packit |
90a5c9 |
ap_rprintf(r, "%d", worker->s->lbstatus);
|
|
Packit |
90a5c9 |
ap_rputs(apr_strfsize(worker->s->transferred, fbuf), r);
|
|
Packit |
90a5c9 |
ap_rputs("", r);
|
|
Packit |
90a5c9 |
ap_rputs(apr_strfsize(worker->s->read, fbuf), r);
|
|
Packit |
90a5c9 |
if (set_worker_hc_param_f) {
|
|
Packit |
90a5c9 |
ap_rprintf(r, "%s", ap_proxy_show_hcmethod(worker->s->method));
|
|
Packit |
90a5c9 |
ap_rprintf(r, "%" APR_TIME_T_FMT "ms", apr_time_as_msec(worker->s->interval));
|
|
Packit |
90a5c9 |
ap_rprintf(r, "%d (%d)", worker->s->passes,worker->s->pcount);
|
|
Packit |
90a5c9 |
ap_rprintf(r, "%d (%d)", worker->s->fails, worker->s->fcount);
|
|
Packit |
90a5c9 |
ap_rprintf(r, "%s", worker->s->hcuri);
|
|
Packit |
90a5c9 |
ap_rprintf(r, "%s", worker->s->hcexpr);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs("\n", r);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
++workers;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs("\n", r);
|
|
Packit |
90a5c9 |
++balancer;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs(" \n", r);
|
|
Packit |
90a5c9 |
if (hc_show_exprs_f) {
|
|
Packit |
90a5c9 |
hc_show_exprs_f(r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (wsel && bsel) {
|
|
Packit |
90a5c9 |
ap_rputs("Edit worker settings for ", r);
|
|
Packit |
90a5c9 |
ap_rvputs(r, (*wsel->s->uds_path?"":""), ap_proxy_worker_name(r->pool, wsel), (*wsel->s->uds_path?"":""), "\n", NULL);
|
|
Packit |
90a5c9 |
ap_rputs("
|
|
Packit |
90a5c9 |
ap_rvputs(r, ap_escape_uri(r->pool, action), "'>\n", NULL);
|
|
Packit |
90a5c9 |
ap_rputs("
|
|
Packit |
90a5c9 |
ap_rprintf(r, "value='%.2f'>\n", (float)(wsel->s->lbfactor)/100.0);
|
|
Packit |
90a5c9 |
ap_rputs("LB Set:
|
|
Packit |
90a5c9 |
ap_rprintf(r, "value='%d'>\n", wsel->s->lbset);
|
|
Packit |
90a5c9 |
ap_rputs("Route:
|
|
Packit |
90a5c9 |
ap_rvputs(r, "value='", ap_escape_html(r->pool, wsel->s->route),
|
|
Packit |
90a5c9 |
NULL);
|
|
Packit |
90a5c9 |
ap_rputs("'>\n", r);
|
|
Packit |
90a5c9 |
ap_rputs("Route Redirect:
|
|
Packit |
90a5c9 |
ap_rvputs(r, "value='", ap_escape_html(r->pool, wsel->s->redirect),
|
|
Packit |
90a5c9 |
NULL);
|
|
Packit |
90a5c9 |
ap_rputs("'>\n", r);
|
|
Packit |
90a5c9 |
ap_rputs("Status:", r);
|
|
Packit |
90a5c9 |
ap_rputs(""
|
|
Packit |
90a5c9 |
"Ignore Errors"
|
|
Packit |
90a5c9 |
"Draining Mode"
|
|
Packit |
90a5c9 |
"Disabled"
|
|
Packit |
90a5c9 |
"Hot Standby"
|
|
Packit |
90a5c9 |
"Hot Spare", r);
|
|
Packit |
90a5c9 |
if (hc_show_exprs_f) {
|
|
Packit |
90a5c9 |
ap_rputs("HC Fail", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs("Stopped\n", r);
|
|
Packit |
90a5c9 |
create_radio("w_status_I", (PROXY_WORKER_IS(wsel, PROXY_WORKER_IGNORE_ERRORS)), r);
|
|
Packit |
90a5c9 |
create_radio("w_status_N", (PROXY_WORKER_IS(wsel, PROXY_WORKER_DRAIN)), r);
|
|
Packit |
90a5c9 |
create_radio("w_status_D", (PROXY_WORKER_IS(wsel, PROXY_WORKER_DISABLED)), r);
|
|
Packit |
90a5c9 |
create_radio("w_status_H", (PROXY_WORKER_IS(wsel, PROXY_WORKER_HOT_STANDBY)), r);
|
|
Packit |
90a5c9 |
create_radio("w_status_R", (PROXY_WORKER_IS(wsel, PROXY_WORKER_HOT_SPARE)), r);
|
|
Packit |
90a5c9 |
if (hc_show_exprs_f) {
|
|
Packit |
90a5c9 |
create_radio("w_status_C", (PROXY_WORKER_IS(wsel, PROXY_WORKER_HC_FAIL)), r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
create_radio("w_status_S", (PROXY_WORKER_IS(wsel, PROXY_WORKER_STOPPED)), r);
|
|
Packit |
90a5c9 |
ap_rputs("\n", r);
|
|
Packit |
90a5c9 |
if (hc_select_exprs_f) {
|
|
Packit |
90a5c9 |
proxy_hcmethods_t *method = proxy_hcmethods;
|
|
Packit |
90a5c9 |
ap_rputs("\n\n", r);
|
|
Packit |
90a5c9 |
ap_rputs("Method<select name='w_hm'>\n", r);
|
|
Packit |
90a5c9 |
for (; method->name; method++) {
|
|
Packit |
90a5c9 |
if (method->implemented) {
|
|
Packit |
90a5c9 |
ap_rprintf(r, "<option value='%s' %s >%s</option>\n",
|
|
Packit |
90a5c9 |
method->name,
|
|
Packit |
90a5c9 |
(wsel->s->method == method->method) ? "selected" : "",
|
|
Packit |
90a5c9 |
method->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs("</select>\n\n", r);
|
|
Packit |
90a5c9 |
ap_rputs("Expr<select name='w_he'>\n", r);
|
|
Packit |
90a5c9 |
hc_select_exprs_f(r, wsel->s->hcexpr);
|
|
Packit |
90a5c9 |
ap_rputs("</select>\n\n", r);
|
|
Packit |
90a5c9 |
ap_rprintf(r, "Interval (ms)
|
|
Packit |
90a5c9 |
"value='%" APR_TIME_T_FMT "'>\n", apr_time_as_msec(wsel->s->interval));
|
|
Packit |
90a5c9 |
ap_rprintf(r, "Passes trigger
|
|
Packit |
90a5c9 |
"value='%d'>\n", wsel->s->passes);
|
|
Packit |
90a5c9 |
ap_rprintf(r, "Fails trigger)
|
|
Packit |
90a5c9 |
"value='%d'>\n", wsel->s->fails);
|
|
Packit |
90a5c9 |
ap_rprintf(r, "HC uri
|
|
Packit |
90a5c9 |
"value='%s'\n", ap_escape_html(r->pool, wsel->s->hcuri));
|
|
Packit |
90a5c9 |
ap_rputs("\n\n", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs("<input type=submit value='Submit'>\n", r);
|
|
Packit |
90a5c9 |
ap_rvputs(r, "\n
|
|
Packit |
90a5c9 |
ap_rvputs(r, "value='", ap_escape_uri(r->pool, wsel->s->name), "'>\n", NULL);
|
|
Packit |
90a5c9 |
ap_rvputs(r, "
|
|
Packit |
90a5c9 |
ap_rvputs(r, "value='", bsel->s->name + sizeof(BALANCER_PREFIX) - 1,
|
|
Packit |
90a5c9 |
"'>\n", NULL);
|
|
Packit |
90a5c9 |
ap_rvputs(r, "
|
|
Packit |
90a5c9 |
bsel->s->nonce, "'>\n", NULL);
|
|
Packit |
90a5c9 |
ap_rputs("</form>\n", r);
|
|
Packit |
90a5c9 |
ap_rputs(" \n", r);
|
|
Packit |
90a5c9 |
} else if (bsel) {
|
|
Packit |
90a5c9 |
const apr_array_header_t *provs;
|
|
Packit |
90a5c9 |
const ap_list_provider_names_t *pname;
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
ap_rputs("Edit balancer settings for ", r);
|
|
Packit |
90a5c9 |
ap_rvputs(r, bsel->s->name, "\n", NULL);
|
|
Packit |
90a5c9 |
ap_rputs("
|
|
Packit |
90a5c9 |
ap_rvputs(r, ap_escape_uri(r->pool, action), "'>\n", NULL);
|
|
Packit |
90a5c9 |
ap_rputs("\n", r);
|
|
Packit |
90a5c9 |
provs = ap_list_provider_names(r->pool, PROXY_LBMETHOD, "0");
|
|
Packit |
90a5c9 |
if (provs) {
|
|
Packit |
90a5c9 |
ap_rputs("LBmethod:", r);
|
|
Packit |
90a5c9 |
ap_rputs("\n<select name='b_lbm' id='b_lbm'>", r);
|
|
Packit |
90a5c9 |
pname = (ap_list_provider_names_t *)provs->elts;
|
|
Packit |
90a5c9 |
for (i = 0; i < provs->nelts; i++, pname++) {
|
|
Packit |
90a5c9 |
ap_rvputs(r,"
|
|
Packit |
90a5c9 |
if (strcmp(pname->provider_name, bsel->s->lbpname) == 0)
|
|
Packit |
90a5c9 |
ap_rputs(" selected ", r);
|
|
Packit |
90a5c9 |
ap_rvputs(r, ">", pname->provider_name, "\n", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs("</select>\n\n", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs("Timeout:
|
|
Packit |
90a5c9 |
ap_rprintf(r, "value='%" APR_TIME_T_FMT "'>\n", apr_time_sec(bsel->s->timeout));
|
|
Packit |
90a5c9 |
ap_rputs("Failover Attempts:
|
|
Packit |
90a5c9 |
ap_rprintf(r, "value='%d'>\n", bsel->s->max_attempts);
|
|
Packit |
90a5c9 |
ap_rputs("Disable Failover:", r);
|
|
Packit |
90a5c9 |
create_radio("b_sforce", bsel->s->sticky_force, r);
|
|
Packit |
90a5c9 |
ap_rputs("Sticky Session:
|
|
Packit |
90a5c9 |
if (strcmp(bsel->s->sticky, bsel->s->sticky_path)) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "value ='", bsel->s->sticky, " | ",
|
|
Packit |
90a5c9 |
bsel->s->sticky_path, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "value ='", bsel->s->sticky, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs("'> (Use '-' to delete)\n", r);
|
|
Packit |
90a5c9 |
if (storage->num_free_slots(bsel->wslot) != 0) {
|
|
Packit |
90a5c9 |
ap_rputs("Add New Worker:<input name='b_nwrkr' id='b_nwrkr' size=32 type=text>"
|
|
Packit |
90a5c9 |
" Are you sure? <input name='b_wyes' id='b_wyes' type=checkbox value='1'>"
|
|
Packit |
90a5c9 |
"", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs("<input type=submit value='Submit'>\n", r);
|
|
Packit |
90a5c9 |
ap_rvputs(r, "\n
|
|
Packit |
90a5c9 |
ap_rvputs(r, "value='", bsel->s->name + sizeof(BALANCER_PREFIX) - 1,
|
|
Packit |
90a5c9 |
"'>\n", NULL);
|
|
Packit |
90a5c9 |
ap_rvputs(r, "
|
|
Packit |
90a5c9 |
bsel->s->nonce, "'>\n", NULL);
|
|
Packit |
90a5c9 |
ap_rputs("</form>\n", r);
|
|
Packit |
90a5c9 |
ap_rputs(" \n", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs(ap_psignature("",r), r);
|
|
Packit |
90a5c9 |
ap_rputs("</body></html>\n", r);
|
|
Packit |
90a5c9 |
ap_rflush(r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return DONE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void balancer_child_init(apr_pool_t *p, server_rec *s)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
while (s) {
|
|
Packit |
90a5c9 |
proxy_balancer *balancer;
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
void *sconf = s->module_config;
|
|
Packit |
90a5c9 |
proxy_server_conf *conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (conf->balancers->nelts) {
|
|
Packit |
90a5c9 |
apr_size_t size;
|
|
Packit |
90a5c9 |
unsigned int num;
|
|
Packit |
90a5c9 |
storage->attach(&(conf->bslot), conf->id, &size, &num, p);
|
|
Packit |
90a5c9 |
if (!conf->bslot) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01205) "slotmem_attach failed");
|
|
Packit |
90a5c9 |
exit(1); /* Ugly, but what else? */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
balancer = (proxy_balancer *)conf->balancers->elts;
|
|
Packit |
90a5c9 |
for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
|
|
Packit |
90a5c9 |
rv = ap_proxy_initialize_balancer(balancer, s, p);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s, APLOGNO(01206)
|
|
Packit |
90a5c9 |
"Failed to init balancer %s in child",
|
|
Packit |
90a5c9 |
balancer->s->name);
|
|
Packit |
90a5c9 |
exit(1); /* Ugly, but what else? */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
init_balancer_members(conf->pool, s, balancer);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
s = s->next;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void ap_proxy_balancer_register_hook(apr_pool_t *p)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
/* Only the mpm_winnt has child init hook handler.
|
|
Packit |
90a5c9 |
* make sure that we are called after the mpm
|
|
Packit |
90a5c9 |
* initializes
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static const char *const aszPred[] = { "mpm_winnt.c", "mod_slotmem_shm.c", NULL};
|
|
Packit |
90a5c9 |
static const char *const aszPred2[] = { "mod_proxy.c", NULL};
|
|
Packit |
90a5c9 |
/* manager handler */
|
|
Packit |
90a5c9 |
ap_hook_post_config(balancer_post_config, aszPred2, NULL, APR_HOOK_MIDDLE);
|
|
Packit |
90a5c9 |
ap_hook_pre_config(balancer_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
|
|
Packit |
90a5c9 |
ap_hook_handler(balancer_handler, NULL, NULL, APR_HOOK_FIRST);
|
|
Packit |
90a5c9 |
ap_hook_child_init(balancer_child_init, aszPred, NULL, APR_HOOK_MIDDLE);
|
|
Packit |
90a5c9 |
proxy_hook_pre_request(proxy_balancer_pre_request, NULL, NULL, APR_HOOK_FIRST);
|
|
Packit |
90a5c9 |
proxy_hook_post_request(proxy_balancer_post_request, NULL, NULL, APR_HOOK_FIRST);
|
|
Packit |
90a5c9 |
proxy_hook_canon_handler(proxy_balancer_canon, NULL, NULL, APR_HOOK_FIRST);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE_MODULE(proxy_balancer) = {
|
|
Packit |
90a5c9 |
STANDARD20_MODULE_STUFF,
|
|
Packit |
90a5c9 |
NULL, /* create per-directory config structure */
|
|
Packit |
90a5c9 |
NULL, /* merge per-directory config structures */
|
|
Packit |
90a5c9 |
NULL, /* create per-server config structure */
|
|
Packit |
90a5c9 |
NULL, /* merge per-server config structures */
|
|
Packit |
90a5c9 |
NULL, /* command apr_table_t */
|
|
Packit |
90a5c9 |
ap_proxy_balancer_register_hook /* register hooks */
|
|
Packit |
90a5c9 |
};
|