various fixes in touch_reload

This commit is contained in:
roberto@goyle
2011-03-19 09:33:28 +01:00
parent 8b55460156
commit 4cbf6cfc33
5 changed files with 38 additions and 23 deletions
+6 -23
View File
@@ -1052,7 +1052,9 @@ void master_loop(char **argv, char **environ) {
}
uwsgi_log( "DAMN ! process %d died :( trying respawn ...\n", diedpid);
if (uwsgi.workers[uwsgi.mywid].manage_next_request) {
uwsgi_log( "DAMN ! worker %d (pid: %d) died :( trying respawn ...\n", uwsgi.mywid, (int)diedpid);
}
gettimeofday(&last_respawn, NULL);
if (last_respawn.tv_sec == uwsgi.respawn_delta) {
uwsgi_log( "worker respawning too fast !!! i have to sleep a bit...\n");
@@ -1087,28 +1089,9 @@ void master_loop(char **argv, char **environ) {
uwsgi_error("fork()");
}
else {
uwsgi_log( "Respawned uWSGI worker (new pid: %d)\n", pid);
//close(uwsgi.workers[uwsgi.mywid].pipe[1]);
//event_queue_add_fd_read(uwsgi.master_queue, uwsgi.workers[uwsgi.mywid].pipe[0]);
#ifdef UWSGI_SPOOLER
if (uwsgi.mywid <= 0 && diedpid != uwsgi.shared->spooler_pid) {
#else
if (uwsgi.mywid <= 0) {
#endif
#ifdef UWSGI_PROXY
// 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
}
#endif
}
}
}
uwsgi_log( "Respawned uWSGI worker %d (new pid: %d)\n", uwsgi.mywid, (int) pid);
}
}
}
}
+8
View File
@@ -149,6 +149,14 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre
wi->interpreter = up.main_thread;
}
if (wsgi_req->touch_reload_len) {
struct stat trst;
char *touch_reload = uwsgi_strncopy(wsgi_req->touch_reload, wsgi_req->touch_reload_len);
if (!stat(touch_reload, &trst)) {
wi->touch_reload = touch_reload;
wi->touch_reload_mtime = trst.st_mtime;
}
}
wi->callable = up.loaders[loader](arg1);
+8
View File
@@ -516,6 +516,14 @@ int uwsgi_parse_vars(struct wsgi_request *wsgi_req) {
wsgi_req->chdir = ptrbuf;
wsgi_req->chdir_len = strsize;
}
else if (!uwsgi_strncmp("UWSGI_FILE", 10, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->file = ptrbuf;
wsgi_req->file_len = strsize;
}
else if (!uwsgi_strncmp("UWSGI_TOUCH_RELOAD", 18, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->touch_reload = ptrbuf;
wsgi_req->touch_reload_len = strsize;
}
else if (!uwsgi_strncmp("UWSGI_SETENV", 12, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
char *env_value = memchr(ptrbuf, '=', strsize);
if (env_value) {
+10
View File
@@ -941,6 +941,7 @@ char *uwsgi_strncopy(char *s, int len) {
int uwsgi_get_app_id(char *script_name, int script_name_len, int modifier1) {
int i;
struct stat st;
for(i=0;i<uwsgi.apps_cnt;i++) {
//uwsgi_log("searching for %.*s in %.*s %p\n", script_name_len, script_name, uwsgi.apps[i].mountpoint_len, uwsgi.apps[i].mountpoint, uwsgi.apps[i].callable);
@@ -948,6 +949,15 @@ int uwsgi_get_app_id(char *script_name, int script_name_len, int modifier1) {
continue;
}
if (!uwsgi_strncmp(uwsgi.apps[i].mountpoint, uwsgi.apps[i].mountpoint_len, script_name, script_name_len)) {
if (uwsgi.apps[i].touch_reload) {
if (!stat(uwsgi.apps[i].touch_reload, &st)) {
if (st.st_mtime != uwsgi.apps[i].touch_reload_mtime) {
// serve the new request and reload
uwsgi.workers[uwsgi.mywid].manage_next_request = 0;
return -1;
}
}
}
if (modifier1 == -1) return i;
if (modifier1 == uwsgi.apps[i].modifier1) return i;
}
+6
View File
@@ -541,6 +541,9 @@ struct uwsgi_app {
int requests;
char *chdir;
char *touch_reload;
time_t touch_reload_mtime;
};
@@ -643,6 +646,9 @@ struct wsgi_request {
char *chdir;
uint16_t chdir_len;
char *touch_reload;
uint16_t touch_reload_len;
int fd_closed;
int sendfile_fd;