diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index 273a2a92..94e635bc 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -1369,6 +1369,15 @@ void uwsgi_python_hijack(void) { #ifndef UWSGI_PYPY if (up.pyshell && uwsgi.mywid == 1) { + // re-map stdin to stdout and stderr if we are logging to a file + if (uwsgi.logfile) { + if (dup2(0, 1) < 0) { + uwsgi_error("dup2()"); + } + if (dup2(0, 2) < 0) { + uwsgi_error("dup2()"); + } + } UWSGI_GET_GIL; PyImport_ImportModule("readline"); PyRun_InteractiveLoop(stdin, "uwsgi"); diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index f25e9b3e..2152198a 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -2359,6 +2359,20 @@ PyObject *py_uwsgi_reload(PyObject * self, PyObject * args) { return Py_True; } +/* uWSGI stop */ +PyObject *py_uwsgi_stop(PyObject * self, PyObject * args) { + + if (kill(uwsgi.workers[0].pid, SIGQUIT)) { + uwsgi_error("kill()"); + Py_INCREF(Py_None); + return Py_None; + } + + Py_INCREF(Py_True); + return Py_True; +} + + /* blocking hint */ PyObject *py_uwsgi_set_blocking(PyObject * self, PyObject * args) { @@ -2696,6 +2710,7 @@ static PyMethodDef uwsgi_advanced_methods[] = { {"send_message", py_uwsgi_send_message, METH_VARARGS, ""}, {"send_multi_message", py_uwsgi_send_multi_message, METH_VARARGS, ""}, {"reload", py_uwsgi_reload, METH_VARARGS, ""}, + {"stop", py_uwsgi_stop, METH_VARARGS, ""}, {"workers", py_uwsgi_workers, METH_VARARGS, ""}, {"masterpid", py_uwsgi_masterpid, METH_VARARGS, ""}, {"total_requests", py_uwsgi_total_requests, METH_VARARGS, ""}, diff --git a/uwsgi.c b/uwsgi.c index 6a311d27..9aab2f2a 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -954,6 +954,13 @@ int main(int argc, char *argv[], char *envp[]) { } } + char *screen_env = getenv("TERM"); + if (screen_env) { + if (!strcmp(screen_env, "screen")) { + uwsgi.screen_session = getenv("STY"); + } + } + env_reloads = getenv("UWSGI_RELOADS"); if (env_reloads) { //convert env value to int @@ -1359,6 +1366,10 @@ int main(int argc, char *argv[], char *envp[]) { } + if (uwsgi.screen_session) { + uwsgi_log("*** running under screen session %s ***\n", uwsgi.screen_session); + } + if (uwsgi.pidfile && !uwsgi.is_a_reload) { uwsgi_log("writing pidfile to %s\n", uwsgi.pidfile); pidfile = fopen(uwsgi.pidfile, "w"); diff --git a/uwsgi.h b/uwsgi.h index d4d6c3e6..6c664f66 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -971,6 +971,8 @@ struct uwsgi_server { int die_on_idle; + char *screen_session; + int has_emperor; int emperor_fd; int emperor_tyrant; diff --git a/welcome.py b/welcome.py index 8c70ca60..6fa06819 100644 --- a/welcome.py +++ b/welcome.py @@ -4,6 +4,7 @@ import gc import sys gc.set_debug(gc.DEBUG_SAVEALL) +print os.environ print sys.modules print sys.argv