diff --git a/core/emperor.c b/core/emperor.c index 3d040304..35c6b51c 100644 --- a/core/emperor.c +++ b/core/emperor.c @@ -135,6 +135,32 @@ int uwsgi_emperor_is_valid(char *name) { return 0; } +static char *emperor_check_on_demand_socket(char *filename) { + if (uwsgi.emperor_on_demand_extension) { + char *tmp = uwsgi_concat2(filename, uwsgi.emperor_on_demand_extension); + int fd = open(tmp, O_RDONLY); + free(tmp); + if (fd < 0) return NULL; + size_t len = 0; + char *ret = uwsgi_read_fd(fd, &len, 1); + close(fd); + // change the first non prinabel character to 0 + size_t i; + for(i=0;id_name, st.st_mtime, NULL, 0, st.st_uid, st.st_gid, NULL); + char *socket_name = emperor_check_on_demand_socket(de->d_name); + emperor_add(ues, de->d_name, st.st_mtime, NULL, 0, st.st_uid, st.st_gid, socket_name); + if (socket_name) free(socket_name); } } closedir(dir); @@ -250,7 +278,9 @@ void uwsgi_imperial_monitor_glob(struct uwsgi_emperor_scanner *ues) { } } else { - emperor_add(ues, g.gl_pathv[i], st.st_mtime, NULL, 0, st.st_uid, st.st_gid, NULL); + char *socket_name = emperor_check_on_demand_socket(g.gl_pathv[i]); + emperor_add(ues, g.gl_pathv[i], st.st_mtime, NULL, 0, st.st_uid, st.st_gid, socket_name); + if (socket_name) free(socket_name); } } @@ -609,7 +639,7 @@ void emperor_add(struct uwsgi_emperor_scanner *ues, char *name, time_t born, cha } event_queue_add_fd_read(uwsgi.emperor_queue, n_ui->on_demand_fd); - uwsgi_log("[uwsgi-emperor] %s -> \"on demand\" instance detected, waiting for connections on socket \"%s\"...\n", name, socket_name); + uwsgi_log("[uwsgi-emperor] %s -> \"on demand\" instance detected, waiting for connections on socket \"%s\" ...\n", name, socket_name); return; } diff --git a/core/uwsgi.c b/core/uwsgi.c index d5d3b297..b32e7ec8 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -176,6 +176,11 @@ static struct uwsgi_option uwsgi_base_options[] = { {"emperor-throttle", required_argument, 0, "set throttling level (in milliseconds) for bad behaving vassals (default 1000)", uwsgi_opt_set_int, &uwsgi.emperor_throttle, 0}, {"emperor-max-throttle", required_argument, 0, "set max throttling level (in milliseconds) for bad behaving vassals (default 3 minutes)", uwsgi_opt_set_int, &uwsgi.emperor_max_throttle, 0}, {"emperor-magic-exec", no_argument, 0, "prefix vassals config files with exec:// if they have the executable bit", uwsgi_opt_true, &uwsgi.emperor_magic_exec, 0}, + {"emperor-on-demand-extension", required_argument, 0, "search for text file (vassal name + extension) containing the on demand socket name", uwsgi_opt_set_str, &uwsgi.emperor_on_demand_extension, 0}, + {"emperor-on-demand-ext", required_argument, 0, "search for text file (vassal name + extension) containing the on demand socket name", uwsgi_opt_set_str, &uwsgi.emperor_on_demand_extension, 0}, + {"emperor-on-demand-directory", required_argument, 0, "enable on demand mode binding to the unix socket in the specified directory named like the vassal + .socket", uwsgi_opt_set_str, &uwsgi.emperor_on_demand_directory, 0}, + {"emperor-on-demand-dir", required_argument, 0, "enable on demand mode binding to the unix socket in the specified directory named like the vassal + .socket", uwsgi_opt_set_str, &uwsgi.emperor_on_demand_directory, 0}, + {"emperor-on-demand-exec", required_argument, 0, "use the output of the specified command as on demand socket name (the vassal name is passed as the only argument)", uwsgi_opt_set_str, &uwsgi.emperor_on_demand_exec, 0}, {"imperial-monitor-list", no_argument, 0, "list enabled imperial monitors", uwsgi_opt_true, &uwsgi.imperial_monitor_list, 0}, {"imperial-monitors-list", no_argument, 0, "list enabled imperial monitors", uwsgi_opt_true, &uwsgi.imperial_monitor_list, 0}, {"vassals-inherit", required_argument, 0, "add config templates to vassals config", uwsgi_opt_add_string_list, &uwsgi.vassals_templates, 0}, diff --git a/uwsgi.h b/uwsgi.h index f1f54ad9..9b49c4d3 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1619,6 +1619,13 @@ struct uwsgi_server { int emperor_max_throttle; int emperor_magic_exec; int emperor_heartbeat; + // search for a file with the specified extension at the same level of the vassal file + char *emperor_on_demand_extension; + // bind to a unix socket on the specified directory named directory/vassal.socket + char *emperor_on_demand_directory; + // run a shell script passing the vassal as the only argument, the stdout is used as the socket + char *emperor_on_demand_exec; + time_t next_heartbeat; int heartbeat; struct uwsgi_string_list *emperor;