added --ping and --ping-timeout

This commit is contained in:
roberto@sirius
2010-08-25 19:21:31 +02:00
parent 14bf840eef
commit f0d96b03fa
2 changed files with 54 additions and 0 deletions
+49
View File
@@ -161,10 +161,48 @@ static struct option long_options[] = {
{"mode", required_argument, 0, LONG_ARGS_MODE},
{"env", required_argument, 0, LONG_ARGS_ENV},
{"vacuum", no_argument, &uwsgi.vacuum, 1},
{"ping", required_argument, 0, LONG_ARGS_PING},
{"ping-timeout", required_argument, 0, LONG_ARGS_PING_TIMEOUT},
{"version", no_argument, 0, LONG_ARGS_VERSION},
{0, 0, 0, 0}
};
void ping(struct uwsgi_server *uwsgi) {
struct uwsgi_header uh;
struct pollfd uwsgi_poll;
// use a 3 secs timeout by default
if (!uwsgi->ping_timeout) uwsgi->ping_timeout = 3 ;
uwsgi_poll.fd = uwsgi_connect(uwsgi->ping, uwsgi->ping_timeout);
if (uwsgi_poll.fd < 0) {
exit(1);
}
uh.modifier1 = UWSGI_MODIFIER_PING;
uh.pktsize = 0;
uh.modifier2 = 0;
if (write(uwsgi_poll.fd, &uh, 4) != 4) {
uwsgi_error("write()");
exit(2);
}
uwsgi_poll.events = POLLIN;
if (!uwsgi_parse_response(&uwsgi_poll, uwsgi->ping_timeout, &uh, NULL)) {
exit(1);
}
else {
if (uh.pktsize > 0) {
exit(2);
}
else {
exit(0);
}
}
}
int find_worker_id(pid_t pid) {
int i;
for (i = 1; i <= uwsgi.numproc; i++) {
@@ -510,6 +548,10 @@ int main(int argc, char *argv[], char *envp[]) {
parse_sys_envs(environ, long_options);
if (uwsgi.ping) {
ping(&uwsgi);
}
if (uwsgi.binary_path == argv[0]) {
cwd = uwsgi_get_cwd();
uwsgi.binary_path = malloc(strlen(argv[0]) + 1);
@@ -2694,6 +2736,12 @@ void manage_opt(int i, char *optarg) {
case LONG_ARGS_CHDIR2:
uwsgi.chdir2 = optarg;
break;
case LONG_ARGS_PING:
uwsgi.ping = optarg;
break;
case LONG_ARGS_PING_TIMEOUT:
uwsgi.ping_timeout = atoi(optarg);
break;
#ifdef UWSGI_HTTP
case LONG_ARGS_HTTP:
uwsgi.http = optarg;
@@ -3086,3 +3134,4 @@ void uwsgi_cluster_add_node(char *nodename, int workers) {
uwsgi_log( "unable to add node %s\n", nodename);
}
+5
View File
@@ -174,6 +174,8 @@ PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);
#define LONG_ARGS_LDAP_SCHEMA 17036
#define LONG_ARGS_LDAP 17037
#define LONG_ARGS_LDAP_SCHEMA_LDIF 17038
#define LONG_ARGS_PING 17039
#define LONG_ARGS_PING_TIMEOUT 17040
@@ -670,6 +672,9 @@ struct uwsgi_server {
#ifdef UWSGI_LDAP
char *ldap;
#endif
char *ping;
int ping_timeout;
};
struct uwsgi_cluster_node {