Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Server management functions. |
| 3 | * |
Willy Tarreau | 21faa91 | 2012-10-10 08:27:36 +0200 | [diff] [blame] | 4 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 5 | * Copyright 2007-2008 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 | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 14 | #include <ctype.h> |
| 15 | |
| 16 | #include <common/cfgparse.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 17 | #include <common/config.h> |
Willy Tarreau | dff5543 | 2012-10-10 17:51:05 +0200 | [diff] [blame] | 18 | #include <common/errors.h> |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 19 | #include <common/namespace.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 20 | #include <common/time.h> |
| 21 | |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 22 | #include <types/global.h> |
| 23 | |
Simon Horman | b1900d5 | 2015-01-30 11:22:54 +0900 | [diff] [blame] | 24 | #include <proto/checks.h> |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 25 | #include <proto/port_range.h> |
| 26 | #include <proto/protocol.h> |
Willy Tarreau | 4aac7db | 2014-05-16 11:48:10 +0200 | [diff] [blame] | 27 | #include <proto/queue.h> |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 28 | #include <proto/raw_sock.h> |
Willy Tarreau | ec6c5df | 2008-07-15 00:22:45 +0200 | [diff] [blame] | 29 | #include <proto/server.h> |
Willy Tarreau | 4aac7db | 2014-05-16 11:48:10 +0200 | [diff] [blame] | 30 | #include <proto/session.h> |
| 31 | #include <proto/task.h> |
| 32 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 33 | |
Willy Tarreau | 21faa91 | 2012-10-10 08:27:36 +0200 | [diff] [blame] | 34 | /* List head of all known server keywords */ |
| 35 | static struct srv_kw_list srv_keywords = { |
| 36 | .list = LIST_HEAD_INIT(srv_keywords.list) |
| 37 | }; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 38 | |
Simon Horman | a360844 | 2013-11-01 16:46:15 +0900 | [diff] [blame] | 39 | int srv_downtime(const struct server *s) |
Willy Tarreau | 21faa91 | 2012-10-10 08:27:36 +0200 | [diff] [blame] | 40 | { |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 41 | if ((s->state != SRV_ST_STOPPED) && s->last_change < now.tv_sec) // ignore negative time |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 42 | return s->down_time; |
| 43 | |
| 44 | return now.tv_sec - s->last_change + s->down_time; |
| 45 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 46 | |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 47 | int srv_lastsession(const struct server *s) |
| 48 | { |
| 49 | if (s->counters.last_sess) |
| 50 | return now.tv_sec - s->counters.last_sess; |
| 51 | |
| 52 | return -1; |
| 53 | } |
| 54 | |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 55 | int srv_getinter(const struct check *check) |
Willy Tarreau | 21faa91 | 2012-10-10 08:27:36 +0200 | [diff] [blame] | 56 | { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 57 | const struct server *s = check->server; |
| 58 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 59 | if ((check->state & CHK_ST_CONFIGURED) && (check->health == check->rise + check->fall - 1)) |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 60 | return check->inter; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 61 | |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 62 | if ((s->state == SRV_ST_STOPPED) && check->health == 0) |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 63 | return (check->downinter)?(check->downinter):(check->inter); |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 64 | |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 65 | return (check->fastinter)?(check->fastinter):(check->inter); |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 66 | } |
| 67 | |
Willy Tarreau | 21faa91 | 2012-10-10 08:27:36 +0200 | [diff] [blame] | 68 | /* |
| 69 | * Registers the server keyword list <kwl> as a list of valid keywords for next |
| 70 | * parsing sessions. |
| 71 | */ |
| 72 | void srv_register_keywords(struct srv_kw_list *kwl) |
| 73 | { |
| 74 | LIST_ADDQ(&srv_keywords.list, &kwl->list); |
| 75 | } |
| 76 | |
| 77 | /* Return a pointer to the server keyword <kw>, or NULL if not found. If the |
| 78 | * keyword is found with a NULL ->parse() function, then an attempt is made to |
| 79 | * find one with a valid ->parse() function. This way it is possible to declare |
| 80 | * platform-dependant, known keywords as NULL, then only declare them as valid |
| 81 | * if some options are met. Note that if the requested keyword contains an |
| 82 | * opening parenthesis, everything from this point is ignored. |
| 83 | */ |
| 84 | struct srv_kw *srv_find_kw(const char *kw) |
| 85 | { |
| 86 | int index; |
| 87 | const char *kwend; |
| 88 | struct srv_kw_list *kwl; |
| 89 | struct srv_kw *ret = NULL; |
| 90 | |
| 91 | kwend = strchr(kw, '('); |
| 92 | if (!kwend) |
| 93 | kwend = kw + strlen(kw); |
| 94 | |
| 95 | list_for_each_entry(kwl, &srv_keywords.list, list) { |
| 96 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 97 | if ((strncmp(kwl->kw[index].kw, kw, kwend - kw) == 0) && |
| 98 | kwl->kw[index].kw[kwend-kw] == 0) { |
| 99 | if (kwl->kw[index].parse) |
| 100 | return &kwl->kw[index]; /* found it !*/ |
| 101 | else |
| 102 | ret = &kwl->kw[index]; /* may be OK */ |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | return ret; |
| 107 | } |
| 108 | |
| 109 | /* Dumps all registered "server" keywords to the <out> string pointer. The |
| 110 | * unsupported keywords are only dumped if their supported form was not |
| 111 | * found. |
| 112 | */ |
| 113 | void srv_dump_kws(char **out) |
| 114 | { |
| 115 | struct srv_kw_list *kwl; |
| 116 | int index; |
| 117 | |
| 118 | *out = NULL; |
| 119 | list_for_each_entry(kwl, &srv_keywords.list, list) { |
| 120 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 121 | if (kwl->kw[index].parse || |
| 122 | srv_find_kw(kwl->kw[index].kw) == &kwl->kw[index]) { |
| 123 | memprintf(out, "%s[%4s] %s%s%s%s\n", *out ? *out : "", |
| 124 | kwl->scope, |
| 125 | kwl->kw[index].kw, |
| 126 | kwl->kw[index].skip ? " <arg>" : "", |
| 127 | kwl->kw[index].default_ok ? " [dflt_ok]" : "", |
| 128 | kwl->kw[index].parse ? "" : " (not supported)"); |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 133 | |
Willy Tarreau | dff5543 | 2012-10-10 17:51:05 +0200 | [diff] [blame] | 134 | /* parse the "id" server keyword */ |
| 135 | static int srv_parse_id(char **args, int *cur_arg, struct proxy *curproxy, struct server *newsrv, char **err) |
| 136 | { |
| 137 | struct eb32_node *node; |
| 138 | |
| 139 | if (!*args[*cur_arg + 1]) { |
| 140 | memprintf(err, "'%s' : expects an integer argument", args[*cur_arg]); |
| 141 | return ERR_ALERT | ERR_FATAL; |
| 142 | } |
| 143 | |
| 144 | newsrv->puid = atol(args[*cur_arg + 1]); |
| 145 | newsrv->conf.id.key = newsrv->puid; |
| 146 | |
| 147 | if (newsrv->puid <= 0) { |
| 148 | memprintf(err, "'%s' : custom id has to be > 0", args[*cur_arg]); |
| 149 | return ERR_ALERT | ERR_FATAL; |
| 150 | } |
| 151 | |
| 152 | node = eb32_lookup(&curproxy->conf.used_server_id, newsrv->puid); |
| 153 | if (node) { |
| 154 | struct server *target = container_of(node, struct server, conf.id); |
| 155 | memprintf(err, "'%s' : custom id %d already used at %s:%d ('server %s')", |
| 156 | args[*cur_arg], newsrv->puid, target->conf.file, target->conf.line, |
| 157 | target->id); |
| 158 | return ERR_ALERT | ERR_FATAL; |
| 159 | } |
| 160 | |
| 161 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 162 | return 0; |
| 163 | } |
| 164 | |
Willy Tarreau | 4aac7db | 2014-05-16 11:48:10 +0200 | [diff] [blame] | 165 | /* Shutdown all connections of a server. The caller must pass a termination |
| 166 | * code in <why>, which must be one of SN_ERR_* indicating the reason for the |
| 167 | * shutdown. |
| 168 | */ |
| 169 | void srv_shutdown_sessions(struct server *srv, int why) |
| 170 | { |
| 171 | struct session *session, *session_bck; |
| 172 | |
| 173 | list_for_each_entry_safe(session, session_bck, &srv->actconns, by_srv) |
| 174 | if (session->srv_conn == srv) |
| 175 | session_shutdown(session, why); |
| 176 | } |
| 177 | |
| 178 | /* Shutdown all connections of all backup servers of a proxy. The caller must |
| 179 | * pass a termination code in <why>, which must be one of SN_ERR_* indicating |
| 180 | * the reason for the shutdown. |
| 181 | */ |
| 182 | void srv_shutdown_backup_sessions(struct proxy *px, int why) |
| 183 | { |
| 184 | struct server *srv; |
| 185 | |
| 186 | for (srv = px->srv; srv != NULL; srv = srv->next) |
| 187 | if (srv->flags & SRV_F_BACKUP) |
| 188 | srv_shutdown_sessions(srv, why); |
| 189 | } |
| 190 | |
Willy Tarreau | bda9227 | 2014-05-20 21:55:30 +0200 | [diff] [blame] | 191 | /* Appends some information to a message string related to a server going UP or |
| 192 | * DOWN. If both <forced> and <reason> are null and the server tracks another |
| 193 | * one, a "via" information will be provided to know where the status came from. |
| 194 | * If <reason> is non-null, the entire string will be appended after a comma and |
| 195 | * a space (eg: to report some information from the check that changed the state). |
| 196 | * If <xferred> is non-negative, some information about requeued sessions are |
| 197 | * provided. |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 198 | */ |
Willy Tarreau | bda9227 | 2014-05-20 21:55:30 +0200 | [diff] [blame] | 199 | void srv_append_status(struct chunk *msg, struct server *s, const char *reason, int xferred, int forced) |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 200 | { |
Willy Tarreau | bda9227 | 2014-05-20 21:55:30 +0200 | [diff] [blame] | 201 | if (reason) |
| 202 | chunk_appendf(msg, ", %s", reason); |
| 203 | else if (!forced && s->track) |
| 204 | chunk_appendf(msg, " via %s/%s", s->track->proxy->id, s->track->id); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 205 | |
| 206 | if (xferred >= 0) { |
| 207 | if (s->state == SRV_ST_STOPPED) |
| 208 | chunk_appendf(msg, ". %d active and %d backup servers left.%s" |
| 209 | " %d sessions active, %d requeued, %d remaining in queue", |
| 210 | s->proxy->srv_act, s->proxy->srv_bck, |
| 211 | (s->proxy->srv_bck && !s->proxy->srv_act) ? " Running on backup." : "", |
| 212 | s->cur_sess, xferred, s->nbpend); |
| 213 | else |
| 214 | chunk_appendf(msg, ". %d active and %d backup servers online.%s" |
| 215 | " %d sessions requeued, %d total in queue", |
| 216 | s->proxy->srv_act, s->proxy->srv_bck, |
| 217 | (s->proxy->srv_bck && !s->proxy->srv_act) ? " Running on backup." : "", |
| 218 | xferred, s->nbpend); |
| 219 | } |
| 220 | } |
| 221 | |
Willy Tarreau | e7d1ef1 | 2014-05-20 22:25:12 +0200 | [diff] [blame] | 222 | /* Marks server <s> down, regardless of its checks' statuses, notifies by all |
| 223 | * available means, recounts the remaining servers on the proxy and transfers |
| 224 | * queued sessions whenever possible to other servers. It automatically |
| 225 | * recomputes the number of servers, but not the map. Maintenance servers are |
| 226 | * ignored. It reports <reason> if non-null as the reason for going down. Note |
| 227 | * that it makes use of the trash to build the log strings, so <reason> must |
| 228 | * not be placed there. |
| 229 | */ |
| 230 | void srv_set_stopped(struct server *s, const char *reason) |
| 231 | { |
| 232 | struct server *srv; |
| 233 | int prev_srv_count = s->proxy->srv_bck + s->proxy->srv_act; |
| 234 | int srv_was_stopping = (s->state == SRV_ST_STOPPING); |
| 235 | int xferred; |
| 236 | |
| 237 | if ((s->admin & SRV_ADMF_MAINT) || s->state == SRV_ST_STOPPED) |
| 238 | return; |
| 239 | |
| 240 | s->last_change = now.tv_sec; |
| 241 | s->state = SRV_ST_STOPPED; |
| 242 | if (s->proxy->lbprm.set_server_status_down) |
| 243 | s->proxy->lbprm.set_server_status_down(s); |
| 244 | |
| 245 | if (s->onmarkeddown & HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS) |
| 246 | srv_shutdown_sessions(s, SN_ERR_DOWN); |
| 247 | |
| 248 | /* we might have sessions queued on this server and waiting for |
| 249 | * a connection. Those which are redispatchable will be queued |
| 250 | * to another server or to the proxy itself. |
| 251 | */ |
| 252 | xferred = pendconn_redistribute(s); |
| 253 | |
| 254 | chunk_printf(&trash, |
| 255 | "%sServer %s/%s is DOWN", s->flags & SRV_F_BACKUP ? "Backup " : "", |
| 256 | s->proxy->id, s->id); |
| 257 | |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 258 | send_email_alert(s, "%s.", trash.str); |
Willy Tarreau | e7d1ef1 | 2014-05-20 22:25:12 +0200 | [diff] [blame] | 259 | srv_append_status(&trash, s, reason, xferred, 0); |
| 260 | Warning("%s.\n", trash.str); |
| 261 | |
| 262 | /* we don't send an alert if the server was previously paused */ |
| 263 | send_log(s->proxy, srv_was_stopping ? LOG_NOTICE : LOG_ALERT, "%s.\n", trash.str); |
| 264 | |
| 265 | if (prev_srv_count && s->proxy->srv_bck == 0 && s->proxy->srv_act == 0) |
| 266 | set_backend_down(s->proxy); |
| 267 | |
| 268 | s->counters.down_trans++; |
| 269 | |
| 270 | for (srv = s->trackers; srv; srv = srv->tracknext) |
| 271 | srv_set_stopped(srv, NULL); |
| 272 | } |
| 273 | |
Willy Tarreau | dbd5e78 | 2014-05-20 22:46:35 +0200 | [diff] [blame] | 274 | /* Marks server <s> up regardless of its checks' statuses and provided it isn't |
| 275 | * in maintenance. Notifies by all available means, recounts the remaining |
| 276 | * servers on the proxy and tries to grab requests from the proxy. It |
| 277 | * automatically recomputes the number of servers, but not the map. Maintenance |
| 278 | * servers are ignored. It reports <reason> if non-null as the reason for going |
| 279 | * up. Note that it makes use of the trash to build the log strings, so <reason> |
| 280 | * must not be placed there. |
| 281 | */ |
| 282 | void srv_set_running(struct server *s, const char *reason) |
| 283 | { |
| 284 | struct server *srv; |
| 285 | int xferred; |
| 286 | |
| 287 | if (s->admin & SRV_ADMF_MAINT) |
| 288 | return; |
| 289 | |
| 290 | if (s->state == SRV_ST_STARTING || s->state == SRV_ST_RUNNING) |
| 291 | return; |
| 292 | |
| 293 | if (s->proxy->srv_bck == 0 && s->proxy->srv_act == 0) { |
| 294 | if (s->proxy->last_change < now.tv_sec) // ignore negative times |
| 295 | s->proxy->down_time += now.tv_sec - s->proxy->last_change; |
| 296 | s->proxy->last_change = now.tv_sec; |
| 297 | } |
| 298 | |
| 299 | if (s->state == SRV_ST_STOPPED && s->last_change < now.tv_sec) // ignore negative times |
| 300 | s->down_time += now.tv_sec - s->last_change; |
| 301 | |
| 302 | s->last_change = now.tv_sec; |
| 303 | |
| 304 | s->state = SRV_ST_STARTING; |
| 305 | if (s->slowstart > 0) |
| 306 | task_schedule(s->warmup, tick_add(now_ms, MS_TO_TICKS(MAX(1000, s->slowstart / 20)))); |
| 307 | else |
| 308 | s->state = SRV_ST_RUNNING; |
| 309 | |
| 310 | server_recalc_eweight(s); |
| 311 | |
| 312 | /* If the server is set with "on-marked-up shutdown-backup-sessions", |
| 313 | * and it's not a backup server and its effective weight is > 0, |
| 314 | * then it can accept new connections, so we shut down all sessions |
| 315 | * on all backup servers. |
| 316 | */ |
| 317 | if ((s->onmarkedup & HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS) && |
| 318 | !(s->flags & SRV_F_BACKUP) && s->eweight) |
| 319 | srv_shutdown_backup_sessions(s->proxy, SN_ERR_UP); |
| 320 | |
| 321 | /* check if we can handle some connections queued at the proxy. We |
| 322 | * will take as many as we can handle. |
| 323 | */ |
| 324 | xferred = pendconn_grab_from_px(s); |
| 325 | |
| 326 | chunk_printf(&trash, |
| 327 | "%sServer %s/%s is UP", s->flags & SRV_F_BACKUP ? "Backup " : "", |
| 328 | s->proxy->id, s->id); |
| 329 | |
| 330 | srv_append_status(&trash, s, reason, xferred, 0); |
| 331 | Warning("%s.\n", trash.str); |
| 332 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash.str); |
| 333 | |
| 334 | for (srv = s->trackers; srv; srv = srv->tracknext) |
| 335 | srv_set_running(srv, NULL); |
| 336 | } |
| 337 | |
Willy Tarreau | 8eb7784 | 2014-05-21 13:54:57 +0200 | [diff] [blame] | 338 | /* Marks server <s> stopping regardless of its checks' statuses and provided it |
| 339 | * isn't in maintenance. Notifies by all available means, recounts the remaining |
| 340 | * servers on the proxy and tries to grab requests from the proxy. It |
| 341 | * automatically recomputes the number of servers, but not the map. Maintenance |
| 342 | * servers are ignored. It reports <reason> if non-null as the reason for going |
| 343 | * up. Note that it makes use of the trash to build the log strings, so <reason> |
| 344 | * must not be placed there. |
| 345 | */ |
| 346 | void srv_set_stopping(struct server *s, const char *reason) |
| 347 | { |
| 348 | struct server *srv; |
| 349 | int xferred; |
| 350 | |
| 351 | if (s->admin & SRV_ADMF_MAINT) |
| 352 | return; |
| 353 | |
| 354 | if (s->state == SRV_ST_STOPPING) |
| 355 | return; |
| 356 | |
| 357 | s->last_change = now.tv_sec; |
| 358 | s->state = SRV_ST_STOPPING; |
| 359 | if (s->proxy->lbprm.set_server_status_down) |
| 360 | s->proxy->lbprm.set_server_status_down(s); |
| 361 | |
| 362 | /* we might have sessions queued on this server and waiting for |
| 363 | * a connection. Those which are redispatchable will be queued |
| 364 | * to another server or to the proxy itself. |
| 365 | */ |
| 366 | xferred = pendconn_redistribute(s); |
| 367 | |
| 368 | chunk_printf(&trash, |
| 369 | "%sServer %s/%s is stopping", s->flags & SRV_F_BACKUP ? "Backup " : "", |
| 370 | s->proxy->id, s->id); |
| 371 | |
| 372 | srv_append_status(&trash, s, reason, xferred, 0); |
| 373 | |
| 374 | Warning("%s.\n", trash.str); |
| 375 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash.str); |
| 376 | |
| 377 | if (!s->proxy->srv_bck && !s->proxy->srv_act) |
| 378 | set_backend_down(s->proxy); |
| 379 | |
| 380 | for (srv = s->trackers; srv; srv = srv->tracknext) |
| 381 | srv_set_stopping(srv, NULL); |
| 382 | } |
Willy Tarreau | dbd5e78 | 2014-05-20 22:46:35 +0200 | [diff] [blame] | 383 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 384 | /* Enables admin flag <mode> (among SRV_ADMF_*) on server <s>. This is used to |
| 385 | * enforce either maint mode or drain mode. It is not allowed to set more than |
| 386 | * one flag at once. The equivalent "inherited" flag is propagated to all |
| 387 | * tracking servers. Maintenance mode disables health checks (but not agent |
| 388 | * checks). When either the flag is already set or no flag is passed, nothing |
| 389 | * is done. |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 390 | */ |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 391 | void srv_set_admin_flag(struct server *s, enum srv_admin mode) |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 392 | { |
| 393 | struct check *check = &s->check; |
| 394 | struct server *srv; |
| 395 | int xferred; |
| 396 | |
| 397 | if (!mode) |
| 398 | return; |
| 399 | |
| 400 | /* stop going down as soon as we meet a server already in the same state */ |
| 401 | if (s->admin & mode) |
| 402 | return; |
| 403 | |
| 404 | s->admin |= mode; |
| 405 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 406 | /* stop going down if the equivalent flag was already present (forced or inherited) */ |
| 407 | if (((mode & SRV_ADMF_MAINT) && (s->admin & ~mode & SRV_ADMF_MAINT)) || |
| 408 | ((mode & SRV_ADMF_DRAIN) && (s->admin & ~mode & SRV_ADMF_DRAIN))) |
| 409 | return; |
| 410 | |
| 411 | /* Maintenance must also disable health checks */ |
| 412 | if (mode & SRV_ADMF_MAINT) { |
| 413 | if (s->check.state & CHK_ST_ENABLED) { |
| 414 | s->check.state |= CHK_ST_PAUSED; |
| 415 | check->health = 0; |
| 416 | } |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 417 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 418 | if (s->state == SRV_ST_STOPPED) { /* server was already down */ |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 419 | chunk_printf(&trash, |
| 420 | "%sServer %s/%s was DOWN and now enters maintenance", |
| 421 | s->flags & SRV_F_BACKUP ? "Backup " : "", s->proxy->id, s->id); |
| 422 | |
Willy Tarreau | bda9227 | 2014-05-20 21:55:30 +0200 | [diff] [blame] | 423 | srv_append_status(&trash, s, NULL, -1, (mode & SRV_ADMF_FMAINT)); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 424 | |
| 425 | Warning("%s.\n", trash.str); |
| 426 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash.str); |
| 427 | } |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 428 | else { /* server was still running */ |
| 429 | int srv_was_stopping = (s->state == SRV_ST_STOPPING) || (s->admin & SRV_ADMF_DRAIN); |
| 430 | int prev_srv_count = s->proxy->srv_bck + s->proxy->srv_act; |
| 431 | |
| 432 | check->health = 0; /* failure */ |
| 433 | s->last_change = now.tv_sec; |
| 434 | s->state = SRV_ST_STOPPED; |
| 435 | if (s->proxy->lbprm.set_server_status_down) |
| 436 | s->proxy->lbprm.set_server_status_down(s); |
| 437 | |
| 438 | if (s->onmarkeddown & HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS) |
| 439 | srv_shutdown_sessions(s, SN_ERR_DOWN); |
| 440 | |
| 441 | /* we might have sessions queued on this server and waiting for |
| 442 | * a connection. Those which are redispatchable will be queued |
| 443 | * to another server or to the proxy itself. |
| 444 | */ |
| 445 | xferred = pendconn_redistribute(s); |
| 446 | |
| 447 | chunk_printf(&trash, |
| 448 | "%sServer %s/%s is going DOWN for maintenance", |
| 449 | s->flags & SRV_F_BACKUP ? "Backup " : "", |
| 450 | s->proxy->id, s->id); |
| 451 | |
| 452 | srv_append_status(&trash, s, NULL, xferred, (mode & SRV_ADMF_FMAINT)); |
| 453 | |
| 454 | Warning("%s.\n", trash.str); |
| 455 | send_log(s->proxy, srv_was_stopping ? LOG_NOTICE : LOG_ALERT, "%s.\n", trash.str); |
| 456 | |
| 457 | if (prev_srv_count && s->proxy->srv_bck == 0 && s->proxy->srv_act == 0) |
| 458 | set_backend_down(s->proxy); |
| 459 | |
| 460 | s->counters.down_trans++; |
| 461 | } |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 462 | } |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 463 | |
| 464 | /* drain state is applied only if not yet in maint */ |
| 465 | if ((mode & SRV_ADMF_DRAIN) && !(s->admin & SRV_ADMF_MAINT)) { |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 466 | int prev_srv_count = s->proxy->srv_bck + s->proxy->srv_act; |
| 467 | |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 468 | s->last_change = now.tv_sec; |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 469 | if (s->proxy->lbprm.set_server_status_down) |
| 470 | s->proxy->lbprm.set_server_status_down(s); |
| 471 | |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 472 | /* we might have sessions queued on this server and waiting for |
| 473 | * a connection. Those which are redispatchable will be queued |
| 474 | * to another server or to the proxy itself. |
| 475 | */ |
| 476 | xferred = pendconn_redistribute(s); |
| 477 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 478 | chunk_printf(&trash, "%sServer %s/%s enters drain state", |
| 479 | s->flags & SRV_F_BACKUP ? "Backup " : "", s->proxy->id, s->id); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 480 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 481 | srv_append_status(&trash, s, NULL, xferred, (mode & SRV_ADMF_FDRAIN)); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 482 | |
| 483 | Warning("%s.\n", trash.str); |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 484 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash.str); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 485 | |
| 486 | if (prev_srv_count && s->proxy->srv_bck == 0 && s->proxy->srv_act == 0) |
| 487 | set_backend_down(s->proxy); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 488 | } |
| 489 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 490 | /* compute the inherited flag to propagate */ |
| 491 | if (mode & SRV_ADMF_MAINT) |
| 492 | mode = SRV_ADMF_IMAINT; |
| 493 | else if (mode & SRV_ADMF_DRAIN) |
| 494 | mode = SRV_ADMF_IDRAIN; |
| 495 | |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 496 | for (srv = s->trackers; srv; srv = srv->tracknext) |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 497 | srv_set_admin_flag(srv, mode); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 498 | } |
| 499 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 500 | /* Disables admin flag <mode> (among SRV_ADMF_*) on server <s>. This is used to |
| 501 | * stop enforcing either maint mode or drain mode. It is not allowed to set more |
| 502 | * than one flag at once. The equivalent "inherited" flag is propagated to all |
| 503 | * tracking servers. Leaving maintenance mode re-enables health checks. When |
| 504 | * either the flag is already cleared or no flag is passed, nothing is done. |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 505 | */ |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 506 | void srv_clr_admin_flag(struct server *s, enum srv_admin mode) |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 507 | { |
| 508 | struct check *check = &s->check; |
| 509 | struct server *srv; |
| 510 | int xferred = -1; |
| 511 | |
| 512 | if (!mode) |
| 513 | return; |
| 514 | |
| 515 | /* stop going down as soon as we see the flag is not there anymore */ |
| 516 | if (!(s->admin & mode)) |
| 517 | return; |
| 518 | |
| 519 | s->admin &= ~mode; |
| 520 | |
| 521 | if (s->admin & SRV_ADMF_MAINT) { |
| 522 | /* remaining in maintenance mode, let's inform precisely about the |
| 523 | * situation. |
| 524 | */ |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 525 | if (mode & SRV_ADMF_FMAINT) { |
| 526 | chunk_printf(&trash, |
| 527 | "%sServer %s/%s is leaving forced maintenance but remains in maintenance", |
| 528 | s->flags & SRV_F_BACKUP ? "Backup " : "", |
| 529 | s->proxy->id, s->id); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 530 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 531 | if (s->track) /* normally it's mandatory here */ |
| 532 | chunk_appendf(&trash, " via %s/%s", |
| 533 | s->track->proxy->id, s->track->id); |
| 534 | Warning("%s.\n", trash.str); |
| 535 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash.str); |
| 536 | } |
| 537 | else if (mode & SRV_ADMF_IMAINT) { |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 538 | chunk_printf(&trash, |
| 539 | "%sServer %s/%s remains in forced maintenance", |
| 540 | s->flags & SRV_F_BACKUP ? "Backup " : "", |
| 541 | s->proxy->id, s->id); |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 542 | Warning("%s.\n", trash.str); |
| 543 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash.str); |
| 544 | } |
| 545 | /* don't report anything when leaving drain mode and remaining in maintenance */ |
| 546 | } |
| 547 | else if (mode & SRV_ADMF_MAINT) { |
| 548 | /* OK here we're leaving maintenance, we have many things to check, |
| 549 | * because the server might possibly be coming back up depending on |
| 550 | * its state. In practice, leaving maintenance means that we should |
| 551 | * immediately turn to UP (more or less the slowstart) under the |
| 552 | * following conditions : |
| 553 | * - server is neither checked nor tracked |
| 554 | * - server tracks another server which is not checked |
| 555 | * - server tracks another server which is already up |
| 556 | * Which sums up as something simpler : |
| 557 | * "either the tracking server is up or the server's checks are disabled |
| 558 | * or up". Otherwise we only re-enable health checks. There's a special |
| 559 | * case associated to the stopping state which can be inherited. Note |
| 560 | * that the server might still be in drain mode, which is naturally dealt |
| 561 | * with by the lower level functions. |
| 562 | */ |
| 563 | |
| 564 | if (s->check.state & CHK_ST_ENABLED) { |
| 565 | s->check.state &= ~CHK_ST_PAUSED; |
| 566 | check->health = check->rise; /* start OK but check immediately */ |
| 567 | } |
| 568 | |
| 569 | if ((!s->track || s->track->state != SRV_ST_STOPPED) && |
| 570 | (!(s->agent.state & CHK_ST_ENABLED) || (s->agent.health >= s->agent.rise)) && |
| 571 | (!(s->check.state & CHK_ST_ENABLED) || (s->check.health >= s->check.rise))) { |
| 572 | if (s->proxy->srv_bck == 0 && s->proxy->srv_act == 0) { |
| 573 | if (s->proxy->last_change < now.tv_sec) // ignore negative times |
| 574 | s->proxy->down_time += now.tv_sec - s->proxy->last_change; |
| 575 | s->proxy->last_change = now.tv_sec; |
| 576 | } |
| 577 | |
| 578 | if (s->last_change < now.tv_sec) // ignore negative times |
| 579 | s->down_time += now.tv_sec - s->last_change; |
| 580 | s->last_change = now.tv_sec; |
| 581 | |
| 582 | if (s->track && s->track->state == SRV_ST_STOPPING) |
| 583 | s->state = SRV_ST_STOPPING; |
| 584 | else { |
| 585 | s->state = SRV_ST_STARTING; |
| 586 | if (s->slowstart > 0) |
| 587 | task_schedule(s->warmup, tick_add(now_ms, MS_TO_TICKS(MAX(1000, s->slowstart / 20)))); |
| 588 | else |
| 589 | s->state = SRV_ST_RUNNING; |
| 590 | } |
| 591 | |
| 592 | server_recalc_eweight(s); |
| 593 | |
| 594 | /* If the server is set with "on-marked-up shutdown-backup-sessions", |
| 595 | * and it's not a backup server and its effective weight is > 0, |
| 596 | * then it can accept new connections, so we shut down all sessions |
| 597 | * on all backup servers. |
| 598 | */ |
| 599 | if ((s->onmarkedup & HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS) && |
| 600 | !(s->flags & SRV_F_BACKUP) && s->eweight) |
| 601 | srv_shutdown_backup_sessions(s->proxy, SN_ERR_UP); |
| 602 | |
| 603 | /* check if we can handle some connections queued at the proxy. We |
| 604 | * will take as many as we can handle. |
| 605 | */ |
| 606 | xferred = pendconn_grab_from_px(s); |
| 607 | } |
| 608 | |
| 609 | if (mode & SRV_ADMF_FMAINT) { |
| 610 | chunk_printf(&trash, |
| 611 | "%sServer %s/%s is %s/%s (leaving forced maintenance)", |
| 612 | s->flags & SRV_F_BACKUP ? "Backup " : "", |
| 613 | s->proxy->id, s->id, |
| 614 | (s->state == SRV_ST_STOPPED) ? "DOWN" : "UP", |
| 615 | (s->admin & SRV_ADMF_DRAIN) ? "DRAIN" : "READY"); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 616 | } |
| 617 | else { |
| 618 | chunk_printf(&trash, |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 619 | "%sServer %s/%s is %s/%s (leaving maintenance)", |
| 620 | s->flags & SRV_F_BACKUP ? "Backup " : "", |
| 621 | s->proxy->id, s->id, |
| 622 | (s->state == SRV_ST_STOPPED) ? "DOWN" : "UP", |
| 623 | (s->admin & SRV_ADMF_DRAIN) ? "DRAIN" : "READY"); |
| 624 | srv_append_status(&trash, s, NULL, xferred, 0); |
| 625 | } |
| 626 | Warning("%s.\n", trash.str); |
| 627 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash.str); |
| 628 | } |
| 629 | else if ((mode & SRV_ADMF_DRAIN) && (s->admin & SRV_ADMF_DRAIN)) { |
| 630 | /* remaining in drain mode after removing one of its flags */ |
| 631 | |
| 632 | if (mode & SRV_ADMF_FDRAIN) { |
| 633 | chunk_printf(&trash, |
| 634 | "%sServer %s/%s is leaving forced drain but remains in drain mode", |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 635 | s->flags & SRV_F_BACKUP ? "Backup " : "", |
| 636 | s->proxy->id, s->id); |
| 637 | |
| 638 | if (s->track) /* normally it's mandatory here */ |
| 639 | chunk_appendf(&trash, " via %s/%s", |
| 640 | s->track->proxy->id, s->track->id); |
| 641 | } |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 642 | else { |
| 643 | chunk_printf(&trash, |
| 644 | "%sServer %s/%s remains in forced drain mode", |
| 645 | s->flags & SRV_F_BACKUP ? "Backup " : "", |
| 646 | s->proxy->id, s->id); |
| 647 | } |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 648 | Warning("%s.\n", trash.str); |
| 649 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash.str); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 650 | } |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 651 | else if (mode & SRV_ADMF_DRAIN) { |
| 652 | /* OK completely leaving drain mode */ |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 653 | if (s->proxy->srv_bck == 0 && s->proxy->srv_act == 0) { |
| 654 | if (s->proxy->last_change < now.tv_sec) // ignore negative times |
| 655 | s->proxy->down_time += now.tv_sec - s->proxy->last_change; |
| 656 | s->proxy->last_change = now.tv_sec; |
| 657 | } |
| 658 | |
| 659 | if (s->last_change < now.tv_sec) // ignore negative times |
| 660 | s->down_time += now.tv_sec - s->last_change; |
| 661 | s->last_change = now.tv_sec; |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 662 | server_recalc_eweight(s); |
| 663 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 664 | if (mode & SRV_ADMF_FDRAIN) { |
| 665 | chunk_printf(&trash, |
| 666 | "%sServer %s/%s is %s (leaving forced drain)", |
| 667 | s->flags & SRV_F_BACKUP ? "Backup " : "", |
| 668 | s->proxy->id, s->id, |
| 669 | (s->state == SRV_ST_STOPPED) ? "DOWN" : "UP"); |
| 670 | } |
| 671 | else { |
| 672 | chunk_printf(&trash, |
| 673 | "%sServer %s/%s is %s (leaving drain)", |
| 674 | s->flags & SRV_F_BACKUP ? "Backup " : "", |
| 675 | s->proxy->id, s->id, |
| 676 | (s->state == SRV_ST_STOPPED) ? "DOWN" : "UP"); |
| 677 | if (s->track) /* normally it's mandatory here */ |
| 678 | chunk_appendf(&trash, " via %s/%s", |
| 679 | s->track->proxy->id, s->track->id); |
| 680 | } |
| 681 | Warning("%s.\n", trash.str); |
| 682 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash.str); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 683 | } |
| 684 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 685 | /* stop going down if the equivalent flag is still present (forced or inherited) */ |
| 686 | if (((mode & SRV_ADMF_MAINT) && (s->admin & SRV_ADMF_MAINT)) || |
| 687 | ((mode & SRV_ADMF_DRAIN) && (s->admin & SRV_ADMF_DRAIN))) |
| 688 | return; |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 689 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 690 | if (mode & SRV_ADMF_MAINT) |
| 691 | mode = SRV_ADMF_IMAINT; |
| 692 | else if (mode & SRV_ADMF_DRAIN) |
| 693 | mode = SRV_ADMF_IDRAIN; |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 694 | |
| 695 | for (srv = s->trackers; srv; srv = srv->tracknext) |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 696 | srv_clr_admin_flag(srv, mode); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 697 | } |
| 698 | |
Willy Tarreau | dff5543 | 2012-10-10 17:51:05 +0200 | [diff] [blame] | 699 | /* Note: must not be declared <const> as its list will be overwritten. |
| 700 | * Please take care of keeping this list alphabetically sorted, doing so helps |
| 701 | * all code contributors. |
| 702 | * Optional keywords are also declared with a NULL ->parse() function so that |
| 703 | * the config parser can report an appropriate error when a known keyword was |
| 704 | * not enabled. |
| 705 | */ |
| 706 | static struct srv_kw_list srv_kws = { "ALL", { }, { |
| 707 | { "id", srv_parse_id, 1, 0 }, /* set id# of server */ |
| 708 | { NULL, NULL, 0 }, |
| 709 | }}; |
| 710 | |
| 711 | __attribute__((constructor)) |
| 712 | static void __listener_init(void) |
| 713 | { |
| 714 | srv_register_keywords(&srv_kws); |
| 715 | } |
| 716 | |
Willy Tarreau | 004e045 | 2013-11-21 11:22:01 +0100 | [diff] [blame] | 717 | /* Recomputes the server's eweight based on its state, uweight, the current time, |
| 718 | * and the proxy's algorihtm. To be used after updating sv->uweight. The warmup |
| 719 | * state is automatically disabled if the time is elapsed. |
| 720 | */ |
| 721 | void server_recalc_eweight(struct server *sv) |
| 722 | { |
| 723 | struct proxy *px = sv->proxy; |
| 724 | unsigned w; |
| 725 | |
| 726 | if (now.tv_sec < sv->last_change || now.tv_sec >= sv->last_change + sv->slowstart) { |
| 727 | /* go to full throttle if the slowstart interval is reached */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 728 | if (sv->state == SRV_ST_STARTING) |
| 729 | sv->state = SRV_ST_RUNNING; |
Willy Tarreau | 004e045 | 2013-11-21 11:22:01 +0100 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | /* We must take care of not pushing the server to full throttle during slow starts. |
| 733 | * It must also start immediately, at least at the minimal step when leaving maintenance. |
| 734 | */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 735 | if ((sv->state == SRV_ST_STARTING) && (px->lbprm.algo & BE_LB_PROP_DYN)) |
Willy Tarreau | 004e045 | 2013-11-21 11:22:01 +0100 | [diff] [blame] | 736 | w = (px->lbprm.wdiv * (now.tv_sec - sv->last_change) + sv->slowstart) / sv->slowstart; |
| 737 | else |
| 738 | w = px->lbprm.wdiv; |
| 739 | |
| 740 | sv->eweight = (sv->uweight * w + px->lbprm.wmult - 1) / px->lbprm.wmult; |
| 741 | |
| 742 | /* now propagate the status change to any LB algorithms */ |
| 743 | if (px->lbprm.update_server_eweight) |
| 744 | px->lbprm.update_server_eweight(sv); |
Willy Tarreau | 9943d31 | 2014-05-22 16:20:59 +0200 | [diff] [blame] | 745 | else if (srv_is_usable(sv)) { |
Willy Tarreau | 004e045 | 2013-11-21 11:22:01 +0100 | [diff] [blame] | 746 | if (px->lbprm.set_server_status_up) |
| 747 | px->lbprm.set_server_status_up(sv); |
| 748 | } |
| 749 | else { |
| 750 | if (px->lbprm.set_server_status_down) |
| 751 | px->lbprm.set_server_status_down(sv); |
| 752 | } |
| 753 | } |
| 754 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 755 | /* |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 756 | * Parses weight_str and configures sv accordingly. |
| 757 | * Returns NULL on success, error message string otherwise. |
| 758 | */ |
| 759 | const char *server_parse_weight_change_request(struct server *sv, |
| 760 | const char *weight_str) |
| 761 | { |
| 762 | struct proxy *px; |
Simon Horman | b796afa | 2013-02-12 10:45:53 +0900 | [diff] [blame] | 763 | long int w; |
| 764 | char *end; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 765 | |
| 766 | px = sv->proxy; |
| 767 | |
| 768 | /* if the weight is terminated with '%', it is set relative to |
| 769 | * the initial weight, otherwise it is absolute. |
| 770 | */ |
| 771 | if (!*weight_str) |
| 772 | return "Require <weight> or <weight%>.\n"; |
| 773 | |
Simon Horman | b796afa | 2013-02-12 10:45:53 +0900 | [diff] [blame] | 774 | w = strtol(weight_str, &end, 10); |
| 775 | if (end == weight_str) |
| 776 | return "Empty weight string empty or preceded by garbage"; |
| 777 | else if (end[0] == '%' && end[1] == '\0') { |
Simon Horman | 58b5d29 | 2013-02-12 10:45:52 +0900 | [diff] [blame] | 778 | if (w < 0) |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 779 | return "Relative weight must be positive.\n"; |
Simon Horman | 58b5d29 | 2013-02-12 10:45:52 +0900 | [diff] [blame] | 780 | /* Avoid integer overflow */ |
| 781 | if (w > 25600) |
| 782 | w = 25600; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 783 | w = sv->iweight * w / 100; |
Simon Horman | 58b5d29 | 2013-02-12 10:45:52 +0900 | [diff] [blame] | 784 | if (w > 256) |
| 785 | w = 256; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 786 | } |
| 787 | else if (w < 0 || w > 256) |
| 788 | return "Absolute weight can only be between 0 and 256 inclusive.\n"; |
Simon Horman | b796afa | 2013-02-12 10:45:53 +0900 | [diff] [blame] | 789 | else if (end[0] != '\0') |
| 790 | return "Trailing garbage in weight string"; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 791 | |
| 792 | if (w && w != sv->iweight && !(px->lbprm.algo & BE_LB_PROP_DYN)) |
| 793 | return "Backend is using a static LB algorithm and only accepts weights '0%' and '100%'.\n"; |
| 794 | |
| 795 | sv->uweight = w; |
Willy Tarreau | 004e045 | 2013-11-21 11:22:01 +0100 | [diff] [blame] | 796 | server_recalc_eweight(sv); |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 797 | |
| 798 | return NULL; |
| 799 | } |
| 800 | |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 801 | int parse_server(const char *file, int linenum, char **args, struct proxy *curproxy, struct proxy *defproxy) |
| 802 | { |
| 803 | struct server *newsrv = NULL; |
| 804 | const char *err; |
| 805 | char *errmsg = NULL; |
| 806 | int err_code = 0; |
| 807 | unsigned val; |
| 808 | |
| 809 | if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) { /* server address */ |
| 810 | int cur_arg; |
| 811 | short realport = 0; |
| 812 | int do_agent = 0, do_check = 0, defsrv = (*args[0] == 'd'); |
| 813 | |
| 814 | if (!defsrv && curproxy == defproxy) { |
| 815 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 816 | err_code |= ERR_ALERT | ERR_FATAL; |
| 817 | goto out; |
| 818 | } |
| 819 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 820 | err_code |= ERR_ALERT | ERR_FATAL; |
| 821 | |
| 822 | if (!*args[2]) { |
| 823 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 824 | file, linenum, args[0]); |
| 825 | err_code |= ERR_ALERT | ERR_FATAL; |
| 826 | goto out; |
| 827 | } |
| 828 | |
| 829 | err = invalid_char(args[1]); |
| 830 | if (err && !defsrv) { |
| 831 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 832 | file, linenum, *err, args[1]); |
| 833 | err_code |= ERR_ALERT | ERR_FATAL; |
| 834 | goto out; |
| 835 | } |
| 836 | |
| 837 | if (!defsrv) { |
| 838 | struct sockaddr_storage *sk; |
| 839 | int port1, port2; |
| 840 | struct protocol *proto; |
| 841 | |
| 842 | if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) { |
| 843 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 844 | err_code |= ERR_ALERT | ERR_ABORT; |
| 845 | goto out; |
| 846 | } |
| 847 | |
| 848 | /* the servers are linked backwards first */ |
| 849 | newsrv->next = curproxy->srv; |
| 850 | curproxy->srv = newsrv; |
| 851 | newsrv->proxy = curproxy; |
| 852 | newsrv->conf.file = strdup(file); |
| 853 | newsrv->conf.line = linenum; |
| 854 | |
| 855 | newsrv->obj_type = OBJ_TYPE_SERVER; |
| 856 | LIST_INIT(&newsrv->actconns); |
| 857 | LIST_INIT(&newsrv->pendconns); |
| 858 | do_check = 0; |
| 859 | do_agent = 0; |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 860 | newsrv->flags = 0; |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 861 | newsrv->admin = 0; |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 862 | newsrv->state = SRV_ST_RUNNING; /* early server setup */ |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 863 | newsrv->last_change = now.tv_sec; |
| 864 | newsrv->id = strdup(args[1]); |
| 865 | |
| 866 | /* several ways to check the port component : |
| 867 | * - IP => port=+0, relative (IPv4 only) |
| 868 | * - IP: => port=+0, relative |
| 869 | * - IP:N => port=N, absolute |
| 870 | * - IP:+N => port=+N, relative |
| 871 | * - IP:-N => port=-N, relative |
| 872 | */ |
| 873 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL); |
| 874 | if (!sk) { |
| 875 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
| 876 | err_code |= ERR_ALERT | ERR_FATAL; |
| 877 | goto out; |
| 878 | } |
| 879 | |
| 880 | proto = protocol_by_family(sk->ss_family); |
| 881 | if (!proto || !proto->connect) { |
| 882 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 883 | file, linenum, args[0], args[1]); |
| 884 | err_code |= ERR_ALERT | ERR_FATAL; |
| 885 | goto out; |
| 886 | } |
| 887 | |
| 888 | if (!port1 || !port2) { |
| 889 | /* no port specified, +offset, -offset */ |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 890 | newsrv->flags |= SRV_F_MAPPORTS; |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 891 | } |
| 892 | else if (port1 != port2) { |
| 893 | /* port range */ |
| 894 | Alert("parsing [%s:%d] : '%s %s' : port ranges are not allowed in '%s'\n", |
| 895 | file, linenum, args[0], args[1], args[2]); |
| 896 | err_code |= ERR_ALERT | ERR_FATAL; |
| 897 | goto out; |
| 898 | } |
| 899 | else { |
| 900 | /* used by checks */ |
| 901 | realport = port1; |
| 902 | } |
| 903 | |
| 904 | newsrv->addr = *sk; |
Simon Horman | 41f5876 | 2015-01-30 11:22:56 +0900 | [diff] [blame] | 905 | newsrv->proto = newsrv->check.proto = newsrv->agent.proto = protocol_by_family(newsrv->addr.ss_family); |
Cyril Bonté | 9ce1311 | 2014-11-15 22:41:27 +0100 | [diff] [blame] | 906 | newsrv->xprt = newsrv->check.xprt = newsrv->agent.xprt = &raw_sock; |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 907 | |
| 908 | if (!newsrv->proto) { |
| 909 | Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n", |
| 910 | file, linenum, newsrv->addr.ss_family, args[2]); |
| 911 | err_code |= ERR_ALERT | ERR_FATAL; |
| 912 | goto out; |
| 913 | } |
| 914 | |
| 915 | newsrv->check.use_ssl = curproxy->defsrv.check.use_ssl; |
| 916 | newsrv->check.port = curproxy->defsrv.check.port; |
| 917 | newsrv->check.inter = curproxy->defsrv.check.inter; |
| 918 | newsrv->check.fastinter = curproxy->defsrv.check.fastinter; |
| 919 | newsrv->check.downinter = curproxy->defsrv.check.downinter; |
| 920 | newsrv->agent.use_ssl = curproxy->defsrv.agent.use_ssl; |
| 921 | newsrv->agent.port = curproxy->defsrv.agent.port; |
| 922 | newsrv->agent.inter = curproxy->defsrv.agent.inter; |
| 923 | newsrv->agent.fastinter = curproxy->defsrv.agent.fastinter; |
| 924 | newsrv->agent.downinter = curproxy->defsrv.agent.downinter; |
| 925 | newsrv->maxqueue = curproxy->defsrv.maxqueue; |
| 926 | newsrv->minconn = curproxy->defsrv.minconn; |
| 927 | newsrv->maxconn = curproxy->defsrv.maxconn; |
| 928 | newsrv->slowstart = curproxy->defsrv.slowstart; |
| 929 | newsrv->onerror = curproxy->defsrv.onerror; |
| 930 | newsrv->onmarkeddown = curproxy->defsrv.onmarkeddown; |
| 931 | newsrv->onmarkedup = curproxy->defsrv.onmarkedup; |
| 932 | newsrv->consecutive_errors_limit |
| 933 | = curproxy->defsrv.consecutive_errors_limit; |
| 934 | #ifdef OPENSSL |
| 935 | newsrv->use_ssl = curproxy->defsrv.use_ssl; |
| 936 | #endif |
| 937 | newsrv->uweight = newsrv->iweight |
| 938 | = curproxy->defsrv.iweight; |
| 939 | |
| 940 | newsrv->check.status = HCHK_STATUS_INI; |
| 941 | newsrv->check.rise = curproxy->defsrv.check.rise; |
| 942 | newsrv->check.fall = curproxy->defsrv.check.fall; |
| 943 | newsrv->check.health = newsrv->check.rise; /* up, but will fall down at first failure */ |
| 944 | newsrv->check.server = newsrv; |
Simon Horman | e16c1b3 | 2015-01-30 11:22:57 +0900 | [diff] [blame] | 945 | newsrv->check.tcpcheck_rules = &curproxy->tcpcheck_rules; |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 946 | |
| 947 | newsrv->agent.status = HCHK_STATUS_INI; |
| 948 | newsrv->agent.rise = curproxy->defsrv.agent.rise; |
| 949 | newsrv->agent.fall = curproxy->defsrv.agent.fall; |
| 950 | newsrv->agent.health = newsrv->agent.rise; /* up, but will fall down at first failure */ |
| 951 | newsrv->agent.server = newsrv; |
| 952 | |
| 953 | cur_arg = 3; |
| 954 | } else { |
| 955 | newsrv = &curproxy->defsrv; |
| 956 | cur_arg = 1; |
| 957 | } |
| 958 | |
| 959 | while (*args[cur_arg]) { |
| 960 | if (!strcmp(args[cur_arg], "agent-check")) { |
| 961 | global.maxsock++; |
| 962 | do_agent = 1; |
| 963 | cur_arg += 1; |
| 964 | } else if (!strcmp(args[cur_arg], "agent-inter")) { |
| 965 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 966 | if (err) { |
| 967 | Alert("parsing [%s:%d] : unexpected character '%c' in 'agent-inter' argument of server %s.\n", |
| 968 | file, linenum, *err, newsrv->id); |
| 969 | err_code |= ERR_ALERT | ERR_FATAL; |
| 970 | goto out; |
| 971 | } |
| 972 | if (val <= 0) { |
| 973 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 974 | file, linenum, val, args[cur_arg], newsrv->id); |
| 975 | err_code |= ERR_ALERT | ERR_FATAL; |
| 976 | goto out; |
| 977 | } |
| 978 | newsrv->agent.inter = val; |
| 979 | cur_arg += 2; |
| 980 | } |
| 981 | else if (!strcmp(args[cur_arg], "agent-port")) { |
| 982 | global.maxsock++; |
| 983 | newsrv->agent.port = atol(args[cur_arg + 1]); |
| 984 | cur_arg += 2; |
| 985 | } |
| 986 | else if (!defsrv && !strcmp(args[cur_arg], "cookie")) { |
| 987 | newsrv->cookie = strdup(args[cur_arg + 1]); |
| 988 | newsrv->cklen = strlen(args[cur_arg + 1]); |
| 989 | cur_arg += 2; |
| 990 | } |
| 991 | else if (!defsrv && !strcmp(args[cur_arg], "redir")) { |
| 992 | newsrv->rdr_pfx = strdup(args[cur_arg + 1]); |
| 993 | newsrv->rdr_len = strlen(args[cur_arg + 1]); |
| 994 | cur_arg += 2; |
| 995 | } |
| 996 | else if (!strcmp(args[cur_arg], "rise")) { |
| 997 | if (!*args[cur_arg + 1]) { |
| 998 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 999 | file, linenum, args[cur_arg]); |
| 1000 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1001 | goto out; |
| 1002 | } |
| 1003 | |
| 1004 | newsrv->check.rise = atol(args[cur_arg + 1]); |
| 1005 | if (newsrv->check.rise <= 0) { |
| 1006 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 1007 | file, linenum, args[cur_arg]); |
| 1008 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1009 | goto out; |
| 1010 | } |
| 1011 | |
| 1012 | if (newsrv->check.health) |
| 1013 | newsrv->check.health = newsrv->check.rise; |
| 1014 | cur_arg += 2; |
| 1015 | } |
| 1016 | else if (!strcmp(args[cur_arg], "fall")) { |
| 1017 | newsrv->check.fall = atol(args[cur_arg + 1]); |
| 1018 | |
| 1019 | if (!*args[cur_arg + 1]) { |
| 1020 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 1021 | file, linenum, args[cur_arg]); |
| 1022 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1023 | goto out; |
| 1024 | } |
| 1025 | |
| 1026 | if (newsrv->check.fall <= 0) { |
| 1027 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 1028 | file, linenum, args[cur_arg]); |
| 1029 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1030 | goto out; |
| 1031 | } |
| 1032 | |
| 1033 | cur_arg += 2; |
| 1034 | } |
| 1035 | else if (!strcmp(args[cur_arg], "inter")) { |
| 1036 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 1037 | if (err) { |
| 1038 | Alert("parsing [%s:%d] : unexpected character '%c' in 'inter' argument of server %s.\n", |
| 1039 | file, linenum, *err, newsrv->id); |
| 1040 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1041 | goto out; |
| 1042 | } |
| 1043 | if (val <= 0) { |
| 1044 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 1045 | file, linenum, val, args[cur_arg], newsrv->id); |
| 1046 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1047 | goto out; |
| 1048 | } |
| 1049 | newsrv->check.inter = val; |
| 1050 | cur_arg += 2; |
| 1051 | } |
| 1052 | else if (!strcmp(args[cur_arg], "fastinter")) { |
| 1053 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 1054 | if (err) { |
| 1055 | Alert("parsing [%s:%d]: unexpected character '%c' in 'fastinter' argument of server %s.\n", |
| 1056 | file, linenum, *err, newsrv->id); |
| 1057 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1058 | goto out; |
| 1059 | } |
| 1060 | if (val <= 0) { |
| 1061 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 1062 | file, linenum, val, args[cur_arg], newsrv->id); |
| 1063 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1064 | goto out; |
| 1065 | } |
| 1066 | newsrv->check.fastinter = val; |
| 1067 | cur_arg += 2; |
| 1068 | } |
| 1069 | else if (!strcmp(args[cur_arg], "downinter")) { |
| 1070 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 1071 | if (err) { |
| 1072 | Alert("parsing [%s:%d]: unexpected character '%c' in 'downinter' argument of server %s.\n", |
| 1073 | file, linenum, *err, newsrv->id); |
| 1074 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1075 | goto out; |
| 1076 | } |
| 1077 | if (val <= 0) { |
| 1078 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 1079 | file, linenum, val, args[cur_arg], newsrv->id); |
| 1080 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1081 | goto out; |
| 1082 | } |
| 1083 | newsrv->check.downinter = val; |
| 1084 | cur_arg += 2; |
| 1085 | } |
| 1086 | else if (!defsrv && !strcmp(args[cur_arg], "addr")) { |
| 1087 | struct sockaddr_storage *sk; |
| 1088 | int port1, port2; |
| 1089 | struct protocol *proto; |
| 1090 | |
| 1091 | sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL); |
| 1092 | if (!sk) { |
| 1093 | Alert("parsing [%s:%d] : '%s' : %s\n", |
| 1094 | file, linenum, args[cur_arg], errmsg); |
| 1095 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1096 | goto out; |
| 1097 | } |
| 1098 | |
| 1099 | proto = protocol_by_family(sk->ss_family); |
| 1100 | if (!proto || !proto->connect) { |
| 1101 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 1102 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 1103 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1104 | goto out; |
| 1105 | } |
| 1106 | |
| 1107 | if (port1 != port2) { |
| 1108 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 1109 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 1110 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1111 | goto out; |
| 1112 | } |
| 1113 | |
Simon Horman | 41f5876 | 2015-01-30 11:22:56 +0900 | [diff] [blame] | 1114 | newsrv->check.addr = newsrv->agent.addr = *sk; |
| 1115 | newsrv->check.proto = newsrv->agent.proto = protocol_by_family(sk->ss_family); |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1116 | cur_arg += 2; |
| 1117 | } |
| 1118 | else if (!strcmp(args[cur_arg], "port")) { |
| 1119 | newsrv->check.port = atol(args[cur_arg + 1]); |
| 1120 | cur_arg += 2; |
| 1121 | } |
| 1122 | else if (!defsrv && !strcmp(args[cur_arg], "backup")) { |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 1123 | newsrv->flags |= SRV_F_BACKUP; |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1124 | cur_arg ++; |
| 1125 | } |
| 1126 | else if (!defsrv && !strcmp(args[cur_arg], "non-stick")) { |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 1127 | newsrv->flags |= SRV_F_NON_STICK; |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1128 | cur_arg ++; |
| 1129 | } |
| 1130 | else if (!defsrv && !strcmp(args[cur_arg], "send-proxy")) { |
David S | afb7683 | 2014-05-08 23:42:08 -0400 | [diff] [blame] | 1131 | newsrv->pp_opts |= SRV_PP_V1; |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1132 | cur_arg ++; |
| 1133 | } |
David S | afb7683 | 2014-05-08 23:42:08 -0400 | [diff] [blame] | 1134 | else if (!defsrv && !strcmp(args[cur_arg], "send-proxy-v2")) { |
| 1135 | newsrv->pp_opts |= SRV_PP_V2; |
| 1136 | cur_arg ++; |
| 1137 | } |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1138 | else if (!defsrv && !strcmp(args[cur_arg], "check-send-proxy")) { |
| 1139 | newsrv->check.send_proxy = 1; |
| 1140 | cur_arg ++; |
| 1141 | } |
| 1142 | else if (!strcmp(args[cur_arg], "weight")) { |
| 1143 | int w; |
| 1144 | w = atol(args[cur_arg + 1]); |
| 1145 | if (w < 0 || w > SRV_UWGHT_MAX) { |
| 1146 | Alert("parsing [%s:%d] : weight of server %s is not within 0 and %d (%d).\n", |
| 1147 | file, linenum, newsrv->id, SRV_UWGHT_MAX, w); |
| 1148 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1149 | goto out; |
| 1150 | } |
| 1151 | newsrv->uweight = newsrv->iweight = w; |
| 1152 | cur_arg += 2; |
| 1153 | } |
| 1154 | else if (!strcmp(args[cur_arg], "minconn")) { |
| 1155 | newsrv->minconn = atol(args[cur_arg + 1]); |
| 1156 | cur_arg += 2; |
| 1157 | } |
| 1158 | else if (!strcmp(args[cur_arg], "maxconn")) { |
| 1159 | newsrv->maxconn = atol(args[cur_arg + 1]); |
| 1160 | cur_arg += 2; |
| 1161 | } |
| 1162 | else if (!strcmp(args[cur_arg], "maxqueue")) { |
| 1163 | newsrv->maxqueue = atol(args[cur_arg + 1]); |
| 1164 | cur_arg += 2; |
| 1165 | } |
| 1166 | else if (!strcmp(args[cur_arg], "slowstart")) { |
| 1167 | /* slowstart is stored in seconds */ |
| 1168 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 1169 | if (err) { |
| 1170 | Alert("parsing [%s:%d] : unexpected character '%c' in 'slowstart' argument of server %s.\n", |
| 1171 | file, linenum, *err, newsrv->id); |
| 1172 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1173 | goto out; |
| 1174 | } |
| 1175 | newsrv->slowstart = (val + 999) / 1000; |
| 1176 | cur_arg += 2; |
| 1177 | } |
| 1178 | else if (!defsrv && !strcmp(args[cur_arg], "track")) { |
| 1179 | |
| 1180 | if (!*args[cur_arg + 1]) { |
| 1181 | Alert("parsing [%s:%d]: 'track' expects [<proxy>/]<server> as argument.\n", |
| 1182 | file, linenum); |
| 1183 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1184 | goto out; |
| 1185 | } |
| 1186 | |
| 1187 | newsrv->trackit = strdup(args[cur_arg + 1]); |
| 1188 | |
| 1189 | cur_arg += 2; |
| 1190 | } |
| 1191 | else if (!defsrv && !strcmp(args[cur_arg], "check")) { |
| 1192 | global.maxsock++; |
| 1193 | do_check = 1; |
| 1194 | cur_arg += 1; |
| 1195 | } |
| 1196 | else if (!defsrv && !strcmp(args[cur_arg], "disabled")) { |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 1197 | newsrv->admin |= SRV_ADMF_FMAINT; |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 1198 | newsrv->state = SRV_ST_STOPPED; |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1199 | newsrv->check.state |= CHK_ST_PAUSED; |
| 1200 | newsrv->check.health = 0; |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1201 | cur_arg += 1; |
| 1202 | } |
| 1203 | else if (!defsrv && !strcmp(args[cur_arg], "observe")) { |
| 1204 | if (!strcmp(args[cur_arg + 1], "none")) |
| 1205 | newsrv->observe = HANA_OBS_NONE; |
| 1206 | else if (!strcmp(args[cur_arg + 1], "layer4")) |
| 1207 | newsrv->observe = HANA_OBS_LAYER4; |
| 1208 | else if (!strcmp(args[cur_arg + 1], "layer7")) { |
| 1209 | if (curproxy->mode != PR_MODE_HTTP) { |
| 1210 | Alert("parsing [%s:%d]: '%s' can only be used in http proxies.\n", |
| 1211 | file, linenum, args[cur_arg + 1]); |
| 1212 | err_code |= ERR_ALERT; |
| 1213 | } |
| 1214 | newsrv->observe = HANA_OBS_LAYER7; |
| 1215 | } |
| 1216 | else { |
| 1217 | Alert("parsing [%s:%d]: '%s' expects one of 'none', " |
| 1218 | "'layer4', 'layer7' but got '%s'\n", |
| 1219 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 1220 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1221 | goto out; |
| 1222 | } |
| 1223 | |
| 1224 | cur_arg += 2; |
| 1225 | } |
| 1226 | else if (!strcmp(args[cur_arg], "on-error")) { |
| 1227 | if (!strcmp(args[cur_arg + 1], "fastinter")) |
| 1228 | newsrv->onerror = HANA_ONERR_FASTINTER; |
| 1229 | else if (!strcmp(args[cur_arg + 1], "fail-check")) |
| 1230 | newsrv->onerror = HANA_ONERR_FAILCHK; |
| 1231 | else if (!strcmp(args[cur_arg + 1], "sudden-death")) |
| 1232 | newsrv->onerror = HANA_ONERR_SUDDTH; |
| 1233 | else if (!strcmp(args[cur_arg + 1], "mark-down")) |
| 1234 | newsrv->onerror = HANA_ONERR_MARKDWN; |
| 1235 | else { |
| 1236 | Alert("parsing [%s:%d]: '%s' expects one of 'fastinter', " |
| 1237 | "'fail-check', 'sudden-death' or 'mark-down' but got '%s'\n", |
| 1238 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 1239 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1240 | goto out; |
| 1241 | } |
| 1242 | |
| 1243 | cur_arg += 2; |
| 1244 | } |
| 1245 | else if (!strcmp(args[cur_arg], "on-marked-down")) { |
| 1246 | if (!strcmp(args[cur_arg + 1], "shutdown-sessions")) |
| 1247 | newsrv->onmarkeddown = HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS; |
| 1248 | else { |
| 1249 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-sessions' but got '%s'\n", |
| 1250 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 1251 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1252 | goto out; |
| 1253 | } |
| 1254 | |
| 1255 | cur_arg += 2; |
| 1256 | } |
| 1257 | else if (!strcmp(args[cur_arg], "on-marked-up")) { |
| 1258 | if (!strcmp(args[cur_arg + 1], "shutdown-backup-sessions")) |
| 1259 | newsrv->onmarkedup = HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS; |
| 1260 | else { |
| 1261 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-backup-sessions' but got '%s'\n", |
| 1262 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 1263 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1264 | goto out; |
| 1265 | } |
| 1266 | |
| 1267 | cur_arg += 2; |
| 1268 | } |
| 1269 | else if (!strcmp(args[cur_arg], "error-limit")) { |
| 1270 | if (!*args[cur_arg + 1]) { |
| 1271 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 1272 | file, linenum, args[cur_arg]); |
| 1273 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1274 | goto out; |
| 1275 | } |
| 1276 | |
| 1277 | newsrv->consecutive_errors_limit = atoi(args[cur_arg + 1]); |
| 1278 | |
| 1279 | if (newsrv->consecutive_errors_limit <= 0) { |
| 1280 | Alert("parsing [%s:%d]: %s has to be > 0.\n", |
| 1281 | file, linenum, args[cur_arg]); |
| 1282 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1283 | goto out; |
| 1284 | } |
| 1285 | cur_arg += 2; |
| 1286 | } |
| 1287 | else if (!defsrv && !strcmp(args[cur_arg], "source")) { /* address to which we bind when connecting */ |
| 1288 | int port_low, port_high; |
| 1289 | struct sockaddr_storage *sk; |
| 1290 | struct protocol *proto; |
| 1291 | |
| 1292 | if (!*args[cur_arg + 1]) { |
| 1293 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]], and optionally '%s' <addr>, and '%s' <name> as argument.\n", |
| 1294 | file, linenum, "source", "usesrc", "interface"); |
| 1295 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1296 | goto out; |
| 1297 | } |
| 1298 | |
| 1299 | newsrv->conn_src.opts |= CO_SRC_BIND; |
| 1300 | sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high, &errmsg, NULL); |
| 1301 | if (!sk) { |
| 1302 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
| 1303 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
| 1304 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1305 | goto out; |
| 1306 | } |
| 1307 | |
| 1308 | proto = protocol_by_family(sk->ss_family); |
| 1309 | if (!proto || !proto->connect) { |
| 1310 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 1311 | file, linenum, args[cur_arg], args[cur_arg+1]); |
| 1312 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1313 | goto out; |
| 1314 | } |
| 1315 | |
| 1316 | newsrv->conn_src.source_addr = *sk; |
| 1317 | |
| 1318 | if (port_low != port_high) { |
| 1319 | int i; |
| 1320 | |
| 1321 | if (!port_low || !port_high) { |
| 1322 | Alert("parsing [%s:%d] : %s does not support port offsets (found '%s').\n", |
| 1323 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 1324 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1325 | goto out; |
| 1326 | } |
| 1327 | |
| 1328 | if (port_low <= 0 || port_low > 65535 || |
| 1329 | port_high <= 0 || port_high > 65535 || |
| 1330 | port_low > port_high) { |
| 1331 | Alert("parsing [%s:%d] : invalid source port range %d-%d.\n", |
| 1332 | file, linenum, port_low, port_high); |
| 1333 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1334 | goto out; |
| 1335 | } |
| 1336 | newsrv->conn_src.sport_range = port_range_alloc_range(port_high - port_low + 1); |
| 1337 | for (i = 0; i < newsrv->conn_src.sport_range->size; i++) |
| 1338 | newsrv->conn_src.sport_range->ports[i] = port_low + i; |
| 1339 | } |
| 1340 | |
| 1341 | cur_arg += 2; |
| 1342 | while (*(args[cur_arg])) { |
| 1343 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
| 1344 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
| 1345 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | 9cf8d3f | 2014-05-09 22:56:10 +0200 | [diff] [blame] | 1346 | if (!is_inet_addr(&newsrv->conn_src.source_addr)) { |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1347 | Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n", |
| 1348 | file, linenum, "usesrc", "source"); |
| 1349 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1350 | goto out; |
| 1351 | } |
| 1352 | #endif |
| 1353 | if (!*args[cur_arg + 1]) { |
| 1354 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', 'clientip', or 'hdr_ip(name,#)' as argument.\n", |
| 1355 | file, linenum, "usesrc"); |
| 1356 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1357 | goto out; |
| 1358 | } |
| 1359 | if (!strcmp(args[cur_arg + 1], "client")) { |
| 1360 | newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 1361 | newsrv->conn_src.opts |= CO_SRC_TPROXY_CLI; |
| 1362 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
| 1363 | newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 1364 | newsrv->conn_src.opts |= CO_SRC_TPROXY_CIP; |
| 1365 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 1366 | char *name, *end; |
| 1367 | |
| 1368 | name = args[cur_arg+1] + 7; |
| 1369 | while (isspace(*name)) |
| 1370 | name++; |
| 1371 | |
| 1372 | end = name; |
| 1373 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 1374 | end++; |
| 1375 | |
| 1376 | newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 1377 | newsrv->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 1378 | newsrv->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 1379 | newsrv->conn_src.bind_hdr_len = end - name; |
| 1380 | memcpy(newsrv->conn_src.bind_hdr_name, name, end - name); |
| 1381 | newsrv->conn_src.bind_hdr_name[end-name] = '\0'; |
| 1382 | newsrv->conn_src.bind_hdr_occ = -1; |
| 1383 | |
| 1384 | /* now look for an occurrence number */ |
| 1385 | while (isspace(*end)) |
| 1386 | end++; |
| 1387 | if (*end == ',') { |
| 1388 | end++; |
| 1389 | name = end; |
| 1390 | if (*end == '-') |
| 1391 | end++; |
| 1392 | while (isdigit((int)*end)) |
| 1393 | end++; |
| 1394 | newsrv->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
| 1395 | } |
| 1396 | |
| 1397 | if (newsrv->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 1398 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 1399 | " occurrences values smaller than %d.\n", |
| 1400 | file, linenum, MAX_HDR_HISTORY); |
| 1401 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1402 | goto out; |
| 1403 | } |
| 1404 | } else { |
| 1405 | struct sockaddr_storage *sk; |
| 1406 | int port1, port2; |
| 1407 | |
| 1408 | sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL); |
| 1409 | if (!sk) { |
| 1410 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
| 1411 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
| 1412 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1413 | goto out; |
| 1414 | } |
| 1415 | |
| 1416 | proto = protocol_by_family(sk->ss_family); |
| 1417 | if (!proto || !proto->connect) { |
| 1418 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 1419 | file, linenum, args[cur_arg], args[cur_arg+1]); |
| 1420 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1421 | goto out; |
| 1422 | } |
| 1423 | |
| 1424 | if (port1 != port2) { |
| 1425 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 1426 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 1427 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1428 | goto out; |
| 1429 | } |
| 1430 | newsrv->conn_src.tproxy_addr = *sk; |
| 1431 | newsrv->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
| 1432 | } |
| 1433 | global.last_checks |= LSTCHK_NETADM; |
| 1434 | #if !defined(CONFIG_HAP_TRANSPARENT) |
| 1435 | global.last_checks |= LSTCHK_CTTPROXY; |
| 1436 | #endif |
| 1437 | cur_arg += 2; |
| 1438 | continue; |
| 1439 | #else /* no TPROXY support */ |
| 1440 | Alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n", |
| 1441 | file, linenum, "usesrc"); |
| 1442 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1443 | goto out; |
| 1444 | #endif /* defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) */ |
| 1445 | } /* "usesrc" */ |
| 1446 | |
| 1447 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 1448 | #ifdef SO_BINDTODEVICE |
| 1449 | if (!*args[cur_arg + 1]) { |
| 1450 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 1451 | file, linenum, args[0]); |
| 1452 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1453 | goto out; |
| 1454 | } |
| 1455 | free(newsrv->conn_src.iface_name); |
| 1456 | newsrv->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 1457 | newsrv->conn_src.iface_len = strlen(newsrv->conn_src.iface_name); |
| 1458 | global.last_checks |= LSTCHK_NETADM; |
| 1459 | #else |
| 1460 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1461 | file, linenum, args[0], args[cur_arg]); |
| 1462 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1463 | goto out; |
| 1464 | #endif |
| 1465 | cur_arg += 2; |
| 1466 | continue; |
| 1467 | } |
| 1468 | /* this keyword in not an option of "source" */ |
| 1469 | break; |
| 1470 | } /* while */ |
| 1471 | } |
| 1472 | else if (!defsrv && !strcmp(args[cur_arg], "usesrc")) { /* address to use outside: needs "source" first */ |
| 1473 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 1474 | file, linenum, "usesrc", "source"); |
| 1475 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1476 | goto out; |
| 1477 | } |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 1478 | else if (!defsrv && !strcmp(args[cur_arg], "namespace")) { |
| 1479 | #ifdef CONFIG_HAP_NS |
| 1480 | char *arg = args[cur_arg + 1]; |
| 1481 | if (!strcmp(arg, "*")) { |
| 1482 | newsrv->flags |= SRV_F_USE_NS_FROM_PP; |
| 1483 | } else { |
| 1484 | newsrv->netns = netns_store_lookup(arg, strlen(arg)); |
| 1485 | |
| 1486 | if (newsrv->netns == NULL) |
| 1487 | newsrv->netns = netns_store_insert(arg); |
| 1488 | |
| 1489 | if (newsrv->netns == NULL) { |
| 1490 | Alert("Cannot open namespace '%s'.\n", args[cur_arg + 1]); |
| 1491 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1492 | goto out; |
| 1493 | } |
| 1494 | } |
| 1495 | #else |
| 1496 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1497 | file, linenum, args[0], args[cur_arg]); |
| 1498 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1499 | goto out; |
| 1500 | #endif |
| 1501 | cur_arg += 2; |
| 1502 | } |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1503 | else { |
| 1504 | static int srv_dumped; |
| 1505 | struct srv_kw *kw; |
| 1506 | char *err; |
| 1507 | |
| 1508 | kw = srv_find_kw(args[cur_arg]); |
| 1509 | if (kw) { |
| 1510 | char *err = NULL; |
| 1511 | int code; |
| 1512 | |
| 1513 | if (!kw->parse) { |
| 1514 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 1515 | file, linenum, args[0], args[1], args[cur_arg]); |
| 1516 | cur_arg += 1 + kw->skip ; |
| 1517 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1518 | goto out; |
| 1519 | } |
| 1520 | |
| 1521 | if (defsrv && !kw->default_ok) { |
| 1522 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not accepted in default-server sections.\n", |
| 1523 | file, linenum, args[0], args[1], args[cur_arg]); |
| 1524 | cur_arg += 1 + kw->skip ; |
| 1525 | err_code |= ERR_ALERT; |
| 1526 | continue; |
| 1527 | } |
| 1528 | |
| 1529 | code = kw->parse(args, &cur_arg, curproxy, newsrv, &err); |
| 1530 | err_code |= code; |
| 1531 | |
| 1532 | if (code) { |
| 1533 | if (err && *err) { |
| 1534 | indent_msg(&err, 2); |
| 1535 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err); |
| 1536 | } |
| 1537 | else |
| 1538 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 1539 | file, linenum, args[0], args[1], args[cur_arg]); |
| 1540 | if (code & ERR_FATAL) { |
| 1541 | free(err); |
| 1542 | cur_arg += 1 + kw->skip; |
| 1543 | goto out; |
| 1544 | } |
| 1545 | } |
| 1546 | free(err); |
| 1547 | cur_arg += 1 + kw->skip; |
| 1548 | continue; |
| 1549 | } |
| 1550 | |
| 1551 | err = NULL; |
| 1552 | if (!srv_dumped) { |
| 1553 | srv_dump_kws(&err); |
| 1554 | indent_msg(&err, 4); |
| 1555 | srv_dumped = 1; |
| 1556 | } |
| 1557 | |
| 1558 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 1559 | file, linenum, args[0], args[1], args[cur_arg], |
| 1560 | err ? " Registered keywords :" : "", err ? err : ""); |
| 1561 | free(err); |
| 1562 | |
| 1563 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1564 | goto out; |
| 1565 | } |
| 1566 | } |
| 1567 | |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1568 | if (do_check) { |
Simon Horman | b1900d5 | 2015-01-30 11:22:54 +0900 | [diff] [blame] | 1569 | const char *ret; |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1570 | |
| 1571 | if (newsrv->trackit) { |
| 1572 | Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n", |
| 1573 | file, linenum); |
| 1574 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1575 | goto out; |
| 1576 | } |
| 1577 | |
| 1578 | /* If neither a port nor an addr was specified and no check transport |
| 1579 | * layer is forced, then the transport layer used by the checks is the |
| 1580 | * same as for the production traffic. Otherwise we use raw_sock by |
| 1581 | * default, unless one is specified. |
| 1582 | */ |
Simon Horman | 41f5876 | 2015-01-30 11:22:56 +0900 | [diff] [blame] | 1583 | if (!newsrv->check.port && !is_addr(&newsrv->check.addr)) { |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1584 | #ifdef USE_OPENSSL |
| 1585 | newsrv->check.use_ssl |= (newsrv->use_ssl || (newsrv->proxy->options & PR_O_TCPCHK_SSL)); |
| 1586 | #endif |
David S | afb7683 | 2014-05-08 23:42:08 -0400 | [diff] [blame] | 1587 | newsrv->check.send_proxy |= (newsrv->pp_opts); |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1588 | } |
| 1589 | /* try to get the port from check_core.addr if check.port not set */ |
| 1590 | if (!newsrv->check.port) |
Simon Horman | 41f5876 | 2015-01-30 11:22:56 +0900 | [diff] [blame] | 1591 | newsrv->check.port = get_host_port(&newsrv->check.addr); |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1592 | |
| 1593 | if (!newsrv->check.port) |
| 1594 | newsrv->check.port = realport; /* by default */ |
| 1595 | |
| 1596 | if (!newsrv->check.port) { |
| 1597 | /* not yet valid, because no port was set on |
| 1598 | * the server either. We'll check if we have |
| 1599 | * a known port on the first listener. |
| 1600 | */ |
| 1601 | struct listener *l; |
| 1602 | |
| 1603 | list_for_each_entry(l, &curproxy->conf.listeners, by_fe) { |
| 1604 | newsrv->check.port = get_host_port(&l->addr); |
| 1605 | if (newsrv->check.port) |
| 1606 | break; |
| 1607 | } |
| 1608 | } |
| 1609 | /* |
| 1610 | * We need at least a service port, a check port or the first tcp-check rule must |
Willy Tarreau | 5cf0b52 | 2014-05-09 23:59:19 +0200 | [diff] [blame] | 1611 | * be a 'connect' one when checking an IPv4/IPv6 server. |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1612 | */ |
Willy Tarreau | 5cf0b52 | 2014-05-09 23:59:19 +0200 | [diff] [blame] | 1613 | if (!newsrv->check.port && |
Simon Horman | 41f5876 | 2015-01-30 11:22:56 +0900 | [diff] [blame] | 1614 | (is_inet_addr(&newsrv->check.addr) || |
| 1615 | (!is_addr(&newsrv->check.addr) && is_inet_addr(&newsrv->addr)))) { |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1616 | struct tcpcheck_rule *n = NULL, *r = NULL; |
| 1617 | struct list *l; |
| 1618 | |
| 1619 | r = (struct tcpcheck_rule *)newsrv->proxy->tcpcheck_rules.n; |
| 1620 | if (!r) { |
| 1621 | Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n", |
| 1622 | file, linenum, newsrv->id); |
| 1623 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1624 | goto out; |
| 1625 | } |
| 1626 | if ((r->action != TCPCHK_ACT_CONNECT) || !r->port) { |
| 1627 | Alert("parsing [%s:%d] : server %s has neither service port nor check port nor tcp_check rule 'connect' with port information. Check has been disabled.\n", |
| 1628 | file, linenum, newsrv->id); |
| 1629 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1630 | goto out; |
| 1631 | } |
| 1632 | else { |
| 1633 | /* scan the tcp-check ruleset to ensure a port has been configured */ |
| 1634 | l = &newsrv->proxy->tcpcheck_rules; |
| 1635 | list_for_each_entry(n, l, list) { |
| 1636 | r = (struct tcpcheck_rule *)n->list.p; |
| 1637 | if ((r->action == TCPCHK_ACT_CONNECT) && (!r->port)) { |
| 1638 | Alert("parsing [%s:%d] : server %s has neither service port nor check port, and a tcp_check rule 'connect' with no port information. Check has been disabled.\n", |
| 1639 | file, linenum, newsrv->id); |
| 1640 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1641 | goto out; |
| 1642 | } |
| 1643 | } |
| 1644 | } |
| 1645 | } |
| 1646 | |
| 1647 | /* note: check type will be set during the config review phase */ |
Simon Horman | b1900d5 | 2015-01-30 11:22:54 +0900 | [diff] [blame] | 1648 | ret = init_check(&newsrv->check, 0); |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1649 | if (ret) { |
Simon Horman | b1900d5 | 2015-01-30 11:22:54 +0900 | [diff] [blame] | 1650 | Alert("parsing [%s:%d] : %s.\n", file, linenum, ret); |
| 1651 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1652 | goto out; |
| 1653 | } |
| 1654 | |
| 1655 | newsrv->check.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED; |
| 1656 | } |
| 1657 | |
| 1658 | if (do_agent) { |
Simon Horman | b1900d5 | 2015-01-30 11:22:54 +0900 | [diff] [blame] | 1659 | const char *ret; |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1660 | |
| 1661 | if (!newsrv->agent.port) { |
| 1662 | Alert("parsing [%s:%d] : server %s does not have agent port. Agent check has been disabled.\n", |
| 1663 | file, linenum, newsrv->id); |
| 1664 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1665 | goto out; |
| 1666 | } |
| 1667 | |
| 1668 | if (!newsrv->agent.inter) |
| 1669 | newsrv->agent.inter = newsrv->check.inter; |
| 1670 | |
Simon Horman | b1900d5 | 2015-01-30 11:22:54 +0900 | [diff] [blame] | 1671 | ret = init_check(&newsrv->agent, PR_O2_LB_AGENT_CHK); |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1672 | if (ret) { |
Simon Horman | b1900d5 | 2015-01-30 11:22:54 +0900 | [diff] [blame] | 1673 | Alert("parsing [%s:%d] : %s.\n", file, linenum, ret); |
| 1674 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1675 | goto out; |
| 1676 | } |
| 1677 | |
| 1678 | newsrv->agent.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED | CHK_ST_AGENT; |
| 1679 | } |
| 1680 | |
| 1681 | if (!defsrv) { |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 1682 | if (newsrv->flags & SRV_F_BACKUP) |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1683 | curproxy->srv_bck++; |
| 1684 | else |
| 1685 | curproxy->srv_act++; |
| 1686 | |
Willy Tarreau | c5150da | 2014-05-13 19:27:31 +0200 | [diff] [blame] | 1687 | srv_lb_commit_status(newsrv); |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 1688 | } |
| 1689 | } |
| 1690 | return 0; |
| 1691 | |
| 1692 | out: |
| 1693 | free(errmsg); |
| 1694 | return err_code; |
| 1695 | } |
| 1696 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1697 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1698 | * Local variables: |
| 1699 | * c-indent-level: 8 |
| 1700 | * c-basic-offset: 8 |
| 1701 | * End: |
| 1702 | */ |