Permalink
Browse files

add mysql check, modify the smtp parser.

  • Loading branch information...
1 parent dd222ae commit 4f3868e9a0b0e1db370498ff24a6305853261e1c @yaoweibin committed Apr 2, 2010
Showing with 7,056 additions and 23 deletions.
  1. +22 −2 README
  2. +1 −1 config
  3. +16 −0 ngx_tcp_upstream.c
  4. +218 −20 ngx_tcp_upstream_check.c
  5. +43 −0 ngx_tcp_upstream_check.h
  6. +6,546 −0 smtp_response_parse.c
  7. +162 −0 smtp_response_parse.rl
  8. +48 −0 test/t/mysql_check.t
View
24 README
@@ -144,7 +144,7 @@ Directives
==check==
syntax: check interval=milliseconds [fall=count] [rise=count]
- [timeout=milliseconds] [type=tcp|ssl_hello]
+ [timeout=milliseconds] [type=tcp|ssl_hello|smtp|mysql]
default: none, if parameters omitted, default parameters are 'interval=30000
fall=5 rise=2 timeout=1000'
context: upstream
@@ -161,8 +161,13 @@ Directives
'tcp' is a simple tcp socket connect and peek one byte.
'ssl_hello' sends a client ssl hello packet and receives the server
ssl hello packet.
- 'http' sends a http requst packet and recvives and parses the http
+ 'http' sends a http requst packet, recvives and parses the http
response to diagnose if the upstream server is alive.
+ 'smtp' sends a smtp requst packet, recvives and parses the smtp
+ response to diagnose if the upstream server is alive. The response
+ begins with '2' will be judged to be a OK response.
+ 'mysql' connects to the mysql server, recvives the greeting response
+ to diagnose if the upstream server is alive.
==check_http_send=
syntax: check_http_send http_packet
@@ -178,6 +183,21 @@ Directives
description: These status codes indicate the upstream server's http response
is ok, the backend is alive.
+ ==check_smtp_send=
+ syntax: check_smtp_send smtp_packet
+ default: "HELO smtp.localdomain\r\n"
+ context: upstream
+ description: If you set the check type is smtp, then the check function will
+ sends this smtp packet to check the upstream server.
+
+ ==check_smtp_expect_alive=
+ syntax: check_smtp_expect_alive [smtp_2xx | smtp_3xx | smtp_4xx | smtp_5xx]
+ default: check_smtp_expect_alive smtp_2xx;
+ context: upstream
+ description: These status codes indicate the upstream server's smtp response
+ is ok, the backend is alive.
+
+
==check_shm_size==
syntax: check_shm_size size
default: (number_of_checked_upstream_blocks + 1) * pagesize
View
2 config
@@ -4,7 +4,7 @@ ngx_feature_run=no
ngx_feature_incs=
ngx_feature_path="$ngx_addon_dir/modules $ngx_addon_dir"
ngx_feature_deps="$ngx_addon_dir/ngx_tcp.h $ngx_addon_dir/ngx_tcp_session.h $ngx_addon_dir/ngx_tcp_upstream.h $ngx_addon_dir/ngx_tcp_upstream_check.h $ngx_addon_dir/ngx_tcp_upstream_round_robin.h"
-ngx_tcp_src="$ngx_addon_dir/ngx_tcp.c $ngx_addon_dir/ngx_tcp_core_module.c $ngx_addon_dir/ngx_tcp_session.c $ngx_addon_dir/ngx_tcp_upstream.c $ngx_addon_dir/ngx_tcp_upstream_round_robin.c $ngx_addon_dir/modules/ngx_tcp_proxy_module.c $ngx_addon_dir/modules/ngx_tcp_upstream_ip_hash_module.c $ngx_addon_dir/ngx_tcp_upstream_check.c $ngx_addon_dir/http_response_parse.c"
+ngx_tcp_src="$ngx_addon_dir/ngx_tcp.c $ngx_addon_dir/ngx_tcp_core_module.c $ngx_addon_dir/ngx_tcp_session.c $ngx_addon_dir/ngx_tcp_upstream.c $ngx_addon_dir/ngx_tcp_upstream_round_robin.c $ngx_addon_dir/modules/ngx_tcp_proxy_module.c $ngx_addon_dir/modules/ngx_tcp_upstream_ip_hash_module.c $ngx_addon_dir/ngx_tcp_upstream_check.c $ngx_addon_dir/http_response_parse.c $ngx_addon_dir/smtp_response_parse.c"
ngx_feature_test="int a;"
. auto/feature
View
@@ -29,6 +29,14 @@ static ngx_conf_bitmask_t ngx_check_http_expect_alive_masks[] = {
{ ngx_null_string, 0 }
};
+static ngx_conf_bitmask_t ngx_check_smtp_expect_alive_masks[] = {
+ { ngx_string("smtp_2xx"), NGX_CHECK_SMTP_2XX },
+ { ngx_string("smtp_3xx"), NGX_CHECK_SMTP_3XX },
+ { ngx_string("smtp_4xx"), NGX_CHECK_SMTP_4XX },
+ { ngx_string("smtp_5xx"), NGX_CHECK_SMTP_5XX },
+ { ngx_null_string, 0 }
+};
+
static ngx_command_t ngx_tcp_upstream_commands[] = {
{ ngx_string("upstream"),
@@ -73,6 +81,13 @@ static ngx_command_t ngx_tcp_upstream_commands[] = {
offsetof(ngx_tcp_upstream_srv_conf_t, status_alive),
&ngx_check_http_expect_alive_masks },
+ { ngx_string("check_smtp_expect_alive"),
+ NGX_TCP_UPS_CONF|NGX_CONF_1MORE,
+ ngx_conf_set_bitmask_slot,
+ NGX_TCP_SRV_CONF_OFFSET,
+ offsetof(ngx_tcp_upstream_srv_conf_t, status_alive),
+ &ngx_check_smtp_expect_alive_masks },
+
{ ngx_string("check_shm_size"),
NGX_TCP_MAIN_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
@@ -647,6 +662,7 @@ ngx_tcp_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags) {
uscf->line = cf->conf_file->line;
uscf->port = u->port;
uscf->default_port = u->default_port;
+ uscf->status_alive = 0;
if (u->naddrs == 1) {
uscf->servers = ngx_array_create(cf->pool, 1,
Oops, something went wrong.

0 comments on commit 4f3868e

Please sign in to comment.