mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-06-16 02:15:48 +00:00
--inherit and --vassals-inherit
This commit is contained in:
@@ -122,9 +122,10 @@ void emperor_add(char *name, time_t born, char *config, uint32_t config_size) {
|
||||
struct uwsgi_instance *c_ui = ui;
|
||||
struct uwsgi_instance *n_ui = NULL;
|
||||
pid_t pid;
|
||||
char *argv[4];
|
||||
char **argv;
|
||||
char *uef;
|
||||
char **uenvs;
|
||||
int counter;
|
||||
|
||||
while (c_ui->ui_next) {
|
||||
c_ui = c_ui->ui_next;
|
||||
@@ -233,7 +234,14 @@ void emperor_add(char *name, time_t born, char *config, uint32_t config_size) {
|
||||
close(n_ui->pipe_config[0]);
|
||||
}
|
||||
|
||||
counter = 4;
|
||||
struct uwsgi_config_template *uct = uwsgi.vassals_templates;
|
||||
while(uct) {
|
||||
counter+=2;
|
||||
uct = uct->next;
|
||||
}
|
||||
|
||||
argv = uwsgi_malloc(sizeof(char *) * counter);
|
||||
// set args
|
||||
argv[0] = uwsgi.binary_path;
|
||||
if (!strcmp(name + (strlen(name) - 4), ".xml"))
|
||||
@@ -247,7 +255,15 @@ void emperor_add(char *name, time_t born, char *config, uint32_t config_size) {
|
||||
if (!strcmp(name + (strlen(name) - 3), ".js"))
|
||||
argv[1] = "--json";
|
||||
argv[2] = name;
|
||||
argv[3] = NULL;
|
||||
counter = 3;
|
||||
uct = uwsgi.vassals_templates;
|
||||
while(uct) {
|
||||
argv[counter] = "--inherit";
|
||||
argv[counter+1] = uct->filename;
|
||||
counter+=2;
|
||||
uct = uct->next;
|
||||
}
|
||||
argv[counter] = NULL;
|
||||
// start !!!
|
||||
if (execvp(argv[0], argv)) {
|
||||
uwsgi_error("execvp()");
|
||||
@@ -341,6 +357,8 @@ reconnect:
|
||||
|
||||
ui = &ui_base;
|
||||
|
||||
int freq = 0 ;
|
||||
|
||||
for (;;) {
|
||||
|
||||
|
||||
@@ -351,7 +369,8 @@ reconnect:
|
||||
}
|
||||
}
|
||||
|
||||
nevents = event_queue_wait_multi(emperor_queue, 3, events, 64);
|
||||
nevents = event_queue_wait_multi(emperor_queue, freq, events, 64);
|
||||
freq = 3;
|
||||
|
||||
for (i = 0; i<nevents;i++) {
|
||||
interesting_fd = event_queue_interesting_fd(events, i);
|
||||
|
||||
@@ -47,6 +47,7 @@ static struct option long_base_options[] = {
|
||||
{"xmlconfig", required_argument, 0, 'x'},
|
||||
{"xml", required_argument, 0, 'x'},
|
||||
#endif
|
||||
{"inherit", required_argument, 0, LONG_ARGS_INHERIT},
|
||||
{"daemonize", required_argument, 0, 'd'},
|
||||
{"listen", required_argument, 0, 'l'},
|
||||
{"max-vars", required_argument, 0, 'v'},
|
||||
@@ -66,6 +67,7 @@ static struct option long_base_options[] = {
|
||||
{"emperor-amqp-vhost", required_argument, 0, LONG_ARGS_EMPEROR_AMQP_VHOST},
|
||||
{"emperor-amqp-username", required_argument, 0, LONG_ARGS_EMPEROR_AMQP_USERNAME},
|
||||
{"emperor-amqp-password", required_argument, 0, LONG_ARGS_EMPEROR_AMQP_PASSWORD},
|
||||
{"vassals-inherit", required_argument, 0, LONG_ARGS_VASSALS_INHERIT},
|
||||
{"reload-mercy", required_argument, 0, LONG_ARGS_RELOAD_MERCY},
|
||||
{"exit-on-reload", no_argument, &uwsgi.exit_on_reload, 1},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
@@ -199,6 +201,21 @@ static struct option long_base_options[] = {
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
void config_magic_table_fill(char *filename, char **magic_table) {
|
||||
|
||||
magic_table['o'] = filename;
|
||||
if (filename[0] == '/') {
|
||||
magic_table['p'] = filename;
|
||||
}
|
||||
else {
|
||||
magic_table['p'] = uwsgi_concat3(uwsgi.cwd,"/",filename);
|
||||
}
|
||||
magic_table['s'] = uwsgi_get_last_char(magic_table['p'], '/')+1;
|
||||
magic_table['d'] = uwsgi_concat2n(magic_table['p'], magic_table['s']-magic_table['p'], "", 0);
|
||||
if (uwsgi_get_last_char(filename, '.')) magic_table['e'] = uwsgi_get_last_char(filename, '.')+1;
|
||||
if (uwsgi_get_last_char(magic_table['s'], '.')) magic_table['n'] = uwsgi_concat2n(magic_table['s'], uwsgi_get_last_char(magic_table['s'], '.')-magic_table['s'], "", 0) ;
|
||||
}
|
||||
|
||||
int find_worker_id(pid_t pid)
|
||||
{
|
||||
int i;
|
||||
@@ -714,67 +731,26 @@ int main(int argc, char *argv[], char *envp[])
|
||||
|
||||
#ifdef UWSGI_XML
|
||||
if (uwsgi.xml_config != NULL) {
|
||||
magic_table['o'] = uwsgi.xml_config;
|
||||
if (uwsgi.xml_config[0] == '/') {
|
||||
magic_table['p'] = uwsgi.xml_config;
|
||||
}
|
||||
else {
|
||||
magic_table['p'] = uwsgi_concat3(uwsgi.cwd,"/",uwsgi.xml_config);
|
||||
}
|
||||
magic_table['s'] = uwsgi_get_last_char(magic_table['p'], '/')+1;
|
||||
magic_table['d'] = uwsgi_concat2n(magic_table['p'], magic_table['s']-magic_table['p'], "", 0);
|
||||
if (uwsgi_get_last_char(uwsgi.xml_config, '.')) magic_table['e'] = uwsgi_get_last_char(uwsgi.xml_config, '.')+1;
|
||||
if (uwsgi_get_last_char(magic_table['s'], '.')) magic_table['n'] = uwsgi_concat2n(magic_table['s'], uwsgi_get_last_char(magic_table['s'], '.')-magic_table['s'], "", 0) ;
|
||||
uwsgi_xml_config(uwsgi.wsgi_req, 0, magic_table);
|
||||
config_magic_table_fill(uwsgi.xml_config, magic_table);
|
||||
uwsgi_xml_config(uwsgi.xml_config, uwsgi.wsgi_req, 0, magic_table);
|
||||
uwsgi.xml_config = magic_table['p'];
|
||||
}
|
||||
#endif
|
||||
#ifdef UWSGI_INI
|
||||
if (uwsgi.ini != NULL) {
|
||||
magic_table['o'] = uwsgi.ini;
|
||||
if (uwsgi.ini[0] == '/') {
|
||||
magic_table['p'] = uwsgi.ini;
|
||||
}
|
||||
else {
|
||||
magic_table['p'] = uwsgi_concat3(uwsgi.cwd,"/",uwsgi.ini);
|
||||
}
|
||||
|
||||
magic_table['s'] = uwsgi_get_last_char(magic_table['p'], '/')+1;
|
||||
magic_table['d'] = uwsgi_concat2n(magic_table['p'], magic_table['s']-magic_table['p'], "", 0);
|
||||
if (uwsgi_get_last_char(uwsgi.ini, '.')) magic_table['e'] = uwsgi_get_last_char(uwsgi.ini, '.')+1;
|
||||
if (uwsgi_get_last_char(magic_table['s'], '.')) magic_table['n'] = uwsgi_concat2n(magic_table['s'], uwsgi_get_last_char(magic_table['s'], '.')-magic_table['s'], "", 0) ;
|
||||
config_magic_table_fill(uwsgi.ini, magic_table);
|
||||
uwsgi_ini_config(uwsgi.ini, magic_table);
|
||||
}
|
||||
#endif
|
||||
#ifdef UWSGI_YAML
|
||||
if (uwsgi.yaml != NULL) {
|
||||
magic_table['o'] = uwsgi.yaml;
|
||||
if (uwsgi.yaml[0] == '/') {
|
||||
magic_table['p'] = uwsgi.yaml;
|
||||
}
|
||||
else {
|
||||
magic_table['p'] = uwsgi_concat3(uwsgi.cwd,"/",uwsgi.yaml);
|
||||
}
|
||||
magic_table['s'] = uwsgi_get_last_char(magic_table['p'], '/')+1;
|
||||
magic_table['d'] = uwsgi_concat2n(magic_table['p'], magic_table['s']-magic_table['p'], "", 0);
|
||||
if (uwsgi_get_last_char(uwsgi.yaml, '.')) magic_table['e'] = uwsgi_get_last_char(uwsgi.yaml, '.')+1;
|
||||
if (uwsgi_get_last_char(magic_table['s'], '.')) magic_table['n'] = uwsgi_concat2n(magic_table['s'], uwsgi_get_last_char(magic_table['s'], '.')-magic_table['s'], "", 0) ;
|
||||
config_magic_table_fill(uwsgi.yaml, magic_table);
|
||||
uwsgi_yaml_config(uwsgi.yaml, magic_table);
|
||||
}
|
||||
#endif
|
||||
#ifdef UWSGI_JSON
|
||||
if (uwsgi.json != NULL) {
|
||||
magic_table['o'] = uwsgi.json;
|
||||
if (uwsgi.json[0] == '/') {
|
||||
magic_table['p'] = uwsgi.json;
|
||||
}
|
||||
else {
|
||||
magic_table['p'] = uwsgi_concat3(uwsgi.cwd,"/",uwsgi.json);
|
||||
}
|
||||
magic_table['s'] = uwsgi_get_last_char(magic_table['p'], '/')+1;
|
||||
magic_table['d'] = uwsgi_concat2n(magic_table['p'], magic_table['s']-magic_table['p'], "", 0);
|
||||
if (uwsgi_get_last_char(uwsgi.json, '.')) magic_table['e'] = uwsgi_get_last_char(uwsgi.json, '.')+1;
|
||||
if (uwsgi_get_last_char(magic_table['s'], '.')) magic_table['n'] = uwsgi_concat2n(magic_table['s'], uwsgi_get_last_char(magic_table['s'], '.')-magic_table['s'], "", 0) ;
|
||||
config_magic_table_fill(uwsgi.json, magic_table);
|
||||
uwsgi_json_config(uwsgi.json, magic_table);
|
||||
}
|
||||
#endif
|
||||
@@ -787,6 +763,34 @@ int main(int argc, char *argv[], char *envp[])
|
||||
//parse environ
|
||||
parse_sys_envs(environ);
|
||||
|
||||
struct uwsgi_config_template *uct = uwsgi.config_templates;
|
||||
while(uct) {
|
||||
uwsgi_log("using %s as config template\n", uct->filename);
|
||||
#ifdef UWSGI_XML
|
||||
if (!strcmp(uct->filename+strlen(uct->filename)-4, ".xml")) {
|
||||
uwsgi_xml_config(uct->filename, uwsgi.wsgi_req, 0, magic_table);
|
||||
}
|
||||
#endif
|
||||
#ifdef UWSGI_INI
|
||||
if (!strcmp(uct->filename+strlen(uct->filename)-4, ".ini")) {
|
||||
uwsgi_ini_config(uct->filename, magic_table);
|
||||
}
|
||||
#endif
|
||||
#ifdef UWSGI_YAML
|
||||
if (!strcmp(uct->filename+strlen(uct->filename)-4, ".yml")) {
|
||||
uwsgi_yaml_config(uct->filename, magic_table);
|
||||
}
|
||||
if (!strcmp(uct->filename+strlen(uct->filename)-5, ".yaml")) {
|
||||
uwsgi_yaml_config(uct->filename, magic_table);
|
||||
}
|
||||
#endif
|
||||
#ifdef UWSGI_JSON
|
||||
if (!strcmp(uct->filename+strlen(uct->filename)-3, ".js")) {
|
||||
uwsgi_json_config(uct->filename, magic_table);
|
||||
}
|
||||
#endif
|
||||
uct = uct->next;
|
||||
}
|
||||
|
||||
// second pass
|
||||
for (i = 0; i < uwsgi.exported_opts_cnt; i++) {
|
||||
@@ -2010,7 +2014,7 @@ uwsgi.shared->hooks[UWSGI_MODIFIER_PING] = uwsgi_request_ping; //100
|
||||
/*parse xml for <app> tags */
|
||||
#ifdef UWSGI_XML
|
||||
if (uwsgi.xml_round2 && uwsgi.xml_config != NULL) {
|
||||
uwsgi_xml_config(uwsgi.wsgi_req, 1, NULL);
|
||||
uwsgi_xml_config(uwsgi.xml_config, uwsgi.wsgi_req, 1, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -2443,6 +2447,7 @@ end:
|
||||
|
||||
char *p;
|
||||
struct uwsgi_static_map *usm, *old_usm;
|
||||
struct uwsgi_config_template *uct, *old_uct;
|
||||
|
||||
switch (i) {
|
||||
|
||||
@@ -2646,6 +2651,48 @@ end:
|
||||
uwsgi.file_serve_mode = 1;
|
||||
}
|
||||
return 1;
|
||||
case LONG_ARGS_INHERIT:
|
||||
uct = uwsgi.config_templates;
|
||||
if (!uct) {
|
||||
uct = uwsgi_malloc(sizeof(struct uwsgi_config_template));
|
||||
uwsgi.config_templates = uct;
|
||||
}
|
||||
else {
|
||||
old_uct = uct;
|
||||
while(uct->next) {
|
||||
uct = uct->next;
|
||||
old_uct = uct;
|
||||
}
|
||||
|
||||
old_uct->next = uwsgi_malloc(sizeof(struct uwsgi_config_template));
|
||||
uct = old_uct->next;
|
||||
}
|
||||
|
||||
uct->filename = optarg;
|
||||
uct->next = NULL;
|
||||
|
||||
return 1;
|
||||
case LONG_ARGS_VASSALS_INHERIT:
|
||||
uct = uwsgi.vassals_templates;
|
||||
if (!uct) {
|
||||
uct = uwsgi_malloc(sizeof(struct uwsgi_config_template));
|
||||
uwsgi.vassals_templates = uct;
|
||||
}
|
||||
else {
|
||||
old_uct = uct;
|
||||
while(uct->next) {
|
||||
uct = uct->next;
|
||||
old_uct = uct;
|
||||
}
|
||||
|
||||
old_uct->next = uwsgi_malloc(sizeof(struct uwsgi_config_template));
|
||||
uct = old_uct->next;
|
||||
}
|
||||
|
||||
uct->filename = optarg;
|
||||
uct->next = NULL;
|
||||
|
||||
return 1;
|
||||
case LONG_ARGS_STATIC_MAP:
|
||||
usm = uwsgi.static_maps;
|
||||
if (!usm) {
|
||||
|
||||
@@ -226,6 +226,11 @@ struct uwsgi_help_item {
|
||||
char *value;
|
||||
};
|
||||
|
||||
struct uwsgi_config_template {
|
||||
char *filename;
|
||||
struct uwsgi_config_template *next;
|
||||
};
|
||||
|
||||
struct uwsgi_static_map {
|
||||
|
||||
char *mountpoint;
|
||||
@@ -414,6 +419,8 @@ struct uwsgi_opt {
|
||||
#define LONG_ARGS_EMPEROR_AMQP_PASSWORD 17098
|
||||
#define LONG_ARGS_PROTOCOL 17099
|
||||
#define LONG_ARGS_ZEROMQ 17100
|
||||
#define LONG_ARGS_INHERIT 17101
|
||||
#define LONG_ARGS_VASSALS_INHERIT 17102
|
||||
|
||||
|
||||
#define UWSGI_OK 0
|
||||
@@ -827,6 +834,7 @@ struct uwsgi_server {
|
||||
int emperor_fd_config;
|
||||
char *emperor_dir;
|
||||
pid_t emperor_pid;
|
||||
struct uwsgi_config_template *vassals_templates;
|
||||
int loyal;
|
||||
|
||||
char *emperor_amqp_vhost;
|
||||
@@ -1019,6 +1027,8 @@ struct uwsgi_server {
|
||||
char *ini;
|
||||
#endif
|
||||
|
||||
struct uwsgi_config_template *config_templates;
|
||||
|
||||
int single_interpreter;
|
||||
|
||||
struct uwsgi_shared *shared;
|
||||
@@ -1379,7 +1389,7 @@ void harakiri(void);
|
||||
void stats(int);
|
||||
|
||||
#ifdef UWSGI_XML
|
||||
void uwsgi_xml_config(struct wsgi_request *, int, char *[]);
|
||||
void uwsgi_xml_config(char *, struct wsgi_request *, int, char *[]);
|
||||
#endif
|
||||
|
||||
void internal_server_error(int, char *);
|
||||
|
||||
+2
-2
@@ -7,8 +7,8 @@
|
||||
<chdir>%v/../</chdir>
|
||||
<localhost>127.0.0.1</localhost>
|
||||
|
||||
<socket>%(localhost):3031</socket>
|
||||
<socket>/tmp/%(id).sock</socket>
|
||||
<socket>%(localhost):3039</socket>
|
||||
<socket>/tmp/%(id).sock2</socket>
|
||||
|
||||
<cpus>4</cpus>
|
||||
<werkzeug>werkzeug.testapp:test_app</werkzeug>
|
||||
|
||||
@@ -9,7 +9,7 @@ extern struct uwsgi_server uwsgi;
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
|
||||
void uwsgi_xml_config(struct wsgi_request *wsgi_req, int app_tag, char *magic_table[]) {
|
||||
void uwsgi_xml_config(char *filename, struct wsgi_request *wsgi_req, int app_tag, char *magic_table[]) {
|
||||
xmlDoc *doc = NULL;
|
||||
xmlNode *element = NULL;
|
||||
xmlNode *node = NULL;
|
||||
@@ -26,12 +26,12 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, int app_tag, char *magic_ta
|
||||
char *xml_content;
|
||||
int xml_size = 0;
|
||||
|
||||
if (!uwsgi_startswith(uwsgi.xml_config, "http://", 7)) {
|
||||
colon = uwsgi_get_last_char(uwsgi.xml_config, '/');
|
||||
if (!uwsgi_startswith(filename, "http://", 7)) {
|
||||
colon = uwsgi_get_last_char(filename, '/');
|
||||
colon = uwsgi_get_last_char(colon, ':');
|
||||
}
|
||||
else {
|
||||
colon = uwsgi_get_last_char(uwsgi.xml_config, ':');
|
||||
colon = uwsgi_get_last_char(filename, ':');
|
||||
}
|
||||
if (colon) {
|
||||
colon[0] = 0;
|
||||
@@ -43,16 +43,16 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, int app_tag, char *magic_ta
|
||||
uwsgi_log( "[uWSGI] using xml uwsgi id: %s\n", colon);
|
||||
}
|
||||
|
||||
xml_content = uwsgi_open_and_read(uwsgi.xml_config, &xml_size, 0, magic_table);
|
||||
xml_content = uwsgi_open_and_read(filename, &xml_size, 0, magic_table);
|
||||
|
||||
doc = xmlReadMemory(xml_content, xml_size, uwsgi.xml_config, NULL, 0);
|
||||
doc = xmlReadMemory(xml_content, xml_size, filename, NULL, 0);
|
||||
if (doc == NULL) {
|
||||
uwsgi_log( "[uWSGI] could not parse file %s.\n", uwsgi.xml_config);
|
||||
uwsgi_log( "[uWSGI] could not parse file %s.\n", filename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!app_tag) {
|
||||
uwsgi_log( "[uWSGI] parsing config file %s\n", uwsgi.xml_config);
|
||||
uwsgi_log( "[uWSGI] parsing config file %s\n", filename);
|
||||
}
|
||||
|
||||
element = xmlDocGetRootElement(doc);
|
||||
|
||||
Reference in New Issue
Block a user