Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Health-checks functions. |
| 3 | * |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 4 | * Copyright 2000-2009 Willy Tarreau <w@1wt.eu> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 5 | * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
Willy Tarreau | b881608 | 2008-01-18 12:18:15 +0100 | [diff] [blame] | 14 | #include <assert.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 15 | #include <ctype.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 16 | #include <errno.h> |
| 17 | #include <fcntl.h> |
| 18 | #include <stdio.h> |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 19 | #include <stdlib.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 20 | #include <string.h> |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 21 | #include <time.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 22 | #include <unistd.h> |
| 23 | #include <sys/socket.h> |
Dmitry Sivachenko | caf5898 | 2009-08-24 15:11:06 +0400 | [diff] [blame] | 24 | #include <sys/types.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 25 | #include <netinet/in.h> |
Willy Tarreau | 1274bc4 | 2009-07-15 07:16:31 +0200 | [diff] [blame] | 26 | #include <netinet/tcp.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 27 | #include <arpa/inet.h> |
| 28 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 29 | #include <common/compat.h> |
| 30 | #include <common/config.h> |
| 31 | #include <common/mini-clist.h> |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 32 | #include <common/standard.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 33 | #include <common/time.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 34 | |
| 35 | #include <types/global.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 36 | |
| 37 | #include <proto/backend.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 38 | #include <proto/checks.h> |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 39 | #include <proto/buffers.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 40 | #include <proto/fd.h> |
| 41 | #include <proto/log.h> |
| 42 | #include <proto/queue.h> |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 43 | #include <proto/port_range.h> |
Willy Tarreau | 3d30059 | 2007-03-18 18:34:41 +0100 | [diff] [blame] | 44 | #include <proto/proto_http.h> |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 45 | #include <proto/proto_tcp.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 46 | #include <proto/proxy.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 47 | #include <proto/server.h> |
| 48 | #include <proto/task.h> |
| 49 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 50 | const struct check_status check_statuses[HCHK_STATUS_SIZE] = { |
| 51 | [HCHK_STATUS_UNKNOWN] = { SRV_CHK_UNKNOWN, "UNK", "Unknown" }, |
| 52 | [HCHK_STATUS_INI] = { SRV_CHK_UNKNOWN, "INI", "Initializing" }, |
| 53 | [HCHK_STATUS_START] = { /* SPECIAL STATUS*/ }, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 54 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 55 | [HCHK_STATUS_HANA] = { SRV_CHK_ERROR, "HANA", "Health analyze" }, |
| 56 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 57 | [HCHK_STATUS_SOCKERR] = { SRV_CHK_ERROR, "SOCKERR", "Socket error" }, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 58 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 59 | [HCHK_STATUS_L4OK] = { SRV_CHK_RUNNING, "L4OK", "Layer4 check passed" }, |
| 60 | [HCHK_STATUS_L4TOUT] = { SRV_CHK_ERROR, "L4TOUT", "Layer4 timeout" }, |
| 61 | [HCHK_STATUS_L4CON] = { SRV_CHK_ERROR, "L4CON", "Layer4 connection problem" }, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 62 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 63 | [HCHK_STATUS_L6OK] = { SRV_CHK_RUNNING, "L6OK", "Layer6 check passed" }, |
| 64 | [HCHK_STATUS_L6TOUT] = { SRV_CHK_ERROR, "L6TOUT", "Layer6 timeout" }, |
| 65 | [HCHK_STATUS_L6RSP] = { SRV_CHK_ERROR, "L6RSP", "Layer6 invalid response" }, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 66 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 67 | [HCHK_STATUS_L7TOUT] = { SRV_CHK_ERROR, "L7TOUT", "Layer7 timeout" }, |
| 68 | [HCHK_STATUS_L7RSP] = { SRV_CHK_ERROR, "L7RSP", "Layer7 invalid response" }, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 69 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 70 | [HCHK_STATUS_L57DATA] = { /* DUMMY STATUS */ }, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 71 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 72 | [HCHK_STATUS_L7OKD] = { SRV_CHK_RUNNING, "L7OK", "Layer7 check passed" }, |
| 73 | [HCHK_STATUS_L7OKCD] = { SRV_CHK_RUNNING | SRV_CHK_DISABLE, "L7OKC", "Layer7 check conditionally passed" }, |
| 74 | [HCHK_STATUS_L7STS] = { SRV_CHK_ERROR, "L7STS", "Layer7 wrong status" }, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 75 | }; |
| 76 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 77 | const struct analyze_status analyze_statuses[HANA_STATUS_SIZE] = { /* 0: ignore, 1: error, 2: OK */ |
| 78 | [HANA_STATUS_UNKNOWN] = { "Unknown", { 0, 0 }}, |
| 79 | |
| 80 | [HANA_STATUS_L4_OK] = { "L4 successful connection", { 2, 0 }}, |
| 81 | [HANA_STATUS_L4_ERR] = { "L4 unsuccessful connection", { 1, 1 }}, |
| 82 | |
| 83 | [HANA_STATUS_HTTP_OK] = { "Correct http response", { 0, 2 }}, |
| 84 | [HANA_STATUS_HTTP_STS] = { "Wrong http response", { 0, 1 }}, |
| 85 | [HANA_STATUS_HTTP_HDRRSP] = { "Invalid http response (headers)", { 0, 1 }}, |
| 86 | [HANA_STATUS_HTTP_RSP] = { "Invalid http response", { 0, 1 }}, |
| 87 | |
| 88 | [HANA_STATUS_HTTP_READ_ERROR] = { "Read error (http)", { 0, 1 }}, |
| 89 | [HANA_STATUS_HTTP_READ_TIMEOUT] = { "Read timeout (http)", { 0, 1 }}, |
| 90 | [HANA_STATUS_HTTP_BROKEN_PIPE] = { "Close from server (http)", { 0, 1 }}, |
| 91 | }; |
| 92 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 93 | /* |
| 94 | * Convert check_status code to description |
| 95 | */ |
| 96 | const char *get_check_status_description(short check_status) { |
| 97 | |
| 98 | const char *desc; |
| 99 | |
| 100 | if (check_status < HCHK_STATUS_SIZE) |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 101 | desc = check_statuses[check_status].desc; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 102 | else |
| 103 | desc = NULL; |
| 104 | |
| 105 | if (desc && *desc) |
| 106 | return desc; |
| 107 | else |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 108 | return check_statuses[HCHK_STATUS_UNKNOWN].desc; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /* |
| 112 | * Convert check_status code to short info |
| 113 | */ |
| 114 | const char *get_check_status_info(short check_status) { |
| 115 | |
| 116 | const char *info; |
| 117 | |
| 118 | if (check_status < HCHK_STATUS_SIZE) |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 119 | info = check_statuses[check_status].info; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 120 | else |
| 121 | info = NULL; |
| 122 | |
| 123 | if (info && *info) |
| 124 | return info; |
| 125 | else |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 126 | return check_statuses[HCHK_STATUS_UNKNOWN].info; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 127 | } |
| 128 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 129 | const char *get_analyze_status(short analyze_status) { |
| 130 | |
| 131 | const char *desc; |
| 132 | |
| 133 | if (analyze_status < HANA_STATUS_SIZE) |
| 134 | desc = analyze_statuses[analyze_status].desc; |
| 135 | else |
| 136 | desc = NULL; |
| 137 | |
| 138 | if (desc && *desc) |
| 139 | return desc; |
| 140 | else |
| 141 | return analyze_statuses[HANA_STATUS_UNKNOWN].desc; |
| 142 | } |
| 143 | |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 144 | #define SSP_O_HCHK 0x0002 |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 145 | |
| 146 | static void server_status_printf(struct chunk *msg, struct server *s, unsigned options, int xferred) { |
| 147 | |
Krzysztof Piotr Oledzki | 5f5b7d2 | 2010-01-11 11:13:39 +0100 | [diff] [blame] | 148 | if (s->tracked) |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 149 | chunk_printf(msg, " via %s/%s", |
| 150 | s->tracked->proxy->id, s->tracked->id); |
| 151 | |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 152 | if (options & SSP_O_HCHK) { |
| 153 | chunk_printf(msg, ", reason: %s", get_check_status_description(s->check_status)); |
| 154 | |
| 155 | if (s->check_status >= HCHK_STATUS_L57DATA) |
| 156 | chunk_printf(msg, ", code: %d", s->check_code); |
| 157 | |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 158 | if (*s->check_desc) { |
| 159 | struct chunk src; |
| 160 | |
| 161 | chunk_printf(msg, ", info: \""); |
| 162 | |
| 163 | chunk_initlen(&src, s->check_desc, 0, strlen(s->check_desc)); |
| 164 | chunk_asciiencode(msg, &src, '"'); |
| 165 | |
| 166 | chunk_printf(msg, "\""); |
| 167 | } |
| 168 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 169 | if (s->check_duration >= 0) |
| 170 | chunk_printf(msg, ", check duration: %ldms", s->check_duration); |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 171 | } |
| 172 | |
Krzysztof Piotr Oledzki | 5f5b7d2 | 2010-01-11 11:13:39 +0100 | [diff] [blame] | 173 | if (xferred > 0) { |
Krzysztof Piotr Oledzki | b16a607 | 2010-01-10 21:12:58 +0100 | [diff] [blame] | 174 | if (!(s->state & SRV_RUNNING)) |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 175 | chunk_printf(msg, ". %d active and %d backup servers left.%s" |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 176 | " %d sessions active, %d requeued, %d remaining in queue", |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 177 | s->proxy->srv_act, s->proxy->srv_bck, |
| 178 | (s->proxy->srv_bck && !s->proxy->srv_act) ? " Running on backup." : "", |
| 179 | s->cur_sess, xferred, s->nbpend); |
| 180 | else |
| 181 | chunk_printf(msg, ". %d active and %d backup servers online.%s" |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 182 | " %d sessions requeued, %d total in queue", |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 183 | s->proxy->srv_act, s->proxy->srv_bck, |
| 184 | (s->proxy->srv_bck && !s->proxy->srv_act) ? " Running on backup." : "", |
| 185 | xferred, s->nbpend); |
| 186 | } |
| 187 | } |
| 188 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 189 | /* |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 190 | * Set s->check_status, update s->check_duration and fill s->result with |
| 191 | * an adequate SRV_CHK_* value. |
| 192 | * |
| 193 | * Show information in logs about failed health check if server is UP |
| 194 | * or succeeded health checks if server is DOWN. |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 195 | */ |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 196 | static void set_server_check_status(struct server *s, short status, char *desc) { |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 197 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 198 | struct chunk msg; |
| 199 | |
| 200 | if (status == HCHK_STATUS_START) { |
| 201 | s->result = SRV_CHK_UNKNOWN; /* no result yet */ |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 202 | s->check_desc[0] = '\0'; |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 203 | s->check_start = now; |
| 204 | return; |
| 205 | } |
| 206 | |
| 207 | if (!s->check_status) |
| 208 | return; |
| 209 | |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 210 | if (desc && *desc) { |
| 211 | strncpy(s->check_desc, desc, HCHK_DESC_LEN-1); |
| 212 | s->check_desc[HCHK_DESC_LEN-1] = '\0'; |
| 213 | } else |
| 214 | s->check_desc[0] = '\0'; |
| 215 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 216 | s->check_status = status; |
| 217 | if (check_statuses[status].result) |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 218 | s->result = check_statuses[status].result; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 219 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 220 | if (status == HCHK_STATUS_HANA) |
| 221 | s->check_duration = -1; |
| 222 | else if (!tv_iszero(&s->check_start)) { |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 223 | /* set_server_check_status() may be called more than once */ |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 224 | s->check_duration = tv_ms_elapsed(&s->check_start, &now); |
| 225 | tv_zero(&s->check_start); |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | if (s->proxy->options2 & PR_O2_LOGHCHKS && |
| 229 | (((s->health != 0) && (s->result & SRV_CHK_ERROR)) || |
| 230 | ((s->health != s->rise + s->fall - 1) && (s->result & SRV_CHK_RUNNING)) || |
| 231 | ((s->state & SRV_GOINGDOWN) && !(s->result & SRV_CHK_DISABLE)) || |
| 232 | (!(s->state & SRV_GOINGDOWN) && (s->result & SRV_CHK_DISABLE)))) { |
| 233 | |
| 234 | int health, rise, fall, state; |
| 235 | |
| 236 | chunk_init(&msg, trash, sizeof(trash)); |
| 237 | |
| 238 | /* FIXME begin: calculate local version of the health/rise/fall/state */ |
| 239 | health = s->health; |
| 240 | rise = s->rise; |
| 241 | fall = s->fall; |
| 242 | state = s->state; |
| 243 | |
| 244 | if (s->result & SRV_CHK_ERROR) { |
| 245 | if (health > rise) { |
| 246 | health--; /* still good */ |
| 247 | } else { |
| 248 | if (health == rise) |
| 249 | state &= ~(SRV_RUNNING | SRV_GOINGDOWN); |
| 250 | |
| 251 | health = 0; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | if (s->result & SRV_CHK_RUNNING) { |
| 256 | if (health < rise + fall - 1) { |
| 257 | health++; /* was bad, stays for a while */ |
| 258 | |
| 259 | if (health == rise) |
| 260 | state |= SRV_RUNNING; |
| 261 | |
| 262 | if (health >= rise) |
| 263 | health = rise + fall - 1; /* OK now */ |
| 264 | } |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 265 | |
| 266 | /* clear consecutive_errors if observing is enabled */ |
| 267 | if (s->onerror) |
| 268 | s->consecutive_errors = 0; |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 269 | } |
| 270 | /* FIXME end: calculate local version of the health/rise/fall/state */ |
| 271 | |
| 272 | chunk_printf(&msg, |
| 273 | "Health check for %sserver %s/%s %s%s", |
| 274 | s->state & SRV_BACKUP ? "backup " : "", |
| 275 | s->proxy->id, s->id, |
| 276 | (s->result & SRV_CHK_DISABLE)?"conditionally ":"", |
| 277 | (s->result & SRV_CHK_RUNNING)?"succeeded":"failed"); |
| 278 | |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 279 | server_status_printf(&msg, s, SSP_O_HCHK, -1); |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 280 | |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 281 | chunk_printf(&msg, ", status: %d/%d %s", |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 282 | (state & SRV_RUNNING) ? (health - rise + 1) : (health), |
| 283 | (state & SRV_RUNNING) ? (fall) : (rise), |
| 284 | (state & SRV_RUNNING)?"UP":"DOWN"); |
| 285 | |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 286 | Warning("%s.\n", trash); |
| 287 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash); |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 288 | } |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 289 | } |
| 290 | |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 291 | /* sends a log message when a backend goes down, and also sets last |
| 292 | * change date. |
| 293 | */ |
| 294 | static void set_backend_down(struct proxy *be) |
| 295 | { |
| 296 | be->last_change = now.tv_sec; |
| 297 | be->down_trans++; |
| 298 | |
| 299 | Alert("%s '%s' has no server available!\n", proxy_type_str(be), be->id); |
| 300 | send_log(be, LOG_EMERG, "%s %s has no server available!\n", proxy_type_str(be), be->id); |
| 301 | } |
| 302 | |
| 303 | /* Redistribute pending connections when a server goes down. The number of |
| 304 | * connections redistributed is returned. |
| 305 | */ |
| 306 | static int redistribute_pending(struct server *s) |
| 307 | { |
| 308 | struct pendconn *pc, *pc_bck, *pc_end; |
| 309 | int xferred = 0; |
| 310 | |
| 311 | FOREACH_ITEM_SAFE(pc, pc_bck, &s->pendconns, pc_end, struct pendconn *, list) { |
| 312 | struct session *sess = pc->sess; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 313 | if ((sess->be->options & (PR_O_REDISP|PR_O_PERSIST)) == PR_O_REDISP && |
| 314 | !(sess->flags & SN_FORCE_PRST)) { |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 315 | /* The REDISP option was specified. We will ignore |
| 316 | * cookie and force to balance or use the dispatcher. |
| 317 | */ |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 318 | |
Krzysztof Piotr Oledzki | 5a329cf | 2008-02-22 03:50:19 +0100 | [diff] [blame] | 319 | /* it's left to the dispatcher to choose a server */ |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 320 | sess->flags &= ~(SN_DIRECT | SN_ASSIGNED | SN_ADDR_SET); |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 321 | |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 322 | pendconn_free(pc); |
Willy Tarreau | fdccded | 2008-08-29 18:19:04 +0200 | [diff] [blame] | 323 | task_wakeup(sess->task, TASK_WOKEN_RES); |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 324 | xferred++; |
| 325 | } |
| 326 | } |
| 327 | return xferred; |
| 328 | } |
| 329 | |
| 330 | /* Check for pending connections at the backend, and assign some of them to |
| 331 | * the server coming up. The server's weight is checked before being assigned |
| 332 | * connections it may not be able to handle. The total number of transferred |
| 333 | * connections is returned. |
| 334 | */ |
| 335 | static int check_for_pending(struct server *s) |
| 336 | { |
| 337 | int xferred; |
| 338 | |
| 339 | if (!s->eweight) |
| 340 | return 0; |
| 341 | |
| 342 | for (xferred = 0; !s->maxconn || xferred < srv_dynamic_maxconn(s); xferred++) { |
| 343 | struct session *sess; |
| 344 | struct pendconn *p; |
| 345 | |
| 346 | p = pendconn_from_px(s->proxy); |
| 347 | if (!p) |
| 348 | break; |
| 349 | p->sess->srv = s; |
| 350 | sess = p->sess; |
| 351 | pendconn_free(p); |
Willy Tarreau | fdccded | 2008-08-29 18:19:04 +0200 | [diff] [blame] | 352 | task_wakeup(sess->task, TASK_WOKEN_RES); |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 353 | } |
| 354 | return xferred; |
| 355 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 356 | |
| 357 | /* Sets server <s> down, notifies by all available means, recounts the |
| 358 | * remaining servers on the proxy and transfers queued sessions whenever |
Willy Tarreau | 5af3a69 | 2007-07-24 23:32:33 +0200 | [diff] [blame] | 359 | * possible to other servers. It automatically recomputes the number of |
| 360 | * servers, but not the map. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 361 | */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 362 | void set_server_down(struct server *s) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 363 | { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 364 | struct server *srv; |
| 365 | struct chunk msg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 366 | int xferred; |
| 367 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 368 | if (s->state & SRV_MAINTAIN) { |
| 369 | s->health = s->rise; |
| 370 | } |
| 371 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 372 | if (s->health == s->rise || s->tracked) { |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 373 | int srv_was_paused = s->state & SRV_GOINGDOWN; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 374 | |
| 375 | s->last_change = now.tv_sec; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 376 | s->state &= ~(SRV_RUNNING | SRV_GOINGDOWN); |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 377 | s->proxy->lbprm.set_server_status_down(s); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 378 | |
| 379 | /* we might have sessions queued on this server and waiting for |
| 380 | * a connection. Those which are redispatchable will be queued |
| 381 | * to another server or to the proxy itself. |
| 382 | */ |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 383 | xferred = redistribute_pending(s); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 384 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 385 | chunk_init(&msg, trash, sizeof(trash)); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 386 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 387 | if (s->state & SRV_MAINTAIN) { |
| 388 | chunk_printf(&msg, |
| 389 | "%sServer %s/%s is DOWN for maintenance", s->state & SRV_BACKUP ? "Backup " : "", |
| 390 | s->proxy->id, s->id); |
| 391 | } else { |
| 392 | chunk_printf(&msg, |
| 393 | "%sServer %s/%s is DOWN", s->state & SRV_BACKUP ? "Backup " : "", |
| 394 | s->proxy->id, s->id); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 395 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 396 | server_status_printf(&msg, s, |
| 397 | ((!s->tracked && !(s->proxy->options2 & PR_O2_LOGHCHKS))?SSP_O_HCHK:0), |
| 398 | xferred); |
| 399 | } |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 400 | Warning("%s.\n", trash); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 401 | |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 402 | /* we don't send an alert if the server was previously paused */ |
| 403 | if (srv_was_paused) |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 404 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash); |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 405 | else |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 406 | send_log(s->proxy, LOG_ALERT, "%s.\n", trash); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 407 | |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 408 | if (s->proxy->srv_bck == 0 && s->proxy->srv_act == 0) |
| 409 | set_backend_down(s->proxy); |
| 410 | |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 411 | s->counters.down_trans++; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 412 | |
Krzysztof Piotr Oledzki | f39c71c | 2009-01-30 00:52:49 +0100 | [diff] [blame] | 413 | if (s->state & SRV_CHECKED) |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 414 | for(srv = s->tracknext; srv; srv = srv->tracknext) |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 415 | if (! (srv->state & SRV_MAINTAIN)) |
| 416 | /* Only notify tracking servers that are not already in maintenance. */ |
| 417 | set_server_down(srv); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 418 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 419 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 420 | s->health = 0; /* failure */ |
| 421 | } |
| 422 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 423 | void set_server_up(struct server *s) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 424 | |
| 425 | struct server *srv; |
| 426 | struct chunk msg; |
| 427 | int xferred; |
| 428 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 429 | if (s->state & SRV_MAINTAIN) { |
| 430 | s->health = s->rise; |
| 431 | } |
| 432 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 433 | if (s->health == s->rise || s->tracked) { |
| 434 | if (s->proxy->srv_bck == 0 && s->proxy->srv_act == 0) { |
| 435 | if (s->proxy->last_change < now.tv_sec) // ignore negative times |
| 436 | s->proxy->down_time += now.tv_sec - s->proxy->last_change; |
| 437 | s->proxy->last_change = now.tv_sec; |
| 438 | } |
| 439 | |
| 440 | if (s->last_change < now.tv_sec) // ignore negative times |
| 441 | s->down_time += now.tv_sec - s->last_change; |
| 442 | |
| 443 | s->last_change = now.tv_sec; |
| 444 | s->state |= SRV_RUNNING; |
| 445 | |
| 446 | if (s->slowstart > 0) { |
| 447 | s->state |= SRV_WARMINGUP; |
| 448 | if (s->proxy->lbprm.algo & BE_LB_PROP_DYN) { |
| 449 | /* For dynamic algorithms, start at the first step of the weight, |
| 450 | * without multiplying by BE_WEIGHT_SCALE. |
| 451 | */ |
| 452 | s->eweight = s->uweight; |
| 453 | if (s->proxy->lbprm.update_server_eweight) |
| 454 | s->proxy->lbprm.update_server_eweight(s); |
| 455 | } |
| 456 | } |
| 457 | s->proxy->lbprm.set_server_status_up(s); |
| 458 | |
| 459 | /* check if we can handle some connections queued at the proxy. We |
| 460 | * will take as many as we can handle. |
| 461 | */ |
| 462 | xferred = check_for_pending(s); |
| 463 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 464 | chunk_init(&msg, trash, sizeof(trash)); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 465 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 466 | if (s->state & SRV_MAINTAIN) { |
| 467 | chunk_printf(&msg, |
| 468 | "%sServer %s/%s is UP (leaving maintenance)", s->state & SRV_BACKUP ? "Backup " : "", |
| 469 | s->proxy->id, s->id); |
| 470 | } else { |
| 471 | chunk_printf(&msg, |
| 472 | "%sServer %s/%s is UP", s->state & SRV_BACKUP ? "Backup " : "", |
| 473 | s->proxy->id, s->id); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 474 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 475 | server_status_printf(&msg, s, |
| 476 | ((!s->tracked && !(s->proxy->options2 & PR_O2_LOGHCHKS))?SSP_O_HCHK:0), |
| 477 | xferred); |
| 478 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 479 | |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 480 | Warning("%s.\n", trash); |
| 481 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 482 | |
Krzysztof Piotr Oledzki | f39c71c | 2009-01-30 00:52:49 +0100 | [diff] [blame] | 483 | if (s->state & SRV_CHECKED) |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 484 | for(srv = s->tracknext; srv; srv = srv->tracknext) |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 485 | if (! (srv->state & SRV_MAINTAIN)) |
| 486 | /* Only notify tracking servers if they're not in maintenance. */ |
| 487 | set_server_up(srv); |
| 488 | |
| 489 | s->state &= ~SRV_MAINTAIN; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | if (s->health >= s->rise) |
| 493 | s->health = s->rise + s->fall - 1; /* OK now */ |
| 494 | |
| 495 | } |
| 496 | |
| 497 | static void set_server_disabled(struct server *s) { |
| 498 | |
| 499 | struct server *srv; |
| 500 | struct chunk msg; |
| 501 | int xferred; |
| 502 | |
| 503 | s->state |= SRV_GOINGDOWN; |
| 504 | s->proxy->lbprm.set_server_status_down(s); |
| 505 | |
| 506 | /* we might have sessions queued on this server and waiting for |
| 507 | * a connection. Those which are redispatchable will be queued |
| 508 | * to another server or to the proxy itself. |
| 509 | */ |
| 510 | xferred = redistribute_pending(s); |
| 511 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 512 | chunk_init(&msg, trash, sizeof(trash)); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 513 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 514 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 515 | "Load-balancing on %sServer %s/%s is disabled", |
| 516 | s->state & SRV_BACKUP ? "Backup " : "", |
| 517 | s->proxy->id, s->id); |
| 518 | |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 519 | server_status_printf(&msg, s, |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 520 | ((!s->tracked && !(s->proxy->options2 & PR_O2_LOGHCHKS))?SSP_O_HCHK:0), |
Krzysztof Piotr Oledzki | b16a607 | 2010-01-10 21:12:58 +0100 | [diff] [blame] | 521 | xferred); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 522 | |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 523 | Warning("%s.\n", trash); |
| 524 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 525 | |
| 526 | if (!s->proxy->srv_bck && !s->proxy->srv_act) |
| 527 | set_backend_down(s->proxy); |
| 528 | |
Krzysztof Piotr Oledzki | f39c71c | 2009-01-30 00:52:49 +0100 | [diff] [blame] | 529 | if (s->state & SRV_CHECKED) |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 530 | for(srv = s->tracknext; srv; srv = srv->tracknext) |
| 531 | set_server_disabled(srv); |
| 532 | } |
| 533 | |
| 534 | static void set_server_enabled(struct server *s) { |
| 535 | |
| 536 | struct server *srv; |
| 537 | struct chunk msg; |
| 538 | int xferred; |
| 539 | |
| 540 | s->state &= ~SRV_GOINGDOWN; |
| 541 | s->proxy->lbprm.set_server_status_up(s); |
| 542 | |
| 543 | /* check if we can handle some connections queued at the proxy. We |
| 544 | * will take as many as we can handle. |
| 545 | */ |
| 546 | xferred = check_for_pending(s); |
| 547 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 548 | chunk_init(&msg, trash, sizeof(trash)); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 549 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 550 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 551 | "Load-balancing on %sServer %s/%s is enabled again", |
| 552 | s->state & SRV_BACKUP ? "Backup " : "", |
| 553 | s->proxy->id, s->id); |
| 554 | |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 555 | server_status_printf(&msg, s, |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 556 | ((!s->tracked && !(s->proxy->options2 & PR_O2_LOGHCHKS))?SSP_O_HCHK:0), |
Krzysztof Piotr Oledzki | b16a607 | 2010-01-10 21:12:58 +0100 | [diff] [blame] | 557 | xferred); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 558 | |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 559 | Warning("%s.\n", trash); |
| 560 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 561 | |
Krzysztof Piotr Oledzki | f39c71c | 2009-01-30 00:52:49 +0100 | [diff] [blame] | 562 | if (s->state & SRV_CHECKED) |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 563 | for(srv = s->tracknext; srv; srv = srv->tracknext) |
| 564 | set_server_enabled(srv); |
| 565 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 566 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 567 | void health_adjust(struct server *s, short status) { |
| 568 | |
| 569 | int failed; |
| 570 | int expire; |
| 571 | |
| 572 | /* return now if observing nor health check is not enabled */ |
| 573 | if (!s->observe || !s->check) |
| 574 | return; |
| 575 | |
| 576 | if (s->observe >= HANA_OBS_SIZE) |
| 577 | return; |
| 578 | |
| 579 | if (status >= HCHK_STATUS_SIZE || !analyze_statuses[status].desc) |
| 580 | return; |
| 581 | |
| 582 | switch (analyze_statuses[status].lr[s->observe - 1]) { |
| 583 | case 1: |
| 584 | failed = 1; |
| 585 | break; |
| 586 | |
| 587 | case 2: |
| 588 | failed = 0; |
| 589 | break; |
| 590 | |
| 591 | default: |
| 592 | return; |
| 593 | } |
| 594 | |
| 595 | if (!failed) { |
| 596 | /* good: clear consecutive_errors */ |
| 597 | s->consecutive_errors = 0; |
| 598 | return; |
| 599 | } |
| 600 | |
| 601 | s->consecutive_errors++; |
| 602 | |
| 603 | if (s->consecutive_errors < s->consecutive_errors_limit) |
| 604 | return; |
| 605 | |
| 606 | sprintf(trash, "Detected %d consecutive errors, last one was: %s", |
| 607 | s->consecutive_errors, get_analyze_status(status)); |
| 608 | |
| 609 | switch (s->onerror) { |
| 610 | case HANA_ONERR_FASTINTER: |
| 611 | /* force fastinter - nothing to do here as all modes force it */ |
| 612 | break; |
| 613 | |
| 614 | case HANA_ONERR_SUDDTH: |
| 615 | /* simulate a pre-fatal failed health check */ |
| 616 | if (s->health > s->rise) |
| 617 | s->health = s->rise + 1; |
| 618 | |
| 619 | /* no break - fall through */ |
| 620 | |
| 621 | case HANA_ONERR_FAILCHK: |
| 622 | /* simulate a failed health check */ |
| 623 | set_server_check_status(s, HCHK_STATUS_HANA, trash); |
| 624 | |
| 625 | if (s->health > s->rise) { |
| 626 | s->health--; /* still good */ |
| 627 | s->counters.failed_checks++; |
| 628 | } |
| 629 | else |
| 630 | set_server_down(s); |
| 631 | |
| 632 | break; |
| 633 | |
| 634 | case HANA_ONERR_MARKDWN: |
| 635 | /* mark server down */ |
| 636 | s->health = s->rise; |
| 637 | set_server_check_status(s, HCHK_STATUS_HANA, trash); |
| 638 | set_server_down(s); |
| 639 | |
| 640 | break; |
| 641 | |
| 642 | default: |
| 643 | /* write a warning? */ |
| 644 | break; |
| 645 | } |
| 646 | |
| 647 | s->consecutive_errors = 0; |
| 648 | s->counters.failed_hana++; |
| 649 | |
| 650 | if (s->fastinter) { |
| 651 | expire = tick_add(now_ms, MS_TO_TICKS(s->fastinter)); |
| 652 | if (s->check->expire > expire) |
| 653 | s->check->expire = expire; |
| 654 | } |
| 655 | } |
| 656 | |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 657 | static int httpchk_build_status_header(struct server *s, char *buffer) |
| 658 | { |
| 659 | int sv_state; |
| 660 | int ratio; |
| 661 | int hlen = 0; |
| 662 | const char *srv_hlt_st[7] = { "DOWN", "DOWN %d/%d", |
| 663 | "UP %d/%d", "UP", |
| 664 | "NOLB %d/%d", "NOLB", |
| 665 | "no check" }; |
| 666 | |
| 667 | memcpy(buffer + hlen, "X-Haproxy-Server-State: ", 24); |
| 668 | hlen += 24; |
| 669 | |
| 670 | if (!(s->state & SRV_CHECKED)) |
| 671 | sv_state = 6; /* should obviously never happen */ |
| 672 | else if (s->state & SRV_RUNNING) { |
| 673 | if (s->health == s->rise + s->fall - 1) |
| 674 | sv_state = 3; /* UP */ |
| 675 | else |
| 676 | sv_state = 2; /* going down */ |
| 677 | |
| 678 | if (s->state & SRV_GOINGDOWN) |
| 679 | sv_state += 2; |
| 680 | } else { |
| 681 | if (s->health) |
| 682 | sv_state = 1; /* going up */ |
| 683 | else |
| 684 | sv_state = 0; /* DOWN */ |
| 685 | } |
| 686 | |
| 687 | hlen += sprintf(buffer + hlen, |
| 688 | srv_hlt_st[sv_state], |
| 689 | (s->state & SRV_RUNNING) ? (s->health - s->rise + 1) : (s->health), |
| 690 | (s->state & SRV_RUNNING) ? (s->fall) : (s->rise)); |
| 691 | |
| 692 | hlen += sprintf(buffer + hlen, "; name=%s/%s; node=%s; weight=%d/%d; scur=%d/%d; qcur=%d", |
| 693 | s->proxy->id, s->id, |
| 694 | global.node, |
| 695 | (s->eweight * s->proxy->lbprm.wmult + s->proxy->lbprm.wdiv - 1) / s->proxy->lbprm.wdiv, |
| 696 | (s->proxy->lbprm.tot_weight * s->proxy->lbprm.wmult + s->proxy->lbprm.wdiv - 1) / s->proxy->lbprm.wdiv, |
| 697 | s->cur_sess, s->proxy->beconn - s->proxy->nbpend, |
| 698 | s->nbpend); |
| 699 | |
| 700 | if ((s->state & SRV_WARMINGUP) && |
| 701 | now.tv_sec < s->last_change + s->slowstart && |
| 702 | now.tv_sec >= s->last_change) { |
| 703 | ratio = MAX(1, 100 * (now.tv_sec - s->last_change) / s->slowstart); |
| 704 | hlen += sprintf(buffer + hlen, "; throttle=%d%%", ratio); |
| 705 | } |
| 706 | |
| 707 | buffer[hlen++] = '\r'; |
| 708 | buffer[hlen++] = '\n'; |
| 709 | |
| 710 | return hlen; |
| 711 | } |
| 712 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 713 | /* |
| 714 | * This function is used only for server health-checks. It handles |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 715 | * the connection acknowledgement. If the proxy requires L7 health-checks, |
| 716 | * it sends the request. In other cases, it calls set_server_check_status() |
| 717 | * to set s->check_status, s->check_duration and s->result. |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 718 | * The function itself returns 0 if it needs some polling before being called |
| 719 | * again, otherwise 1. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 720 | */ |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 721 | static int event_srv_chk_w(int fd) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 722 | { |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 723 | __label__ out_wakeup, out_nowake, out_poll, out_error; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 724 | struct task *t = fdtab[fd].owner; |
| 725 | struct server *s = t->context; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 726 | |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 727 | //fprintf(stderr, "event_srv_chk_w, state=%ld\n", unlikely(fdtab[fd].state)); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 728 | if (unlikely(fdtab[fd].state == FD_STERROR || (fdtab[fd].ev & FD_POLL_ERR))) { |
Krzysztof Piotr Oledzki | 6492db5 | 2010-01-02 22:03:01 +0100 | [diff] [blame] | 729 | int skerr, err = errno; |
| 730 | socklen_t lskerr = sizeof(skerr); |
| 731 | |
| 732 | if (!getsockopt(fd, SOL_SOCKET, SO_ERROR, &skerr, &lskerr) && skerr) |
| 733 | err = skerr; |
| 734 | |
| 735 | set_server_check_status(s, HCHK_STATUS_L4CON, strerror(err)); |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 736 | goto out_error; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 737 | } |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 738 | |
| 739 | /* here, we know that the connection is established */ |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 740 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 741 | if (!(s->result & SRV_CHK_ERROR)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 742 | /* we don't want to mark 'UP' a server on which we detected an error earlier */ |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 743 | if ((s->proxy->options & PR_O_HTTP_CHK) || |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 744 | (s->proxy->options & PR_O_SSL3_CHK) || |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 745 | (s->proxy->options & PR_O_SMTP_CHK) || |
| 746 | (s->proxy->options2 & PR_O2_MYSQL_CHK)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 747 | int ret; |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 748 | const char *check_req = s->proxy->check_req; |
| 749 | int check_len = s->proxy->check_len; |
| 750 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 751 | /* we want to check if this host replies to HTTP or SSLv3 requests |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 752 | * so we'll send the request, and won't wake the checker up now. |
| 753 | */ |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 754 | |
| 755 | if (s->proxy->options & PR_O_SSL3_CHK) { |
| 756 | /* SSL requires that we put Unix time in the request */ |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 757 | int gmt_time = htonl(date.tv_sec); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 758 | memcpy(s->proxy->check_req + 11, &gmt_time, 4); |
| 759 | } |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 760 | else if (s->proxy->options & PR_O_HTTP_CHK) { |
| 761 | memcpy(trash, check_req, check_len); |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 762 | |
| 763 | if (s->proxy->options2 & PR_O2_CHK_SNDST) |
| 764 | check_len += httpchk_build_status_header(s, trash + check_len); |
| 765 | |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 766 | trash[check_len++] = '\r'; |
| 767 | trash[check_len++] = '\n'; |
| 768 | trash[check_len] = '\0'; |
| 769 | check_req = trash; |
| 770 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 771 | |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 772 | ret = send(fd, check_req, check_len, MSG_DONTWAIT | MSG_NOSIGNAL); |
| 773 | if (ret == check_len) { |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 774 | /* we allow up to <timeout.check> if nonzero for a responce */ |
Willy Tarreau | 7cd9d94 | 2008-12-21 13:00:41 +0100 | [diff] [blame] | 775 | if (s->proxy->timeout.check) |
| 776 | t->expire = tick_add_ifset(now_ms, s->proxy->timeout.check); |
Willy Tarreau | f161a34 | 2007-04-08 16:59:42 +0200 | [diff] [blame] | 777 | EV_FD_SET(fd, DIR_RD); /* prepare for reading reply */ |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 778 | goto out_nowake; |
| 779 | } |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 780 | else if (ret == 0 || errno == EAGAIN) |
| 781 | goto out_poll; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 782 | else { |
| 783 | switch (errno) { |
| 784 | case ECONNREFUSED: |
| 785 | case ENETUNREACH: |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 786 | set_server_check_status(s, HCHK_STATUS_L4CON, strerror(errno)); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 787 | break; |
| 788 | |
| 789 | default: |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 790 | set_server_check_status(s, HCHK_STATUS_SOCKERR, strerror(errno)); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 791 | } |
| 792 | |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 793 | goto out_error; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 794 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 795 | } |
| 796 | else { |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 797 | /* We have no data to send to check the connection, and |
| 798 | * getsockopt() will not inform us whether the connection |
| 799 | * is still pending. So we'll reuse connect() to check the |
| 800 | * state of the socket. This has the advantage of givig us |
| 801 | * the following info : |
| 802 | * - error |
| 803 | * - connecting (EALREADY, EINPROGRESS) |
| 804 | * - connected (EISCONN, 0) |
| 805 | */ |
| 806 | |
| 807 | struct sockaddr_in sa; |
| 808 | |
| 809 | sa = (s->check_addr.sin_addr.s_addr) ? s->check_addr : s->addr; |
| 810 | sa.sin_port = htons(s->check_port); |
| 811 | |
| 812 | if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) == 0) |
| 813 | errno = 0; |
| 814 | |
| 815 | if (errno == EALREADY || errno == EINPROGRESS) |
| 816 | goto out_poll; |
| 817 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 818 | if (errno && errno != EISCONN) { |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 819 | set_server_check_status(s, HCHK_STATUS_L4CON, strerror(errno)); |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 820 | goto out_error; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 821 | } |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 822 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 823 | /* good TCP connection is enough */ |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 824 | set_server_check_status(s, HCHK_STATUS_L4OK, NULL); |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 825 | goto out_wakeup; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 826 | } |
| 827 | } |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 828 | out_wakeup: |
Willy Tarreau | fdccded | 2008-08-29 18:19:04 +0200 | [diff] [blame] | 829 | task_wakeup(t, TASK_WOKEN_IO); |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 830 | out_nowake: |
| 831 | EV_FD_CLR(fd, DIR_WR); /* nothing more to write */ |
Willy Tarreau | d6f087e | 2008-01-18 17:20:13 +0100 | [diff] [blame] | 832 | fdtab[fd].ev &= ~FD_POLL_OUT; |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 833 | return 1; |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 834 | out_poll: |
| 835 | /* The connection is still pending. We'll have to poll it |
| 836 | * before attempting to go further. */ |
Willy Tarreau | d6f087e | 2008-01-18 17:20:13 +0100 | [diff] [blame] | 837 | fdtab[fd].ev &= ~FD_POLL_OUT; |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 838 | return 0; |
| 839 | out_error: |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 840 | fdtab[fd].state = FD_STERROR; |
| 841 | goto out_wakeup; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | |
| 845 | /* |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 846 | * This function is used only for server health-checks. It handles the server's |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 847 | * reply to an HTTP request or SSL HELLO. It calls set_server_check_status() to |
| 848 | * update s->check_status, s->check_duration and s->result. |
| 849 | |
| 850 | * The set_server_check_status function is called with HCHK_STATUS_L7OKD if |
| 851 | * an HTTP server replies HTTP 2xx or 3xx (valid responses), if an SMTP server |
| 852 | * returns 2xx, HCHK_STATUS_L6OK if an SSL server returns at least 5 bytes in |
| 853 | * response to an SSL HELLO (the principle is that this is enough to |
| 854 | * distinguish between an SSL server and a pure TCP relay). All other cases will |
| 855 | * call it with a proper error status like HCHK_STATUS_L7STS, HCHK_STATUS_L6RSP, |
| 856 | * etc. |
| 857 | * |
| 858 | * The function returns 0 if it needs to be called again after some polling, |
| 859 | * otherwise non-zero.. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 860 | */ |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 861 | static int event_srv_chk_r(int fd) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 862 | { |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 863 | __label__ out_wakeup; |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 864 | int len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 865 | struct task *t = fdtab[fd].owner; |
| 866 | struct server *s = t->context; |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 867 | char *desc; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 868 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 869 | len = -1; |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 870 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 871 | if (unlikely((s->result & SRV_CHK_ERROR) || |
| 872 | (fdtab[fd].state == FD_STERROR) || |
Willy Tarreau | a5aa1c8 | 2010-01-15 10:35:58 +0100 | [diff] [blame] | 873 | (fdtab[fd].ev & FD_POLL_ERR))) { |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 874 | /* in case of TCP only, this tells us if the connection failed */ |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 875 | if (!(s->result & SRV_CHK_ERROR)) |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 876 | set_server_check_status(s, HCHK_STATUS_SOCKERR, NULL); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 877 | |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 878 | goto out_wakeup; |
| 879 | } |
| 880 | |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 881 | /* Warning! Linux returns EAGAIN on SO_ERROR if data are still available |
| 882 | * but the connection was closed on the remote end. Fortunately, recv still |
| 883 | * works correctly and we don't need to do the getsockopt() on linux. |
| 884 | */ |
Willy Tarreau | fc1daaf | 2010-01-15 10:26:13 +0100 | [diff] [blame] | 885 | len = recv(fd, trash, sizeof(trash), 0); |
Willy Tarreau | a5aa1c8 | 2010-01-15 10:35:58 +0100 | [diff] [blame] | 886 | if (unlikely(len < 0)) { |
| 887 | if (errno == EAGAIN) { |
| 888 | /* not ready, we want to poll first */ |
| 889 | fdtab[fd].ev &= ~FD_POLL_IN; |
| 890 | return 0; |
| 891 | } |
| 892 | /* network error, report it */ |
| 893 | if (!(s->result & SRV_CHK_ERROR)) |
| 894 | set_server_check_status(s, HCHK_STATUS_SOCKERR, NULL); |
| 895 | goto out_wakeup; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 896 | } |
| 897 | |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 898 | if (len < sizeof(trash)) |
| 899 | trash[len] = '\0'; |
| 900 | else |
| 901 | trash[len-1] = '\0'; |
| 902 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 903 | /* Note: the response will only be accepted if read at once */ |
| 904 | if (s->proxy->options & PR_O_HTTP_CHK) { |
| 905 | /* Check if the server speaks HTTP 1.X */ |
| 906 | if ((len < strlen("HTTP/1.0 000\r")) || |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 907 | (memcmp(trash, "HTTP/1.", 7) != 0 || |
| 908 | (trash[12] != ' ' && trash[12] != '\r')) || |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 909 | !isdigit((unsigned char)trash[9]) || !isdigit((unsigned char)trash[10]) || |
| 910 | !isdigit((unsigned char)trash[11])) { |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 911 | |
| 912 | cut_crlf(trash); |
| 913 | set_server_check_status(s, HCHK_STATUS_L7RSP, trash); |
| 914 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 915 | goto out_wakeup; |
| 916 | } |
| 917 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 918 | s->check_code = str2uic(&trash[9]); |
| 919 | |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 920 | desc = ltrim(&trash[12], ' '); |
| 921 | cut_crlf(desc); |
| 922 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 923 | /* check the reply : HTTP/1.X 2xx and 3xx are OK */ |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 924 | if (trash[9] == '2' || trash[9] == '3') |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 925 | set_server_check_status(s, HCHK_STATUS_L7OKD, desc); |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 926 | else if ((s->proxy->options & PR_O_DISABLE404) && |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 927 | (s->state & SRV_RUNNING) && |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 928 | (s->check_code == 404)) |
| 929 | /* 404 may be accepted as "stopping" only if the server was up */ |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 930 | set_server_check_status(s, HCHK_STATUS_L7OKCD, desc); |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 931 | else |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 932 | set_server_check_status(s, HCHK_STATUS_L7STS, desc); |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 933 | } |
| 934 | else if (s->proxy->options & PR_O_SSL3_CHK) { |
| 935 | /* Check for SSLv3 alert or handshake */ |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 936 | if ((len >= 5) && (trash[0] == 0x15 || trash[0] == 0x16)) |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 937 | set_server_check_status(s, HCHK_STATUS_L6OK, NULL); |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 938 | else |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 939 | set_server_check_status(s, HCHK_STATUS_L6RSP, NULL); |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 940 | } |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 941 | else if (s->proxy->options & PR_O_SMTP_CHK) { |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 942 | /* Check if the server speaks SMTP */ |
| 943 | if ((len < strlen("000\r")) || |
| 944 | (trash[3] != ' ' && trash[3] != '\r') || |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 945 | !isdigit((unsigned char)trash[0]) || !isdigit((unsigned char)trash[1]) || |
| 946 | !isdigit((unsigned char)trash[2])) { |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 947 | |
| 948 | cut_crlf(trash); |
| 949 | set_server_check_status(s, HCHK_STATUS_L7RSP, trash); |
| 950 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 951 | goto out_wakeup; |
| 952 | } |
| 953 | |
| 954 | s->check_code = str2uic(&trash[0]); |
| 955 | |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 956 | desc = ltrim(&trash[3], ' '); |
| 957 | cut_crlf(desc); |
| 958 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 959 | /* Check for SMTP code 2xx (should be 250) */ |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 960 | if (trash[0] == '2') |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 961 | set_server_check_status(s, HCHK_STATUS_L7OKD, desc); |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 962 | else |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 963 | set_server_check_status(s, HCHK_STATUS_L7STS, desc); |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 964 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 965 | else if (s->proxy->options2 & PR_O2_MYSQL_CHK) { |
| 966 | /* MySQL Error packet always begin with field_count = 0xff |
| 967 | * contrary to OK Packet who always begin whith 0x00 */ |
Willy Tarreau | 2a3a517 | 2010-01-14 11:41:31 +0100 | [diff] [blame] | 968 | if (trash[4] != '\xff') { |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 969 | /* We set the MySQL Version in description for information purpose |
| 970 | * FIXME : it can be cool to use MySQL Version for other purpose, |
| 971 | * like mark as down old MySQL server. |
| 972 | */ |
| 973 | if (len > 51) { |
| 974 | desc = ltrim(&trash[5], ' '); |
| 975 | set_server_check_status(s, HCHK_STATUS_L7OKD, desc); |
| 976 | } |
| 977 | else { |
| 978 | /* it seems we have a OK packet but without a valid length, |
| 979 | * it must be a protocol error |
| 980 | */ |
| 981 | set_server_check_status(s, HCHK_STATUS_L7RSP, trash); |
| 982 | } |
| 983 | } |
| 984 | else { |
| 985 | /* An error message is attached in the Error packet, |
| 986 | * so we can display it ! :) |
| 987 | */ |
| 988 | desc = ltrim(&trash[7], ' '); |
| 989 | set_server_check_status(s, HCHK_STATUS_L7STS, desc); |
| 990 | } |
| 991 | } |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 992 | else { |
| 993 | /* other checks are valid if the connection succeeded anyway */ |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 994 | set_server_check_status(s, HCHK_STATUS_L4OK, NULL); |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 995 | } |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 996 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 997 | out_wakeup: |
| 998 | if (s->result & SRV_CHK_ERROR) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 999 | fdtab[fd].state = FD_STERROR; |
| 1000 | |
Willy Tarreau | f161a34 | 2007-04-08 16:59:42 +0200 | [diff] [blame] | 1001 | EV_FD_CLR(fd, DIR_RD); |
Willy Tarreau | fdccded | 2008-08-29 18:19:04 +0200 | [diff] [blame] | 1002 | task_wakeup(t, TASK_WOKEN_IO); |
Willy Tarreau | d6f087e | 2008-01-18 17:20:13 +0100 | [diff] [blame] | 1003 | fdtab[fd].ev &= ~FD_POLL_IN; |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 1004 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | /* |
| 1008 | * manages a server health-check. Returns |
| 1009 | * the time the task accepts to wait, or TIME_ETERNITY for infinity. |
| 1010 | */ |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 1011 | struct task *process_chk(struct task *t) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1012 | { |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 1013 | int attempts = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1014 | struct server *s = t->context; |
| 1015 | struct sockaddr_in sa; |
| 1016 | int fd; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1017 | int rv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1018 | |
| 1019 | //fprintf(stderr, "process_chk: task=%p\n", t); |
| 1020 | |
| 1021 | new_chk: |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 1022 | if (attempts++ > 0) { |
| 1023 | /* we always fail to create a server, let's stop insisting... */ |
| 1024 | while (tick_is_expired(t->expire, now_ms)) |
| 1025 | t->expire = tick_add(t->expire, MS_TO_TICKS(s->inter)); |
| 1026 | return t; |
| 1027 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1028 | fd = s->curfd; |
| 1029 | if (fd < 0) { /* no check currently running */ |
| 1030 | //fprintf(stderr, "process_chk: 2\n"); |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 1031 | if (!tick_is_expired(t->expire, now_ms)) /* woke up too early */ |
| 1032 | return t; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1033 | |
| 1034 | /* we don't send any health-checks when the proxy is stopped or when |
| 1035 | * the server should not be checked. |
| 1036 | */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1037 | if (!(s->state & SRV_CHECKED) || s->proxy->state == PR_STSTOPPED || (s->state & SRV_MAINTAIN)) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1038 | while (tick_is_expired(t->expire, now_ms)) |
| 1039 | t->expire = tick_add(t->expire, MS_TO_TICKS(s->inter)); |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 1040 | return t; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | /* we'll initiate a new check */ |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1044 | set_server_check_status(s, HCHK_STATUS_START, NULL); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1045 | if ((fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) != -1) { |
| 1046 | if ((fd < global.maxsock) && |
| 1047 | (fcntl(fd, F_SETFL, O_NONBLOCK) != -1) && |
| 1048 | (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &one, sizeof(one)) != -1)) { |
| 1049 | //fprintf(stderr, "process_chk: 3\n"); |
| 1050 | |
Willy Tarreau | 9edd161 | 2007-10-18 18:07:48 +0200 | [diff] [blame] | 1051 | if (s->proxy->options & PR_O_TCP_NOLING) { |
| 1052 | /* We don't want to useless data */ |
| 1053 | setsockopt(fd, SOL_SOCKET, SO_LINGER, (struct linger *) &nolinger, sizeof(struct linger)); |
| 1054 | } |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 1055 | |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 1056 | if (s->check_addr.sin_addr.s_addr) |
| 1057 | /* we'll connect to the check addr specified on the server */ |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 1058 | sa = s->check_addr; |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 1059 | else |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 1060 | /* we'll connect to the addr on the server */ |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 1061 | sa = s->addr; |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 1062 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1063 | /* we'll connect to the check port on the server */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1064 | sa.sin_port = htons(s->check_port); |
| 1065 | |
| 1066 | /* allow specific binding : |
| 1067 | * - server-specific at first |
| 1068 | * - proxy-specific next |
| 1069 | */ |
| 1070 | if (s->state & SRV_BIND_SRC) { |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1071 | struct sockaddr_in *remote = NULL; |
| 1072 | int ret, flags = 0; |
Willy Tarreau | 163c532 | 2006-11-14 16:18:41 +0100 | [diff] [blame] | 1073 | |
Willy Tarreau | cf1d572 | 2008-02-14 20:28:18 +0100 | [diff] [blame] | 1074 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1075 | if ((s->state & SRV_TPROXY_MASK) == SRV_TPROXY_ADDR) { |
| 1076 | remote = (struct sockaddr_in *)&s->tproxy_addr; |
| 1077 | flags = 3; |
| 1078 | } |
Willy Tarreau | cf1d572 | 2008-02-14 20:28:18 +0100 | [diff] [blame] | 1079 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 1080 | #ifdef SO_BINDTODEVICE |
| 1081 | /* Note: this might fail if not CAP_NET_RAW */ |
| 1082 | if (s->iface_name) |
| 1083 | setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, |
Willy Tarreau | 604e830 | 2009-03-06 00:48:23 +0100 | [diff] [blame] | 1084 | s->iface_name, s->iface_len + 1); |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 1085 | #endif |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 1086 | if (s->sport_range) { |
| 1087 | int bind_attempts = 10; /* should be more than enough to find a spare port */ |
| 1088 | struct sockaddr_in src; |
| 1089 | |
| 1090 | ret = 1; |
| 1091 | src = s->source_addr; |
| 1092 | |
| 1093 | do { |
| 1094 | /* note: in case of retry, we may have to release a previously |
| 1095 | * allocated port, hence this loop's construct. |
| 1096 | */ |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 1097 | port_range_release_port(fdinfo[fd].port_range, fdinfo[fd].local_port); |
| 1098 | fdinfo[fd].port_range = NULL; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 1099 | |
| 1100 | if (!bind_attempts) |
| 1101 | break; |
| 1102 | bind_attempts--; |
| 1103 | |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 1104 | fdinfo[fd].local_port = port_range_alloc_port(s->sport_range); |
| 1105 | if (!fdinfo[fd].local_port) |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 1106 | break; |
| 1107 | |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 1108 | fdinfo[fd].port_range = s->sport_range; |
| 1109 | src.sin_port = htons(fdinfo[fd].local_port); |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 1110 | |
| 1111 | ret = tcpv4_bind_socket(fd, flags, &src, remote); |
| 1112 | } while (ret != 0); /* binding NOK */ |
| 1113 | } |
| 1114 | else { |
| 1115 | ret = tcpv4_bind_socket(fd, flags, &s->source_addr, remote); |
| 1116 | } |
| 1117 | |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1118 | if (ret) { |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1119 | set_server_check_status(s, HCHK_STATUS_SOCKERR, NULL); |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1120 | switch (ret) { |
| 1121 | case 1: |
| 1122 | Alert("Cannot bind to source address before connect() for server %s/%s. Aborting.\n", |
| 1123 | s->proxy->id, s->id); |
| 1124 | break; |
| 1125 | case 2: |
Willy Tarreau | 163c532 | 2006-11-14 16:18:41 +0100 | [diff] [blame] | 1126 | Alert("Cannot bind to tproxy source address before connect() for server %s/%s. Aborting.\n", |
| 1127 | s->proxy->id, s->id); |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1128 | break; |
Willy Tarreau | 163c532 | 2006-11-14 16:18:41 +0100 | [diff] [blame] | 1129 | } |
| 1130 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1131 | } |
| 1132 | else if (s->proxy->options & PR_O_BIND_SRC) { |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1133 | struct sockaddr_in *remote = NULL; |
| 1134 | int ret, flags = 0; |
| 1135 | |
Willy Tarreau | cf1d572 | 2008-02-14 20:28:18 +0100 | [diff] [blame] | 1136 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | 163c532 | 2006-11-14 16:18:41 +0100 | [diff] [blame] | 1137 | if ((s->proxy->options & PR_O_TPXY_MASK) == PR_O_TPXY_ADDR) { |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1138 | remote = (struct sockaddr_in *)&s->proxy->tproxy_addr; |
| 1139 | flags = 3; |
| 1140 | } |
Willy Tarreau | cf1d572 | 2008-02-14 20:28:18 +0100 | [diff] [blame] | 1141 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1142 | #ifdef SO_BINDTODEVICE |
| 1143 | /* Note: this might fail if not CAP_NET_RAW */ |
| 1144 | if (s->proxy->iface_name) |
| 1145 | setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, |
Willy Tarreau | 604e830 | 2009-03-06 00:48:23 +0100 | [diff] [blame] | 1146 | s->proxy->iface_name, s->proxy->iface_len + 1); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1147 | #endif |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1148 | ret = tcpv4_bind_socket(fd, flags, &s->proxy->source_addr, remote); |
| 1149 | if (ret) { |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1150 | set_server_check_status(s, HCHK_STATUS_SOCKERR, NULL); |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1151 | switch (ret) { |
| 1152 | case 1: |
| 1153 | Alert("Cannot bind to source address before connect() for %s '%s'. Aborting.\n", |
| 1154 | proxy_type_str(s->proxy), s->proxy->id); |
| 1155 | break; |
| 1156 | case 2: |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 1157 | Alert("Cannot bind to tproxy source address before connect() for %s '%s'. Aborting.\n", |
| 1158 | proxy_type_str(s->proxy), s->proxy->id); |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1159 | break; |
Willy Tarreau | 163c532 | 2006-11-14 16:18:41 +0100 | [diff] [blame] | 1160 | } |
| 1161 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1162 | } |
| 1163 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 1164 | if (s->result == SRV_CHK_UNKNOWN) { |
Dmitry Sivachenko | caf5898 | 2009-08-24 15:11:06 +0400 | [diff] [blame] | 1165 | #if defined(TCP_QUICKACK) |
Willy Tarreau | 1274bc4 | 2009-07-15 07:16:31 +0200 | [diff] [blame] | 1166 | /* disabling tcp quick ack now allows |
| 1167 | * the request to leave the machine with |
| 1168 | * the first ACK. |
| 1169 | */ |
| 1170 | if (s->proxy->options2 & PR_O2_SMARTCON) |
Dmitry Sivachenko | caf5898 | 2009-08-24 15:11:06 +0400 | [diff] [blame] | 1171 | setsockopt(fd, IPPROTO_TCP, TCP_QUICKACK, (char *) &zero, sizeof(zero)); |
Willy Tarreau | 1274bc4 | 2009-07-15 07:16:31 +0200 | [diff] [blame] | 1172 | #endif |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1173 | if ((connect(fd, (struct sockaddr *)&sa, sizeof(sa)) != -1) || (errno == EINPROGRESS)) { |
| 1174 | /* OK, connection in progress or established */ |
| 1175 | |
| 1176 | //fprintf(stderr, "process_chk: 4\n"); |
| 1177 | |
| 1178 | s->curfd = fd; /* that's how we know a test is in progress ;-) */ |
Willy Tarreau | 7a96648 | 2007-04-15 10:58:02 +0200 | [diff] [blame] | 1179 | fd_insert(fd); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1180 | fdtab[fd].owner = t; |
Willy Tarreau | 5446940 | 2006-07-29 16:59:06 +0200 | [diff] [blame] | 1181 | fdtab[fd].cb[DIR_RD].f = &event_srv_chk_r; |
| 1182 | fdtab[fd].cb[DIR_RD].b = NULL; |
| 1183 | fdtab[fd].cb[DIR_WR].f = &event_srv_chk_w; |
| 1184 | fdtab[fd].cb[DIR_WR].b = NULL; |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 1185 | fdinfo[fd].peeraddr = (struct sockaddr *)&sa; |
| 1186 | fdinfo[fd].peerlen = sizeof(sa); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1187 | fdtab[fd].state = FD_STCONN; /* connection in progress */ |
Willy Tarreau | fb14edc | 2009-06-14 15:24:37 +0200 | [diff] [blame] | 1188 | fdtab[fd].flags = FD_FL_TCP | FD_FL_TCP_NODELAY; |
Willy Tarreau | f161a34 | 2007-04-08 16:59:42 +0200 | [diff] [blame] | 1189 | EV_FD_SET(fd, DIR_WR); /* for connect status */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1190 | #ifdef DEBUG_FULL |
Willy Tarreau | f161a34 | 2007-04-08 16:59:42 +0200 | [diff] [blame] | 1191 | assert (!EV_FD_ISSET(fd, DIR_RD)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1192 | #endif |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1193 | //fprintf(stderr, "process_chk: 4+, %lu\n", __tv_to_ms(&s->proxy->timeout.connect)); |
| 1194 | /* we allow up to min(inter, timeout.connect) for a connection |
| 1195 | * to establish but only when timeout.check is set |
| 1196 | * as it may be to short for a full check otherwise |
| 1197 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1198 | t->expire = tick_add(now_ms, MS_TO_TICKS(s->inter)); |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1199 | |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1200 | if (s->proxy->timeout.check && s->proxy->timeout.connect) { |
| 1201 | int t_con = tick_add(now_ms, s->proxy->timeout.connect); |
| 1202 | t->expire = tick_first(t->expire, t_con); |
Willy Tarreau | 6054819 | 2008-02-17 11:34:10 +0100 | [diff] [blame] | 1203 | } |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 1204 | return t; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1205 | } |
| 1206 | else if (errno != EALREADY && errno != EISCONN && errno != EAGAIN) { |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 1207 | /* a real error */ |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1208 | |
| 1209 | switch (errno) { |
| 1210 | /* FIXME: is it possible to get ECONNREFUSED/ENETUNREACH with O_NONBLOCK? */ |
| 1211 | case ECONNREFUSED: |
| 1212 | case ENETUNREACH: |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1213 | set_server_check_status(s, HCHK_STATUS_L4CON, strerror(errno)); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1214 | break; |
| 1215 | |
| 1216 | default: |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1217 | set_server_check_status(s, HCHK_STATUS_SOCKERR, strerror(errno)); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1218 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1219 | } |
| 1220 | } |
| 1221 | } |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 1222 | port_range_release_port(fdinfo[fd].port_range, fdinfo[fd].local_port); |
| 1223 | fdinfo[fd].port_range = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1224 | close(fd); /* socket creation error */ |
| 1225 | } |
| 1226 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 1227 | if (s->result == SRV_CHK_UNKNOWN) { /* nothing done */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1228 | //fprintf(stderr, "process_chk: 6\n"); |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1229 | while (tick_is_expired(t->expire, now_ms)) |
| 1230 | t->expire = tick_add(t->expire, MS_TO_TICKS(s->inter)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1231 | goto new_chk; /* may be we should initialize a new check */ |
| 1232 | } |
| 1233 | |
| 1234 | /* here, we have seen a failure */ |
| 1235 | if (s->health > s->rise) { |
| 1236 | s->health--; /* still good */ |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1237 | s->counters.failed_checks++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1238 | } |
| 1239 | else |
| 1240 | set_server_down(s); |
| 1241 | |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1242 | //fprintf(stderr, "process_chk: 7, %lu\n", __tv_to_ms(&s->proxy->timeout.connect)); |
| 1243 | /* we allow up to min(inter, timeout.connect) for a connection |
| 1244 | * to establish but only when timeout.check is set |
| 1245 | * as it may be to short for a full check otherwise |
| 1246 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1247 | while (tick_is_expired(t->expire, now_ms)) { |
| 1248 | int t_con; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1249 | |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1250 | t_con = tick_add(t->expire, s->proxy->timeout.connect); |
| 1251 | t->expire = tick_add(t->expire, MS_TO_TICKS(s->inter)); |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1252 | |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1253 | if (s->proxy->timeout.check) |
| 1254 | t->expire = tick_first(t->expire, t_con); |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1255 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1256 | goto new_chk; |
| 1257 | } |
| 1258 | else { |
| 1259 | //fprintf(stderr, "process_chk: 8\n"); |
| 1260 | /* there was a test running */ |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 1261 | if ((s->result & (SRV_CHK_ERROR|SRV_CHK_RUNNING)) == SRV_CHK_RUNNING) { /* good server detected */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1262 | //fprintf(stderr, "process_chk: 9\n"); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1263 | |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 1264 | if (s->state & SRV_WARMINGUP) { |
| 1265 | if (now.tv_sec < s->last_change || now.tv_sec >= s->last_change + s->slowstart) { |
| 1266 | s->state &= ~SRV_WARMINGUP; |
| 1267 | if (s->proxy->lbprm.algo & BE_LB_PROP_DYN) |
| 1268 | s->eweight = s->uweight * BE_WEIGHT_SCALE; |
| 1269 | if (s->proxy->lbprm.update_server_eweight) |
| 1270 | s->proxy->lbprm.update_server_eweight(s); |
| 1271 | } |
| 1272 | else if (s->proxy->lbprm.algo & BE_LB_PROP_DYN) { |
| 1273 | /* for dynamic algorithms, let's update the weight */ |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 1274 | s->eweight = (BE_WEIGHT_SCALE * (now.tv_sec - s->last_change) + |
| 1275 | s->slowstart - 1) / s->slowstart; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 1276 | s->eweight *= s->uweight; |
| 1277 | if (s->proxy->lbprm.update_server_eweight) |
| 1278 | s->proxy->lbprm.update_server_eweight(s); |
| 1279 | } |
| 1280 | /* probably that we can refill this server with a bit more connections */ |
| 1281 | check_for_pending(s); |
| 1282 | } |
| 1283 | |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 1284 | /* we may have to add/remove this server from the LB group */ |
| 1285 | if ((s->state & SRV_RUNNING) && (s->proxy->options & PR_O_DISABLE404)) { |
| 1286 | if ((s->state & SRV_GOINGDOWN) && |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1287 | ((s->result & (SRV_CHK_RUNNING|SRV_CHK_DISABLE)) == SRV_CHK_RUNNING)) |
| 1288 | set_server_enabled(s); |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 1289 | else if (!(s->state & SRV_GOINGDOWN) && |
| 1290 | ((s->result & (SRV_CHK_RUNNING | SRV_CHK_DISABLE)) == |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1291 | (SRV_CHK_RUNNING | SRV_CHK_DISABLE))) |
| 1292 | set_server_disabled(s); |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 1293 | } |
| 1294 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1295 | if (s->health < s->rise + s->fall - 1) { |
| 1296 | s->health++; /* was bad, stays for a while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1297 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1298 | set_server_up(s); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1299 | } |
| 1300 | s->curfd = -1; /* no check running anymore */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1301 | fd_delete(fd); |
Willy Tarreau | 44ec0f0 | 2007-10-14 23:47:04 +0200 | [diff] [blame] | 1302 | |
| 1303 | rv = 0; |
| 1304 | if (global.spread_checks > 0) { |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1305 | rv = srv_getinter(s) * global.spread_checks / 100; |
Willy Tarreau | 44ec0f0 | 2007-10-14 23:47:04 +0200 | [diff] [blame] | 1306 | rv -= (int) (2 * rv * (rand() / (RAND_MAX + 1.0))); |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1307 | //fprintf(stderr, "process_chk(%p): (%d+/-%d%%) random=%d\n", s, srv_getinter(s), global.spread_checks, rv); |
Willy Tarreau | 44ec0f0 | 2007-10-14 23:47:04 +0200 | [diff] [blame] | 1308 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1309 | t->expire = tick_add(now_ms, MS_TO_TICKS(srv_getinter(s) + rv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1310 | goto new_chk; |
| 1311 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1312 | else if ((s->result & SRV_CHK_ERROR) || tick_is_expired(t->expire, now_ms)) { |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1313 | if (!(s->result & SRV_CHK_ERROR)) { |
| 1314 | if (!EV_FD_ISSET(fd, DIR_RD)) { |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1315 | set_server_check_status(s, HCHK_STATUS_L4TOUT, NULL); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1316 | } else { |
| 1317 | if (s->proxy->options & PR_O_SSL3_CHK) |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1318 | set_server_check_status(s, HCHK_STATUS_L6TOUT, NULL); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1319 | else /* HTTP, SMTP */ |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1320 | set_server_check_status(s, HCHK_STATUS_L7TOUT, NULL); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1321 | } |
| 1322 | } |
| 1323 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1324 | //fprintf(stderr, "process_chk: 10\n"); |
| 1325 | /* failure or timeout detected */ |
| 1326 | if (s->health > s->rise) { |
| 1327 | s->health--; /* still good */ |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1328 | s->counters.failed_checks++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1329 | } |
| 1330 | else |
| 1331 | set_server_down(s); |
| 1332 | s->curfd = -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1333 | fd_delete(fd); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1334 | |
| 1335 | rv = 0; |
| 1336 | if (global.spread_checks > 0) { |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1337 | rv = srv_getinter(s) * global.spread_checks / 100; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1338 | rv -= (int) (2 * rv * (rand() / (RAND_MAX + 1.0))); |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1339 | //fprintf(stderr, "process_chk(%p): (%d+/-%d%%) random=%d\n", s, srv_getinter(s), global.spread_checks, rv); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1340 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1341 | t->expire = tick_add(now_ms, MS_TO_TICKS(srv_getinter(s) + rv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1342 | goto new_chk; |
| 1343 | } |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 1344 | /* if result is unknown and there's no timeout, we have to wait again */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1345 | } |
| 1346 | //fprintf(stderr, "process_chk: 11\n"); |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 1347 | s->result = SRV_CHK_UNKNOWN; |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 1348 | return t; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1349 | } |
| 1350 | |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1351 | /* |
| 1352 | * Start health-check. |
| 1353 | * Returns 0 if OK, -1 if error, and prints the error in this case. |
| 1354 | */ |
| 1355 | int start_checks() { |
| 1356 | |
| 1357 | struct proxy *px; |
| 1358 | struct server *s; |
| 1359 | struct task *t; |
| 1360 | int nbchk=0, mininter=0, srvpos=0; |
| 1361 | |
Willy Tarreau | 2c43a1e | 2007-10-14 23:05:39 +0200 | [diff] [blame] | 1362 | /* 1- count the checkers to run simultaneously. |
| 1363 | * We also determine the minimum interval among all of those which |
| 1364 | * have an interval larger than SRV_CHK_INTER_THRES. This interval |
| 1365 | * will be used to spread their start-up date. Those which have |
| 1366 | * a shorter interval will start independantly and will not dictate |
| 1367 | * too short an interval for all others. |
| 1368 | */ |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1369 | for (px = proxy; px; px = px->next) { |
| 1370 | for (s = px->srv; s; s = s->next) { |
| 1371 | if (!(s->state & SRV_CHECKED)) |
| 1372 | continue; |
| 1373 | |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1374 | if ((srv_getinter(s) >= SRV_CHK_INTER_THRES) && |
| 1375 | (!mininter || mininter > srv_getinter(s))) |
| 1376 | mininter = srv_getinter(s); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1377 | |
| 1378 | nbchk++; |
| 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | if (!nbchk) |
| 1383 | return 0; |
| 1384 | |
| 1385 | srand((unsigned)time(NULL)); |
| 1386 | |
| 1387 | /* |
| 1388 | * 2- start them as far as possible from each others. For this, we will |
| 1389 | * start them after their interval set to the min interval divided by |
| 1390 | * the number of servers, weighted by the server's position in the list. |
| 1391 | */ |
| 1392 | for (px = proxy; px; px = px->next) { |
| 1393 | for (s = px->srv; s; s = s->next) { |
| 1394 | if (!(s->state & SRV_CHECKED)) |
| 1395 | continue; |
| 1396 | |
Willy Tarreau | a461318 | 2009-03-21 18:13:21 +0100 | [diff] [blame] | 1397 | if ((t = task_new()) == NULL) { |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1398 | Alert("Starting [%s:%s] check: out of memory.\n", px->id, s->id); |
| 1399 | return -1; |
| 1400 | } |
| 1401 | |
Krzysztof Piotr Oledzki | a643baf | 2008-05-29 23:53:44 +0200 | [diff] [blame] | 1402 | s->check = t; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1403 | t->process = process_chk; |
| 1404 | t->context = s; |
| 1405 | |
| 1406 | /* check this every ms */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1407 | t->expire = tick_add(now_ms, |
| 1408 | MS_TO_TICKS(((mininter && mininter >= srv_getinter(s)) ? |
| 1409 | mininter : srv_getinter(s)) * srvpos / nbchk)); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1410 | s->check_start = now; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1411 | task_queue(t); |
| 1412 | |
| 1413 | srvpos++; |
| 1414 | } |
| 1415 | } |
| 1416 | return 0; |
| 1417 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1418 | |
| 1419 | /* |
| 1420 | * Local variables: |
| 1421 | * c-indent-level: 8 |
| 1422 | * c-basic-offset: 8 |
| 1423 | * End: |
| 1424 | */ |