diff --git a/core/spooler.c b/core/spooler.c index e3d0cd43..f47100dc 100644 --- a/core/spooler.c +++ b/core/spooler.c @@ -15,22 +15,25 @@ static uint64_t wakeup = 0; // function to allow waking up the spooler if blocked in event_wait void spooler_wakeup() { wakeup++; } -void uwsgi_opt_add_spooler(char *opt, char *directory, void *none) { +void uwsgi_opt_add_spooler(char *opt, char *directory, void *mode) { int i; + struct uwsgi_spooler *us; if (access(directory, R_OK | W_OK | X_OK)) { - uwsgi_error("[spooler directory] access()"); - exit(1); + uwsgi_error("[spooler directory] access()"); + exit(1); } if (uwsgi.spooler_numproc > 0) { for(i=0;imode = (long) mode; } } else { - uwsgi_new_spooler(directory); + us = uwsgi_new_spooler(directory); + if (mode) us->mode = (long) mode; } } @@ -41,13 +44,13 @@ struct uwsgi_spooler *uwsgi_new_spooler(char *dir) { struct uwsgi_spooler *uspool = uwsgi.spoolers; if (!uspool) { - uwsgi.spoolers = uwsgi_malloc_shared(sizeof(struct uwsgi_spooler)); + uwsgi.spoolers = uwsgi_calloc_shared(sizeof(struct uwsgi_spooler)); uspool = uwsgi.spoolers; } else { while(uspool) { if (uspool->next == NULL) { - uspool->next = uwsgi_malloc_shared(sizeof(struct uwsgi_spooler)); + uspool->next = uwsgi_calloc_shared(sizeof(struct uwsgi_spooler)); uspool = uspool->next; break; } diff --git a/core/uwsgi.c b/core/uwsgi.c index f0c5408c..678940d0 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -50,7 +50,6 @@ static struct uwsgi_option uwsgi_base_options[] = { {"no-harakiri-arh", no_argument, 0, "do not enable harakiri during after-request-hook", uwsgi_opt_true, &uwsgi.harakiri_no_arh, 0}, {"no-harakiri-after-req-hook", no_argument, 0, "do not enable harakiri during after-request-hook", uwsgi_opt_true, &uwsgi.harakiri_no_arh, 0}, {"backtrace-depth", no_argument, 0, "set backtrace depth", uwsgi_opt_set_int, &uwsgi.backtrace_depth, 0}, - {"spooler-harakiri", required_argument, 0, "set harakiri timeout for spooler tasks", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_SPOOLER_HARAKIRI, 0}, {"mule-harakiri", required_argument, 0, "set harakiri timeout for mule tasks", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_MULE_HARAKIRI, 0}, #ifdef UWSGI_XML {"xmlconfig", required_argument, 'x', "load config from xml file", uwsgi_opt_load_xml, NULL, UWSGI_OPT_IMMEDIATE}, @@ -186,11 +185,13 @@ static struct uwsgi_option uwsgi_base_options[] = { #ifdef UWSGI_SPOOLER {"spooler", required_argument, 'Q', "run a spooler on the specified directory", uwsgi_opt_add_spooler, NULL, UWSGI_OPT_MASTER}, + {"spooler-external", required_argument, 0, "map spoolers requests to a spooler directory managed by an external instance", uwsgi_opt_add_spooler, (void *) UWSGI_SPOOLER_EXTERNAL, UWSGI_OPT_MASTER}, {"spooler-ordered", no_argument, 0, "try to order the execution of spooler tasks", uwsgi_opt_true, &uwsgi.spooler_ordered, 0}, {"spooler-chdir", required_argument, 0, "chdir() to specified directory before each spooler task", uwsgi_opt_set_str, &uwsgi.spooler_chdir, 0}, {"spooler-processes", required_argument, 0, "set the number of processes for spoolers", uwsgi_opt_set_int, &uwsgi.spooler_numproc, 0}, {"spooler-quiet", no_argument, 0, "do not be verbose with spooler tasks", uwsgi_opt_true, &uwsgi.spooler_quiet, 0}, {"spooler-max-tasks", required_argument, 0, "set the maximum number of tasks to run before recycling a spooler", uwsgi_opt_set_int, &uwsgi.spooler_max_tasks, 0}, + {"spooler-harakiri", required_argument, 0, "set harakiri timeout for spooler tasks", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_SPOOLER_HARAKIRI, 0}, #endif {"mule", optional_argument, 0, "add a mule", uwsgi_opt_add_mule, NULL, UWSGI_OPT_MASTER}, {"mules", required_argument, 0, "add the specified number of mules", uwsgi_opt_add_mules, NULL, UWSGI_OPT_MASTER}, @@ -2459,9 +2460,12 @@ int uwsgi_start(void *v_argv) { create_signal_pipe(uwsgi.shared->spooler_signal_pipe); struct uwsgi_spooler *uspool = uwsgi.spoolers; while (uspool) { - create_signal_pipe(uspool->signal_pipe); + // lock is required even in EXTERNAL mode uspool->lock = uwsgi_lock_init(uwsgi_concat2("spooler on ", uspool->dir)); + if (uspool->mode == UWSGI_SPOOLER_EXTERNAL) goto next; + create_signal_pipe(uspool->signal_pipe); uspool->pid = spooler_start(uspool); +next: uspool = uspool->next; } } diff --git a/uwsgi.h b/uwsgi.h index ac7f21a7..2ef40c79 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -553,6 +553,8 @@ struct uwsgi_opt { #define UWSGI_OPTION_SPOOLER_HARAKIRI 17 #define UWSGI_OPTION_MULE_HARAKIRI 18 +#define UWSGI_SPOOLER_EXTERNAL 1 + #define UWSGI_MODIFIER_ADMIN_REQUEST 10 #define UWSGI_MODIFIER_SPOOL_REQUEST 17 #define UWSGI_MODIFIER_EVAL 22 @@ -769,6 +771,8 @@ struct uwsgi_spooler { struct uwsgi_lock_item *lock; time_t harakiri; + int mode; + int running; int signal_pipe[2];