From c72889c10fb0371cc3543f4b716a8bcccf7bcdac Mon Sep 17 00:00:00 2001 From: "roberto@precise64" Date: Fri, 2 Mar 2012 07:31:20 +0100 Subject: [PATCH] added --daemonize2 --- event.c | 1 + utils.c | 1 - uwsgi.c | 20 ++++++++++++++++++++ uwsgi.h | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/event.c b/event.c index 5d3a5512..4a6d3c09 100644 --- a/event.c +++ b/event.c @@ -172,6 +172,7 @@ int event_queue_init() { int epfd; + epfd = epoll_create(256); if (epfd < 0) { diff --git a/utils.c b/utils.c index e6b4d044..015094c3 100644 --- a/utils.c +++ b/utils.c @@ -180,7 +180,6 @@ void daemonize(char *logfile) { exit(1); } */ - fdin = open("/dev/null", O_RDWR); if (fdin < 0) { uwsgi_error_open("/dev/null"); diff --git a/uwsgi.c b/uwsgi.c index 19f72d72..464426b4 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -81,6 +81,7 @@ static struct uwsgi_option uwsgi_base_options[] = { {"inherit", required_argument, 0, "use the specified file as config template", uwsgi_opt_load, NULL,0}, {"daemonize", required_argument, 'd', "daemonize uWSGI", uwsgi_opt_set_str, &uwsgi.daemonize, 0}, + {"daemonize2", required_argument, 0, "daemonize uWSGI after app loading", uwsgi_opt_set_str, &uwsgi.daemonize2, 0}, {"stop", required_argument, 0, "stop an instance", uwsgi_opt_pidfile_signal, (void *) SIGINT, UWSGI_OPT_IMMEDIATE}, {"reload", required_argument, 0, "reload an instance", uwsgi_opt_pidfile_signal, (void *) SIGHUP, UWSGI_OPT_IMMEDIATE}, {"pause", required_argument, 0, "pause an instance", uwsgi_opt_pidfile_signal, (void *) SIGTSTP, UWSGI_OPT_IMMEDIATE}, @@ -2579,6 +2580,25 @@ skipzero: uwsgi_init_all_apps(); } + if (uwsgi.daemonize2) { + if (uwsgi.has_emperor) { + logto(uwsgi.daemonize2); + } + else { + if (!uwsgi.is_a_reload) { + uwsgi_log("*** daemonizing uWSGI ***\n"); + daemonize(uwsgi.daemonize2); + } + else if (uwsgi.log_reopen) { + logto(uwsgi.daemonize2); + } + } + uwsgi.mypid = getpid(); + masterpid = uwsgi.mypid; + + uwsgi.workers[0].pid = masterpid; + } + if (uwsgi.no_server) { uwsgi_log("no-server mode requested. Goodbye.\n"); exit(0); diff --git a/uwsgi.h b/uwsgi.h index be23b4f8..e7af9650 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1240,6 +1240,7 @@ struct uwsgi_server { int check_static_docroot; char *daemonize; + char *daemonize2; int do_not_change_umask; char *logfile; int logfile_chown;