Permalink
Browse files

Merge remote branch 'remotes/piotr/master'

Conflicts:
	ngx_http_healthcheck_module.c
	sample_ngx_config.conf
  • Loading branch information...
2 parents aa5d5c2 + a1eded3 commit fda3153393e2631555928e76f38f160255b1444e @cep21 committed May 13, 2010
Showing with 75 additions and 7 deletions.
  1. +44 −0 nginx.patch
  2. +22 −7 ngx_http_healthcheck_module.c
  3. +9 −0 ngx_http_healthcheck_module.h
View
@@ -49,3 +49,47 @@ index 97ec71b..ff2772a 100644
ngx_uint_t flags;
ngx_str_t host;
u_char *file_name;
+--- src/http/ngx_http_upstream_round_robin.c.orig Mon Mar 8 20:55:32 2010
++++ src/http/ngx_http_upstream_round_robin.c Mon Mar 8 21:03:17 2010
+@@ -4,6 +4,8 @@
+ */
+
+
++/* on top, so it won't collide with ngx_supervisord's patch */
++#include <ngx_http_healthcheck_module.h>
+ #include <ngx_config.h>
+ #include <ngx_core.h>
+ #include <ngx_http.h>
+@@ -55,6 +57,7 @@
+ ngx_uint_t i, j, n;
+ ngx_http_upstream_server_t *server;
+ ngx_http_upstream_rr_peers_t *peers, *backup;
++ ngx_int_t health_index;
+
+ us->peer.init = ngx_http_upstream_init_round_robin_peer;
+
+@@ -91,6 +94,14 @@
+ if (server[i].backup) {
+ continue;
+ }
++
++ /* on top, so it won't collide with ngx_supervisord's patch */
++ health_index = ngx_http_healthcheck_add_peer(us,
++ &server[i].addrs[j], cf->pool);
++ if (health_index == NGX_ERROR) {
++ return NGX_ERROR;
++ }
++ peers->peer[n].health_index = health_index;
+
+ peers->peer[n].sockaddr = server[i].addrs[j].sockaddr;
+ peers->peer[n].socklen = server[i].addrs[j].socklen;
+--- src/http/ngx_http_upstream_round_robin.h.orig Mon Mar 8 21:00:58 2010
++++ src/http/ngx_http_upstream_round_robin.h Mon Mar 8 21:00:06 2010
+@@ -28,6 +28,7 @@
+
+ ngx_uint_t max_fails;
+ time_t fail_timeout;
++ ngx_int_t health_index;
+
+ ngx_uint_t down; /* unsigned down:1; */
+
@@ -69,7 +69,11 @@ typedef struct {
// Upstream this peer belongs to
ngx_http_upstream_srv_conf_t *conf;
// The peer to check
+#if defined(nginx_version) && nginx_version >= 8022
+ ngx_addr_t *peer;
+#else
ngx_peer_addr_t *peer;
+#endif
// Index of the peer. Matches shm segment and is used for 'down' checking
// by external clients
ngx_uint_t index;
@@ -295,19 +299,25 @@ void ngx_http_healthcheck_mark_finished(ngx_http_healthcheck_status_t *stat) {
stat->shm->action_time = ngx_current_msec;
}
+void ngx_http_healthcheck_send_request(ngx_connection_t *);
+
void ngx_http_healthcheck_write_handler(ngx_event_t *wev) {
ngx_connection_t *c;
- ssize_t size;
- ngx_http_healthcheck_status_t *stat;
c = wev->data;
- stat = c->data;
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0,
"healthcheck: Write handler called");
+ ngx_http_healthcheck_send_request(c);
+}
+
+void ngx_http_healthcheck_send_request(ngx_connection_t *c) {
+ ngx_http_healthcheck_status_t *stat = c->data;
+ ssize_t size;
+
if (stat->state != NGX_HEALTH_SENDING_CHECK) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0,
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
"healthcheck: Ignoring a write. Not in writing state");
return;
}
@@ -316,7 +326,7 @@ void ngx_http_healthcheck_write_handler(ngx_event_t *wev) {
size =
c->send(c, stat->conf->health_send.data + stat->send_pos,
stat->conf->health_send.len - stat->send_pos);
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, wev->log, 0,
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
"healthcheck: Send size %z", size);
if (size == NGX_ERROR || size == 0) {
// If the send fails, the connection is bad. Close it out
@@ -334,11 +344,11 @@ void ngx_http_healthcheck_write_handler(ngx_event_t *wev) {
} while (stat->send_pos < (ssize_t)stat->conf->health_send.len);
if (stat->send_pos > (ssize_t)stat->conf->health_send.len) {
- ngx_log_error(NGX_LOG_WARN, wev->log, 0,
+ ngx_log_error(NGX_LOG_WARN, c->log, 0,
"healthcheck: Logic error. %z send pos bigger than buffer len %i",
stat->send_pos, stat->conf->health_send.len);
} else if (stat->send_pos == (ssize_t)stat->conf->health_send.len) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0,
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
"healthcheck: Finished sending request");
stat->state = NGX_HEALTH_READING_STAT_LINE;
}
@@ -584,6 +594,7 @@ static void ngx_http_healthcheck_begin_healthcheck(ngx_event_t *event) {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, event->log, 0,
"healthcheck: Peer connected", stat->index);
+ ngx_http_healthcheck_send_request(c);
}
static void ngx_http_healthcheck_try_for_ownership(ngx_event_t *event) {
@@ -762,7 +773,11 @@ ngx_http_healthcheck_init_zone(ngx_shm_zone_t *shm_zone, void *data) {
// --- BEGIN PUBLIC METHODS ---
ngx_int_t
ngx_http_healthcheck_add_peer(ngx_http_upstream_srv_conf_t *uscf,
+#if defined(nginx_version) && nginx_version >= 8022
+ ngx_addr_t *peer, ngx_pool_t *pool) {
+#else
ngx_peer_addr_t *peer, ngx_pool_t *pool) {
+#endif
ngx_http_healthcheck_status_t *status;
status = ngx_array_push(ngx_http_healthchecks_arr);
if (status == NULL) {
@@ -1,6 +1,10 @@
#ifndef _NGX_HEALTHCHECK_MODULE_H_
#define _NGX_HEALTHCHECK_MODULE_H_
+#include <ngx_core.h>
+#include <ngx_http.h>
+#include <nginx.h>
+
// I don't define everything here, just the stuff external users will
// want to call
@@ -14,8 +18,13 @@
* @return Integer identifier for this healthcheck or NGX_ERROR if stuff
* went bad.
*/
+#if defined(nginx_version) && nginx_version >= 8022
+ngx_int_t ngx_http_healthcheck_add_peer(ngx_http_upstream_srv_conf_t *uscf,
+ ngx_addr_t *peer, ngx_pool_t *pool);
+#else
ngx_int_t ngx_http_healthcheck_add_peer(ngx_http_upstream_srv_conf_t *uscf,
ngx_peer_addr_t *peer, ngx_pool_t *pool);
+#endif
/**
* Check the health of a peer

0 comments on commit fda3153

Please sign in to comment.