--- haproxy_orig.c 2004-11-05 16:52:09.189374251 +0100 +++ haproxy.c 2004-11-05 19:08:22.125006470 +0100 @@ -309,6 +310,7 @@ #define SRV_RUNNING 1 /* the server is UP */ #define SRV_BACKUP 2 /* this server is a backup server */ #define SRV_MAPPORTS 4 /* this server uses mapped ports */ +#define SRV_COMA 8 /* this server uses mapped ports */ /* what to do when a header matches a regex */ #define ACT_ALLOW 0 /* allow the request */ @@ -486,6 +488,11 @@ int state; /* the state of this fd */ }; +struct coma_list{ + char server_name[256]; + struct coma_list *next; +}; /* end struct coma_list */ + /*********************************************************************/ int cfg_maxpconn = 2000; /* # of simultaneous connections per proxy (-N) */ @@ -1447,8 +1454,10 @@ do { if (srv == NULL) srv = px->srv; - if (srv->state & SRV_RUNNING - && !((srv->state & SRV_BACKUP) && ignore_backup)) + /* tv_delayfrom(&p->stop_time, &now, p->grace); + grace_shut + */ + if (!(srv->state & SRV_COMA) && srv->state & SRV_RUNNING && !((srv->state & SRV_BACKUP) && ignore_backup )) return srv; srv = srv->next; } while (srv != px->cursrv); @@ -2754,25 +2763,52 @@ /* Cool... it's the right one */ struct server *srv = t->proxy->srv; - while (srv && - ((srv->cklen != p4 - p3) || memcmp(p3, srv->cookie, p4 - p3))) { + /* + while (srv && ((srv->cklen != p4 - p3) || memcmp(p3, srv->cookie, p4 - p3))) { srv = srv->next; - } + } + */ + + while (srv){ + if((srv->cklen == p4 - p3) && !( memcmp(p3, srv->cookie, p4 - p3))){ + if (srv->state & SRV_RUNNING || t->proxy->options & PR_O_PERSIST) { + /* we found the server and it's usable */ + t->flags &= ~SN_CK_MASK; + t->flags |= SN_CK_VALID | SN_DIRECT; + t->srv = srv; + //fprintf(stderr,">>> bin im else if im process_cli\n"); + break; + }else { + t->flags &= ~SN_CK_MASK; + t->flags |= SN_CK_DOWN; + //fprintf(stderr,">>> bin im else im process_cli\n"); + } + } + //fprintf(stderr,">>> while srv\n"); + srv = srv->next; + }/* end while(srv) */ - if (!srv) { + //fprintf(stderr,">>> end while srv\n"); + + if (!srv && !(t->flags & SN_CK_DOWN)) { t->flags &= ~SN_CK_MASK; t->flags |= SN_CK_INVALID; } + + /* state SLEEP * / else if (srv->state & SRV_RUNNING || t->proxy->options & PR_O_PERSIST) { - /* we found the server and it's usable */ + /* we found the server and it's usable * / t->flags &= ~SN_CK_MASK; t->flags |= SN_CK_VALID | SN_DIRECT; t->srv = srv; + fprintf(stderr,"bin im else if im process_cli\n"); } else { t->flags &= ~SN_CK_MASK; t->flags |= SN_CK_DOWN; + fprintf(stderr,"bin im else im process_cli\n"); } + */ /* if this cookie was set in insert+indirect mode, then it's better that the * server never sees it. @@ -3093,6 +3129,8 @@ int len; len = sprintf(trash, "%08x:%s.clicls[%04x:%04x]\n", t->uniq_id, t->proxy->id, (unsigned short)t->cli_fd, (unsigned short)t->srv_fd); write(1, trash, len); + len = sprintf(trash, "%08X:%s.Flags:%08X\n", t->uniq_id, t->proxy->id,t->flags); + write(1, trash, len); } return 0; } @@ -4437,15 +4475,19 @@ send_log(p, LOG_NOTICE, "SIGUP received, dumping servers states.\n"); while (s) { - if (s->state & SRV_RUNNING) { - Warning("SIGHUP: server %s/%s is UP.\n", p->id, s->id); - send_log(p, LOG_NOTICE, "SIGUP: server %s/%s is UP.\n", p->id, s->id); - } - else { - Warning("SIGHUP: server %s/%s is DOWN.\n", p->id, s->id); - send_log(p, LOG_NOTICE, "SIGHUP: server %s/%s is DOWN.\n", p->id, s->id); - } - s = s->next; + if (s->state & SRV_COMA) { + Warning("SIGHUP: server %s/%s is in COMA.\n", p->id, s->id); + send_log(p, LOG_NOTICE, "SIGUP: server %s/%s is in COMA.\n", p->id, s->id); + } + else if (s->state & SRV_RUNNING) { + Warning("SIGHUP: server %s/%s is UP.\n", p->id, s->id); + send_log(p, LOG_NOTICE, "SIGUP: server %s/%s is UP.\n", p->id, s->id); + } + else { + Warning("SIGHUP: server %s/%s is DOWN.\n", p->id, s->id); + send_log(p, LOG_NOTICE, "SIGHUP: server %s/%s is DOWN.\n", p->id, s->id); + } + s = s->next; } if (find_server(p) == NULL) { @@ -4481,6 +4523,98 @@ } } +/* + * this function + */ +void sig_set_server_coma(int sig) { + struct proxy *p = proxy; + FILE *coma_f = NULL; + char *line = NULL; + char thisline[256]; + int linenum = 0; + struct coma_list head, *temp = NULL, *new = NULL; + + memset(thisline,'\0',256); + + Warning("SIGUSR2 received, set coma servers.\n"); + + if ((coma_f=fopen("comafile.txt","r")) == NULL){ + Warning("can't open comafile.txt.\n"); + return; + } + + head.next = NULL; + temp = &head; + while (fgets(thisline,256, coma_f) != NULL) { + linenum++; + if (thisline[0] != '\0' && thisline[0] != '#') { + if ((new = malloc(sizeof(struct coma_list))) == NULL) { + Alert("parsing [comafile.txt:%d] : out of memory.\n", linenum); + fclose(coma_f); + return; + } + thisline[strlen(thisline)-1]='\0'; + Warning("thisline :%s:\n",thisline); + temp->next = new; + new->next = NULL; + strncpy(new->server_name, thisline, 256); + temp = new; + } + } /* end while */ + fclose(coma_f); + + while (p) { + struct server *s = p->srv; + while (s) { + temp = head.next; + while (temp){ + if (!strcmp(temp->server_name, s->id)) { + s->state |= SRV_COMA; + Warning("Set %s to coma state\n",s->id); + break; + } + temp = temp->next; + } + if (!temp) s->state &= ~SRV_COMA; + s = s->next; + } + p = p->next; + } + + while (head.next) { + temp = head.next; + head.next = temp->next; + free(temp); + } + /* + while (p) { + struct server *s = p->srv; + + send_log(p, LOG_NOTICE, "SIGUP received, dumping servers states.\n"); + while (s) { + if (s->state & SRV_RUNNING) { + Warning("SIGHUP: server %s/%s is UP.\n", p->id, s->id); + send_log(p, LOG_NOTICE, "SIGUP: server %s/%s is UP.\n", p->id, s->id); + } + else { + Warning("SIGHUP: server %s/%s is DOWN.\n", p->id, s->id); + send_log(p, LOG_NOTICE, "SIGHUP: server %s/%s is DOWN.\n", p->id, s->id); + } + s = s->next; + } + + if (find_server(p) == NULL) { + Warning("SIGHUP: proxy %s has no server available !\n", p); + send_log(p, LOG_NOTICE, "SIGHUP: proxy %s has no server available !\n", p); + } + + p = p->next; + } + */ + + signal(sig, sig_set_server_coma); +}/* end sig_set_server_coma */ + void chain_regex(struct hdr_exp **head, regex_t *preg, int action, char *replace) { struct hdr_exp *exp; @@ -6133,6 +6267,7 @@ signal(SIGQUIT, dump); signal(SIGUSR1, sig_soft_stop); + signal(SIGUSR2, sig_set_server_coma); signal(SIGHUP, sig_dump_state); /* on very high loads, a sigpipe sometimes happen just between the