From fd1c7773ee8202b9bd35df53b1ffcac1212e3416 Mon Sep 17 00:00:00 2001 From: "roberto@maverick64" Date: Sat, 15 Jan 2011 12:56:10 +0100 Subject: [PATCH] gateways implementation -> proxy plugin --- buildconf/default.ini | 3 +- erlang.c | 31 ++++++- gateway.c | 83 +++++++++++++++++++ master.c | 34 ++++---- proxy.c => plugins/proxy/proxy.c | 105 +++++++++++++++++++++--- plugins/proxy/uwsgiplugin.py | 7 ++ uwsgi.c | 133 ++++++++----------------------- uwsgi.h | 34 ++++---- uwsgiconfig.py | 14 +--- 9 files changed, 286 insertions(+), 158 deletions(-) create mode 100644 gateway.c rename proxy.c => plugins/proxy/proxy.c (81%) create mode 100644 plugins/proxy/uwsgiplugin.py diff --git a/buildconf/default.ini b/buildconf/default.ini index eb4030a0..a404be47 100644 --- a/buildconf/default.ini +++ b/buildconf/default.ini @@ -11,7 +11,6 @@ udp = true multicast = true threading = true sendfile = true -proxy = true minterpreters = true async = true http = true @@ -25,7 +24,7 @@ xml_implementation = libxml2 plugins = bin_name = uwsgi plugin_dir = . -embedded_plugins = python, ping, nagios, rpc +embedded_plugins = python, ping, proxy, nagios, rpc locking = auto event = auto diff --git a/erlang.c b/erlang.c index 3a8db2cd..7ae9dd3f 100644 --- a/erlang.c +++ b/erlang.c @@ -6,6 +6,7 @@ extern struct uwsgi_server uwsgi; static void erlang_log(void); +/* PyObject *py_erlang_connect(PyObject * self, PyObject * args) { char *erlang_node; @@ -298,6 +299,7 @@ static PyMethodDef uwsgi_erlang_methods[] = { {NULL, NULL}, }; +*/ int init_erlang(char *nodename, char *cookie) { @@ -312,7 +314,8 @@ int init_erlang(char *nodename, char *cookie) { char cookievalue[128]; int cookiefd; - PyMethodDef *uwsgi_function; + + //PyMethodDef *uwsgi_function; ip = strchr(nodename, '@'); @@ -322,6 +325,7 @@ int init_erlang(char *nodename, char *cookie) { return -1; } + uwsgi_log("using cookie %s\n", cookie); if (cookie == NULL) { // get the cookie from the home cookiehome = getenv("HOME"); @@ -416,16 +420,19 @@ int init_erlang(char *nodename, char *cookie) { uwsgi_log( "Erlang C-Node initialized on port %d you can access it with name %s\n", ntohs(e_addr.sin_port), nodename); +/* for (uwsgi_function = uwsgi_erlang_methods; uwsgi_function->ml_name != NULL; uwsgi_function++) { PyObject *func = PyCFunction_New(uwsgi_function, NULL); PyDict_SetItemString(uwsgi.embedded_dict, uwsgi_function->ml_name, func); Py_DECREF(func); } +*/ return efd; } +/* ETERM *py_to_eterm(PyObject * pobj) { int i; int count; @@ -593,13 +600,16 @@ PyObject *eterm_to_py(ETERM * obj) { return eobj; } +*/ void erlang_loop(struct wsgi_request *wsgi_req) { ErlConnect econn; ErlMessage em; - ETERM *eresponse; + unsigned char buffer[4096]; + //ETERM *eresponse; +/* PyObject *callable = PyDict_GetItemString(uwsgi.embedded_dict, "erlang_func"); if (!callable) { PyErr_Print(); @@ -612,21 +622,30 @@ void erlang_loop(struct wsgi_request *wsgi_req) { uwsgi_log( "- error preparing arg tuple for uwsgi.erlang_func callable, Erlang message manager will be disabled -\n"); } +*/ + while (uwsgi.workers[uwsgi.mywid].manage_next_request) { + uwsgi_log("entering erlang cycle\n"); UWSGI_CLEAR_STATUS; wsgi_req->poll.fd = erl_accept(uwsgi.erlangfd, &econn); + uwsgi_log("accepted %d\n", wsgi_req->poll.fd); + if (wsgi_req->poll.fd >= 0) { UWSGI_SET_ERLANGING; for (;;) { - if (erl_receive_msg(wsgi_req->poll.fd, (unsigned char *) wsgi_req->buffer, uwsgi.buffer_size, &em) == ERL_MSG) { + uwsgi_log("receive message\n"); + if (erl_receive_msg(wsgi_req->poll.fd, buffer, 4096, &em) == ERL_MSG) { + + uwsgi_log("message received\n"); if (em.type == ERL_TICK) continue; + /* if (!callable) { callable = PyDict_GetItemString(uwsgi.embedded_dict, "erlang_func"); } @@ -636,6 +655,9 @@ void erlang_loop(struct wsgi_request *wsgi_req) { } PyObject *zero = eterm_to_py(em.msg); + + */ + uwsgi_log("received object %d\n", ERL_TYPE(em.msg)); if (em.msg) { erl_free_compound(em.msg); } @@ -643,6 +665,7 @@ void erlang_loop(struct wsgi_request *wsgi_req) { erl_free_compound(em.to); } + /* if (!zero) { PyErr_Print(); continue; @@ -666,6 +689,7 @@ void erlang_loop(struct wsgi_request *wsgi_req) { Py_DECREF(erlang_result); } + */ if (em.from) { erl_free_compound(em.from); } @@ -676,6 +700,7 @@ void erlang_loop(struct wsgi_request *wsgi_req) { erlang_log(); } else { + uwsgi_log("oooops\n"); break; } } diff --git a/gateway.c b/gateway.c new file mode 100644 index 00000000..479b30a9 --- /dev/null +++ b/gateway.c @@ -0,0 +1,83 @@ +#include "uwsgi.h" + +extern struct uwsgi_server uwsgi; + +struct uwsgi_gateway *register_gateway(char *name, void (*loop)(void)) { + + pid_t gw_pid; + pid_t orig_pid = getpid(); + struct uwsgi_gateway *ug; + int num=1,i; + + if (uwsgi.gateways_cnt >= MAX_GATEWAYS) { + uwsgi_log("you can register max %d gateways\n", MAX_GATEWAYS); + return NULL; + } + + for(i=0;i 0) { + loop(); + // never here !!! (i hope) + exit(1); + } + + ug = &uwsgi.gateways[uwsgi.gateways_cnt]; + ug->pid = orig_pid; + } + else { + if (gw_pid == 0) { + loop(); + // never here !!! (i hope) + exit(1); + } + + ug = &uwsgi.gateways[uwsgi.gateways_cnt]; + ug->pid = gw_pid; + } + + + ug->name = name; + ug->loop = loop; + ug->num = num; + + uwsgi_log( "spawned uWSGI %s %d (pid: %d)\n", ug->name, ug->num, (int) ug->pid); + + uwsgi.gateways_cnt++; + + return ug; + +} + +void gateway_respawn(int id) { + + pid_t gw_pid; + struct uwsgi_gateway *ug = &uwsgi.gateways[id]; + + gw_pid = fork(); + if (gw_pid < 0) { + uwsgi_error("fork()"); + return; + } + + if (gw_pid == 0) { + ug->loop(); + // never here !!! (i hope) + exit(1); + } + + ug->pid = gw_pid; + uwsgi_log( "respawned uWSGI %s %d (pid: %d)\n", ug->name, ug->num, (int) gw_pid); + +} diff --git a/master.c b/master.c index a9eeebd1..77790ed9 100644 --- a/master.c +++ b/master.c @@ -59,6 +59,7 @@ void master_loop(char **argv, char **environ) { struct timeval last_respawn; pid_t pid; + int pid_found = 0; pid_t diedpid; int waitpid_status; @@ -229,12 +230,7 @@ void master_loop(char **argv, char **environ) { #endif -#ifdef UWSGI_PROXY - if (uwsgi.proxy_socket_name && uwsgi.shared->proxy_pid > 0) { - kill(uwsgi.shared->proxy_pid, SIGKILL); - uwsgi_log( "killed proxy with pid %d\n", uwsgi.shared->proxy_pid); - } -#endif + // TODO kill all the gateways uwsgi_log( "goodbye to uWSGI.\n"); exit(0); } @@ -249,12 +245,7 @@ void master_loop(char **argv, char **environ) { #endif #ifdef UWSGI_PROXY - if (uwsgi.proxy_socket_name && uwsgi.shared->proxy_pid > 0) { - kill(uwsgi.shared->proxy_pid, SIGKILL); - uwsgi_log( "wait4() the proxy with pid %d...", uwsgi.shared->proxy_pid); - diedpid = waitpid(uwsgi.shared->proxy_pid, &waitpid_status, 0); - uwsgi_log( "done."); - } + // TODO gracefully kill all the gateways (wait4 them) [see the spooler] #endif uwsgi_log( "binary reloading uWSGI...\n"); if (chdir(uwsgi.cwd)) { @@ -286,7 +277,7 @@ void master_loop(char **argv, char **environ) { exit(1); } - if (uwsgi.numproc > 0 ) { + if (uwsgi.numproc > 0 || uwsgi.gateways_cnt > 0) { master_has_children = 1; } #ifdef UWSGI_SPOOLER @@ -298,6 +289,7 @@ void master_loop(char **argv, char **environ) { if (uwsgi.proxy_socket_name && uwsgi.shared->proxy_pid > 0) { master_has_children = 1; } + // TODO if gateways > 0 master_has_children == 1 #endif if (!master_has_children) { @@ -634,8 +626,19 @@ void master_loop(char **argv, char **environ) { } #endif + /* reload the gateways */ + // TODO reload_gateway(diedpid); + pid_found = 0; + for(i=0;iproxy_pid > 0) { if (diedpid == uwsgi.shared->proxy_pid) { if (WIFEXITED(waitpid_status)) { @@ -736,7 +739,8 @@ void master_loop(char **argv, char **environ) { #endif #ifdef UWSGI_PROXY - if (diedpid != uwsgi.shared->proxy_pid) { + // TODO if no gateway span the error !!! + if (diedpid != uwsgi.shared->proxy_pid) { #endif uwsgi_log( "warning the died pid was not in the workers list. Probably you hit a BUG of uWSGI\n"); #ifdef UWSGI_PROXY diff --git a/proxy.c b/plugins/proxy/proxy.c similarity index 81% rename from proxy.c rename to plugins/proxy/proxy.c index 034e1297..c22435da 100644 --- a/proxy.c +++ b/plugins/proxy/proxy.c @@ -1,5 +1,3 @@ -#ifdef UWSGI_PROXY - /* uWSGI proxy @@ -12,7 +10,24 @@ */ -#include "uwsgi.h" +#include "../../uwsgi.h" + +#define LONG_ARGS_PROXY_WORKERS 50000 + +struct uwsgi_proxy { + char *socket_name; + int add_me; + int workers; + int fd; +} uproxy; + +struct option proxy_options[] = { + {"proxy", required_argument, 0, LONG_ARGS_PROXY}, + {"proxy-node", required_argument, 0, LONG_ARGS_PROXY_NODE}, + {"proxy-max-connections", required_argument, 0, LONG_ARGS_PROXY_MAX_CONNECTIONS}, + {"proxy-workers", required_argument, 0, LONG_ARGS_PROXY_WORKERS}, + {0, 0, 0, 0}, +}; #define UWSGI_PROXY_CONNECTING 1 #define UWSGI_PROXY_WAITING 2 @@ -98,7 +113,8 @@ static int uwsgi_proxy_find_next_node(int current_node) { return -1; } -void uwsgi_proxy(int proxyfd) { +void proxy_loop() { + int efd; #ifdef __linux__ @@ -134,9 +150,9 @@ void uwsgi_proxy(int proxyfd) { int next_node = -1; - uwsgi_log( "spawned uWSGI proxy (pid: %d)\n", getpid()); - +#ifdef UWSGI_DEBUG uwsgi_log( "allocating space for %d concurrent proxy connections\n", max_connections); +#endif // allocate memory for connections upcs = malloc(sizeof(struct uwsgi_proxy_connection) * max_connections); @@ -146,7 +162,11 @@ void uwsgi_proxy(int proxyfd) { } memset(upcs, 0, sizeof(struct uwsgi_proxy_connection) * max_connections); - efd = async_queue_init(proxyfd); + if (uproxy.add_me) { + uwsgi_cluster_simple_add_node(uwsgi.sockets[0].name, 1, CLUSTER_NODE_STATIC); + } + + efd = async_queue_init(uproxy.fd); if (efd < 0) { exit(1); } @@ -182,11 +202,11 @@ void uwsgi_proxy(int proxyfd) { for (i = 0; i < nevents; i++) { - if ( (int)eevents[i].ASYNC_FD == proxyfd) { + if ( (int)eevents[i].ASYNC_FD == uproxy.fd) { if (eevents[i].ASYNC_IS_IN) { // new connection, accept it - ev.ASYNC_FD = accept(proxyfd, (struct sockaddr *) &upc_addr, &upc_len); + ev.ASYNC_FD = accept(uproxy.fd, (struct sockaddr *) &upc_addr, &upc_len); if ( (int) ev.ASYNC_FD < 0) { uwsgi_error("accept()"); continue; @@ -404,6 +424,67 @@ void uwsgi_proxy(int proxyfd) { } } -#else -#warning "*** PROXY support is disabled ***" -#endif +int proxy_init() { + int i; + char *tcp_port; + + if (!uproxy.workers) uproxy.workers = 1 ; + + if (uproxy.socket_name) { + + tcp_port = strchr(uproxy.socket_name, ':'); + + if (tcp_port == NULL) { + uproxy.fd = bind_to_unix(uproxy.socket_name, UWSGI_LISTEN_QUEUE, uwsgi.chmod_socket, uwsgi.abstract_socket); + } + else { + uproxy.fd = bind_to_tcp(uproxy.socket_name, UWSGI_LISTEN_QUEUE, tcp_port); + tcp_port[0] = ':'; + } + + if (uproxy.fd < 0) { + uwsgi_log( "unable to create the proxy server socket.\n"); + exit(1); + } + + for(i=0;i= 0 && !strcmp(optarg, "@self")) { + uproxy.add_me = 1; + } + else { + uwsgi_cluster_simple_add_node(optarg, 1, CLUSTER_NODE_STATIC); + } + return 1; + case LONG_ARGS_PROXY: + uproxy.socket_name = optarg; + return 1; + case LONG_ARGS_PROXY_WORKERS: + uproxy.workers = atoi(optarg); + return 1; + } + + return 0; +} + + +struct uwsgi_plugin proxy_plugin = { + + .options = proxy_options, + .manage_opt = proxy_opt, + .init = proxy_init, +}; + diff --git a/plugins/proxy/uwsgiplugin.py b/plugins/proxy/uwsgiplugin.py new file mode 100644 index 00000000..619755ab --- /dev/null +++ b/plugins/proxy/uwsgiplugin.py @@ -0,0 +1,7 @@ + +NAME='proxy' +CFLAGS = [] +LDFLAGS = [] +LIBS = [] + +GCC_LIST = ['proxy'] diff --git a/uwsgi.c b/uwsgi.c index 3f8ef52b..8a9eac17 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -38,6 +38,7 @@ UWSGI_DECLARE_EMBEDDED_PLUGINS static struct option long_base_options[] = { {"socket", required_argument, 0, 's'}, {"processes", required_argument, 0, 'p'}, + {"workers", required_argument, 0, 'p'}, {"harakiri", required_argument, 0, 't'}, #ifdef UWSGI_XML {"xmlconfig", required_argument, 0, 'x'}, @@ -109,11 +110,6 @@ static struct option long_base_options[] = { {"check-interval", required_argument, 0, LONG_ARGS_CHECK_INTERVAL}, {"binary-path", required_argument, 0, LONG_ARGS_BINARY_PATH}, -#ifdef UWSGI_PROXY - {"proxy", required_argument, 0, LONG_ARGS_PROXY}, - {"proxy-node", required_argument, 0, LONG_ARGS_PROXY_NODE}, - {"proxy-max-connections", required_argument, 0, LONG_ARGS_PROXY_MAX_CONNECTIONS}, -#endif #ifdef UWSGI_ASYNC {"async", required_argument, 0, LONG_ARGS_ASYNC}, #endif @@ -144,6 +140,10 @@ static struct option long_base_options[] = { {"http-only", no_argument, &uwsgi.http_only, 1}, {"http-var", required_argument, 0, LONG_ARGS_HTTP_VAR}, {"http-modifier1", required_argument, 0, LONG_ARGS_HTTP_MODIFIER1}, +#endif +#ifdef UWSGI_ERLANG + {"erlang", required_argument, 0, LONG_ARGS_ERLANG}, + {"erlang-cookie", required_argument, 0, LONG_ARGS_ERLANG_COOKIE}, #endif {"check-static", required_argument, 0, LONG_ARGS_CHECK_STATIC}, {"close-on-exec", no_argument, &uwsgi.close_on_exec, 1}, @@ -611,13 +611,6 @@ options_parsed: } #endif -#ifdef UWSGI_PROXY - if (uwsgi.proxy_add_me) { - uwsgi_cluster_simple_add_node(uwsgi.sockets[0].name, 1, CLUSTER_NODE_STATIC); - } -#endif - - //call after_opt hooks if (uwsgi.binary_path == argv[0]) { @@ -719,8 +712,6 @@ int uwsgi_start(void *v_argv) { FILE *pidfile; - int uwsgi_will_starts = 0; - uwsgi_log("my PID is %d\n", (int) getpid()); #ifdef __linux__ @@ -966,17 +957,6 @@ int uwsgi_start(void *v_argv) { uwsgi.apps_cnt = 0; } - /* plugin initialization */ - for(i =0; i < uwsgi.gp_cnt; i++) { - if (uwsgi.gp[i]->init) { - uwsgi.gp[i]->init(); - } - } - for (i = 0; i < 0xFF; i++) { - if (uwsgi.p[i]->init) { - uwsgi.p[i]->init(); - } - } // application generic lock uwsgi.user_lock = uwsgi_mmap_shared_lock(); @@ -1039,12 +1019,26 @@ int uwsgi_start(void *v_argv) { uwsgi.p[111] = &uwsgi_cache_plugin; } + /* plugin initialization */ + for(i =0; i < uwsgi.gp_cnt; i++) { + if (uwsgi.gp[i]->init) { + uwsgi.gp[i]->init(); + } + } + + // initialize request plugin only if workers are available + if (uwsgi.sockets_cnt) { + for (i = 0; i < 0xFF; i++) { + if (uwsgi.p[i]->init) { + uwsgi.p[i]->init(); + } + } + } + uwsgi.current_wsgi_req = simple_current_wsgi_req; - // call nagios here - #ifdef UWSGI_THREADING if (uwsgi.has_threads) { uwsgi.current_wsgi_req = threaded_current_wsgi_req; @@ -1074,7 +1068,6 @@ int uwsgi_start(void *v_argv) { uwsgi.sockets[i].bound = 1; uwsgi.sockets_poll[i].fd = uwsgi.sockets[i].fd; uwsgi.sockets_poll[i].events = POLLIN; - uwsgi_will_starts = 1; uwsgi_log("uwsgi socket %d inherited UNIX address %s fd %d\n", i, uwsgi.sockets[i].name, uwsgi.sockets[i].fd); } } else if (gsa->sa_family == AF_INET) { @@ -1110,7 +1103,6 @@ int uwsgi_start(void *v_argv) { uwsgi.sockets[i].bound = 1; uwsgi.sockets_poll[i].fd = uwsgi.sockets[i].fd; uwsgi.sockets_poll[i].events = POLLIN; - uwsgi_will_starts = 1; uwsgi_log("uwsgi socket %d inherited INET address %s fd %d\n", i, uwsgi.sockets[i].name, uwsgi.sockets[i].fd); } free(computed_addr); @@ -1164,7 +1156,6 @@ int uwsgi_start(void *v_argv) { uwsgi.sockets[i].bound = 1; uwsgi.sockets_poll[i].fd = uwsgi.sockets[i].fd; uwsgi.sockets_poll[i].events = POLLIN; - uwsgi_will_starts = 1; } int zero_used = 0; @@ -1187,7 +1178,6 @@ int uwsgi_start(void *v_argv) { //uwsgi.sockets[uwsgi.sockets_cnt - 1].name = uwsgi_get_socket_name(gsa->sa_family, gsa); uwsgi.sockets_poll[uwsgi.sockets_cnt - 1].fd = 0; uwsgi.sockets_poll[uwsgi.sockets_cnt - 1].events = POLLIN; - uwsgi_will_starts = 1; uwsgi_log("uwsgi socket %d inherited INET address %s fd %d\n", i, uwsgi.sockets[i].name, uwsgi.sockets[i].fd); } else { uwsgi_log("too many socket defined, i cannot map fd 0\n"); @@ -1223,25 +1213,18 @@ int uwsgi_start(void *v_argv) { } } -#ifdef UWSGI_PROXY - if (uwsgi.proxy_socket_name) { - uwsgi.shared->proxy_pid = proxy_start(uwsgi.master_process); - uwsgi_will_starts = 1; - } -#endif - -#ifdef UWSGI_UDP - if (uwsgi.udp_socket) { - uwsgi_will_starts = 1; - } -#endif - - } - if (!uwsgi_will_starts && !uwsgi.no_server) { + + if (!uwsgi.sockets_cnt && !uwsgi.gateways_cnt && !uwsgi.no_server) { uwsgi_log("The -s/--socket option is missing and stdin is not a socket.\n"); exit(1); } + else if (!uwsgi.sockets_cnt && uwsgi.gateways_cnt && !uwsgi.no_server && !uwsgi.master_process) { + exit(0); + } + + if (!uwsgi.sockets_cnt) uwsgi.numproc = 0; + #ifdef UWSGI_DEBUG for (i = 0; i < uwsgi.sockets_cnt; i++) { so_bufsize_len = sizeof(int); @@ -1333,7 +1316,10 @@ uwsgi.shared->hooks[UWSGI_MODIFIER_PING] = uwsgi_request_ping; //100 */ uwsgi_log("*** Operational MODE: "); - if (uwsgi.threads > 1) { + if (!uwsgi.numproc) { + uwsgi_rawlog("no-workers"); + } + else if (uwsgi.threads > 1) { if (uwsgi.numproc > 1) { uwsgi_rawlog("preforking+threaded"); } else { @@ -1632,46 +1618,6 @@ end: return 0; } -#ifdef UWSGI_PROXY - pid_t proxy_start(int has_master) { - - pid_t pid; - - char *tcp_port = strchr(uwsgi.proxy_socket_name, ':'); - - if (tcp_port == NULL) { - uwsgi.proxyfd = bind_to_unix(uwsgi.proxy_socket_name, UWSGI_LISTEN_QUEUE, uwsgi.chmod_socket, uwsgi.abstract_socket); - } else { - uwsgi.proxyfd = bind_to_tcp(uwsgi.proxy_socket_name, UWSGI_LISTEN_QUEUE, tcp_port); - tcp_port[0] = ':'; - } - - if (uwsgi.proxyfd < 0) { - uwsgi_log("unable to create the server socket.\n"); - exit(1); - } - if (!has_master && uwsgi.numproc == 0) { - uwsgi_proxy(uwsgi.proxyfd); - //never here - exit(1); - } else { - pid = fork(); - if (pid < 0) { - uwsgi_error("fork()"); - exit(1); - } else if (pid > 0) { - close(uwsgi.proxyfd); - return pid; - //continue with uWSGI spawn... - } else { - uwsgi_proxy(uwsgi.proxyfd); - //never here - exit(1); - } - } - } -#endif - static int manage_base_opt(int i, char *optarg) { char *p; @@ -1808,19 +1754,6 @@ end: case LONG_ARGS_BINARY_PATH: uwsgi.binary_path = optarg; return 1; -#ifdef UWSGI_PROXY - case LONG_ARGS_PROXY_NODE: - if (uwsgi.cluster_fd >= 0 && !strcmp(optarg, "@self")) { - uwsgi.proxy_add_me = 1; - } - else { - uwsgi_cluster_simple_add_node(optarg, 1, CLUSTER_NODE_STATIC); - } - return 1; - case LONG_ARGS_PROXY: - uwsgi.proxy_socket_name = optarg; - return 1; -#endif #ifdef UWSGI_ERLANG case LONG_ARGS_ERLANG: uwsgi.erlang_node = optarg; diff --git a/uwsgi.h b/uwsgi.h index 4946b5a5..476a70c6 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -15,6 +15,7 @@ #define MAX_APPS 64 #define MAX_GENERIC_PLUGINS 64 #define MAX_RPC 64 +#define MAX_GATEWAYS 64 #ifndef UWSGI_LOAD_EMBEDDED_PLUGINS #define UWSGI_LOAD_EMBEDDED_PLUGINS @@ -182,6 +183,18 @@ extern int pivot_root(const char * new_root, const char * put_old); #define UWSGI_CACHE_MAX_KEY_SIZE 4071 +// Gateways are processes (managed by the master) that extends the +// server core features +// -- Gateways can prefork -- + +struct uwsgi_gateway { + + char *name; + void (*loop)(void); + pid_t pid; + int num; +}; + // maintain alignment here !!! struct uwsgi_cache_item { @@ -636,6 +649,9 @@ struct uwsgi_server { char *mode; + struct uwsgi_gateway gateways[MAX_GATEWAYS]; + int gateways_cnt; + #ifdef UWSGI_HTTP char *http; char *http_server_name; @@ -654,12 +670,6 @@ struct uwsgi_server { int log_micros; char *log_strftime; -#ifdef UWSGI_PROXY - int proxyfd; - char *proxy_socket_name; - int proxy_add_me; -#endif - int log_master; int log_syslog; char *check_static; @@ -977,10 +987,6 @@ struct uwsgi_shared { int spooler_frequency; #endif -#ifdef UWSGI_PROXY - pid_t proxy_pid; -#endif - #ifdef UWSGI_SNMP char snmp_community[72 + 1]; struct uwsgi_snmp_server_value snmp_gvalue[100]; @@ -1130,11 +1136,6 @@ void erlang_loop(struct wsgi_request *); void manage_opt(int, char *); -#ifdef UWSGI_PROXY -void uwsgi_proxy(int); -pid_t proxy_start(int); -#endif - void uwsgi_cluster_add_node(struct uwsgi_cluster_node *, int); void uwsgi_cluster_simple_add_node(char *, int, int); int uwsgi_ping_node(int, struct wsgi_request *); @@ -1370,3 +1371,6 @@ char *uwsgi_cheap_string(char *, int); int uwsgi_parse_array(char *, uint16_t, char **, uint8_t *); void log_syslog(char *); + +struct uwsgi_gateway *register_gateway(char *, void (*)(void)); +void gateway_respawn(int); diff --git a/uwsgiconfig.py b/uwsgiconfig.py index 5b1c687f..a0f0c6be 100644 --- a/uwsgiconfig.py +++ b/uwsgiconfig.py @@ -139,7 +139,7 @@ class uConf(object): self.config = ConfigParser.ConfigParser() print("using profile: %s" % filename) self.config.read(filename) - self.gcc_list = ['utils', 'protocol', 'socket', 'logging', 'master', 'plugins', 'lock', 'cache', 'event', 'signal', 'rpc', 'loop', 'uwsgi'] + self.gcc_list = ['utils', 'protocol', 'socket', 'logging', 'master', 'plugins', 'lock', 'cache', 'event', 'signal', 'rpc', 'gateway', 'loop', 'uwsgi'] self.cflags = ['-O2', '-Wall', '-Werror', '-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64'] + os.environ.get("CFLAGS", "").split() try: gcc_version = str(spcall2("%s -v" % GCC)).split('\n')[-1].split()[2] @@ -206,7 +206,6 @@ class uConf(object): if uwsgi_os == 'Haiku': self.set('async', 'false') - self.set('proxy', 'false') self.libs.remove('-rdynamic') self.libs.remove('-lpthread') self.libs.append('-lroot') @@ -338,11 +337,6 @@ class uConf(object): self.cflags.append("-DUWSGI_YAML") self.gcc_list.append('yaml') - if self.get('proxy'): - self.depends_on('proxy', ['async']) - self.cflags.append("-DUWSGI_PROXY") - self.gcc_list.append('proxy') - if self.get('ldap'): self.cflags.append("-DUWSGI_LDAP") self.gcc_list.append('ldap') @@ -411,11 +405,9 @@ class uConf(object): if self.get('erlang'): - self.depends_on("ERLANG", ['EMBEDDED']) + self.depends_on("erlang", ['embedded']) self.cflags.append("-DUWSGI_ERLANG") - self.libs.append(ERLANG_LDFLAGS) - if str(ERLANG_CFLAGS) != '': - self.cflags.append(ERLANG_CFLAGS) + self.libs.append(os.environ['ERLANG_LDFLAGS']) self.gcc_list.append('erlang') if self.get('plugin_dir'):