diff --git a/core/master_utils.c b/core/master_utils.c index 669f9ae7..33de0b65 100644 --- a/core/master_utils.c +++ b/core/master_utils.c @@ -677,7 +677,7 @@ void uwsgi_manage_command_cron(time_t now) { if (!uwsgi_cron_delta) { - uwsgi_error("localtime()"); + uwsgi_error("uwsgi_manage_command_cron()/localtime()"); return; } @@ -686,6 +686,16 @@ void uwsgi_manage_command_cron(time_t now) { while (current_cron) { +#ifdef UWSGI_SSL + // check for legion cron + if (current_cron->legion) { + if (!uwsgi_legion_i_am_the_lord(current_cron->legion)) { + current_cron = current_cron->next; + continue; + } + } +#endif + int run_task = uwsgi_cron_task_needs_execution(uwsgi_cron_delta, current_cron->minute, current_cron->hour, current_cron->day, current_cron->month, current_cron->week); if (run_task == 1) { @@ -695,7 +705,7 @@ void uwsgi_manage_command_cron(time_t now) { //call command if (current_cron->command) { if (uwsgi_run_command(current_cron->command, NULL, -1) >= 0) { - uwsgi_log_verbose("[uWSGI-cron] running %s\n", current_cron->command); + uwsgi_log_verbose("[uwsgi-cron] running %s\n", current_cron->command); } } current_cron->last_job = now; diff --git a/core/signal.c b/core/signal.c index ba497517..a366314f 100644 --- a/core/signal.c +++ b/core/signal.c @@ -232,6 +232,29 @@ void uwsgi_opt_add_cron(char *opt, char *value, void *foobar) { uc->command = value + i; } +#ifdef UWSGI_SSL +void uwsgi_opt_add_legion_cron(char *opt, char *value, void *foobar) { + char *space = strchr(value, ' '); + if (!space) { + uwsgi_log("invalid legion-cron syntax, must be prefixed with a legion name\n"); + exit(1); + } + char *legion = uwsgi_concat2n(value, space-value, "", 0); + uwsgi_opt_add_cron(opt, space+1, foobar); + // now get the last added uwsgi_cron structure + struct uwsgi_cron *uc = uwsgi.crons; + while(uc) { + if (!uc->next) { + uc->legion = legion; + return; + } + } + + uwsgi_log("error initializing legion-cron\n"); + exit(1); +} +#endif + int uwsgi_signal_add_cron(uint8_t sig, int minute, int hour, int day, int month, int week) { if (!uwsgi.master_process) diff --git a/core/uwsgi.c b/core/uwsgi.c index 149453cf..cfe10058 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -605,6 +605,10 @@ static struct uwsgi_option uwsgi_base_options[] = { {"zerg-server", required_argument, 0, "enable the zerg server on the specified UNIX socket", uwsgi_opt_set_str, &uwsgi.zerg_server, UWSGI_OPT_MASTER}, {"cron", required_argument, 0, "add a cron task", uwsgi_opt_add_cron, NULL, UWSGI_OPT_MASTER}, +#ifdef UWSGI_SSL + {"legion-cron", required_argument, 0, "add a cron task runnable only when the instance is a lord of the specified legion", uwsgi_opt_add_legion_cron, NULL, UWSGI_OPT_MASTER}, + {"cron_cron", required_argument, 0, "add a cron task runnable only when the instance is a lord of the specified legion", uwsgi_opt_add_legion_cron, NULL, UWSGI_OPT_MASTER}, +#endif {"loop", required_argument, 0, "select the uWSGI loop engine", uwsgi_opt_set_str, &uwsgi.loop, 0}, {"loop-list", no_argument, 0, "list enabled loop engines", uwsgi_opt_true, &uwsgi.loop_list, 0}, {"loops-list", no_argument, 0, "list enabled loop engines", uwsgi_opt_true, &uwsgi.loop_list, 0}, @@ -2415,7 +2419,14 @@ unsafe: if (uwsgi.crons) { struct uwsgi_cron *ucron = uwsgi.crons; while (ucron) { - uwsgi_log("command \"%s\" registered as uWSGI-cron task\n", ucron->command); +#ifdef UWSGI_SSL + if (ucron->legion) { + uwsgi_log("[uwsgi-cron] command \"%s\" registered as cron task for legion \"%s\"\n", ucron->command, ucron->legion); + ucron = ucron->next; + continue; + } +#endif + uwsgi_log("[uwsgi-cron] command \"%s\" registered as cron task\n", ucron->command); ucron = ucron->next; } } diff --git a/uwsgi.h b/uwsgi.h index fd3054db..2d1d006c 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -2314,6 +2314,9 @@ struct uwsgi_cron { uint8_t sig; char *command; +#ifdef UWSGI_SSL + char *legion; +#endif struct uwsgi_cron *next; }; @@ -3182,6 +3185,7 @@ void uwsgi_opt_load_plugin(char *, char *, void *); void uwsgi_opt_load_dl(char *, char *, void *); void uwsgi_opt_load(char *, char *, void *); #ifdef UWSGI_SSL +void uwsgi_opt_add_legion_cron(char *, char *, void *); void uwsgi_opt_sni(char *, char *, void *); struct uwsgi_string_list *uwsgi_ssl_add_sni_item(char *, char *, char *, char *, char *); #endif