mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-05 13:11:33 +00:00
python and ping plugins now embedded by default
This commit is contained in:
@@ -23,10 +23,10 @@ stackless = false
|
||||
debug = false
|
||||
unbit = false
|
||||
xml_implementation = libxml2
|
||||
plugins = python
|
||||
plugins =
|
||||
bin_name = uwsgi
|
||||
plugin_dir = .
|
||||
embedded_plugins =
|
||||
embedded_plugins = python, ping
|
||||
|
||||
[python]
|
||||
paste = true
|
||||
|
||||
@@ -1,17 +1,29 @@
|
||||
#include "../../uwsgi.h"
|
||||
|
||||
{"ping", required_argument, 0, LONG_ARGS_PING},
|
||||
{"ping-timeout", required_argument, 0, LONG_ARGS_PING_TIMEOUT},
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
struct uwsgi_ping {
|
||||
char *ping;
|
||||
int ping_timeout;
|
||||
} uping;
|
||||
|
||||
void ping() {
|
||||
struct option uwsgi_ping_options[] = {
|
||||
{"ping", required_argument, 0, LONG_ARGS_PING},
|
||||
{"ping-timeout", required_argument, 0, LONG_ARGS_PING_TIMEOUT},
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
static void ping() {
|
||||
|
||||
struct uwsgi_header uh;
|
||||
struct pollfd uwsgi_poll;
|
||||
|
||||
// use a 3 secs timeout by default
|
||||
if (!uwsgi.ping_timeout) uwsgi.ping_timeout = 3 ;
|
||||
if (!uping.ping_timeout) uping.ping_timeout = 3 ;
|
||||
|
||||
uwsgi_poll.fd = uwsgi_connect(uwsgi.ping, uwsgi.ping_timeout);
|
||||
uwsgi_log("PING uwsgi host %s (timeout: %d)\n", uping.ping, uping.ping_timeout);
|
||||
|
||||
uwsgi_poll.fd = uwsgi_connect(uping.ping, uping.ping_timeout);
|
||||
if (uwsgi_poll.fd < 0) {
|
||||
exit(1);
|
||||
}
|
||||
@@ -24,7 +36,7 @@ void ping() {
|
||||
exit(2);
|
||||
}
|
||||
uwsgi_poll.events = POLLIN;
|
||||
if (!uwsgi_parse_response(&uwsgi_poll, uwsgi.ping_timeout, &uh, NULL)) {
|
||||
if (!uwsgi_parse_response(&uwsgi_poll, uping.ping_timeout, &uh, NULL)) {
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
@@ -39,6 +51,16 @@ void ping() {
|
||||
}
|
||||
|
||||
|
||||
int ping_init() {
|
||||
|
||||
if (uping.ping) {
|
||||
ping();
|
||||
//never here
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* uwsgi PING|100 */
|
||||
int uwsgi_request_ping(struct wsgi_request *wsgi_req) {
|
||||
char len;
|
||||
@@ -66,3 +88,26 @@ int uwsgi_request_ping(struct wsgi_request *wsgi_req) {
|
||||
return UWSGI_OK;
|
||||
}
|
||||
|
||||
int uwsgi_ping_manage_options(int i, char *optarg) {
|
||||
|
||||
switch(i) {
|
||||
case LONG_ARGS_PING:
|
||||
uping.ping = optarg;
|
||||
return 1;
|
||||
case LONG_ARGS_PING_TIMEOUT:
|
||||
uping.ping_timeout = atoi(optarg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct uwsgi_plugin ping_plugin = {
|
||||
|
||||
.name = "ping",
|
||||
.modifier1 = 100,
|
||||
.options = uwsgi_ping_options,
|
||||
.manage_opt = uwsgi_ping_manage_options,
|
||||
.request = uwsgi_request_ping,
|
||||
.init = ping_init,
|
||||
};
|
||||
|
||||
@@ -520,6 +520,10 @@ int uwsgi_python_manage_options(int i, char *optarg) {
|
||||
case 'w':
|
||||
up.wsgi_config = optarg;
|
||||
return 1;
|
||||
case LONG_ARGS_WSGI_FILE:
|
||||
case LONG_ARGS_FILE_CONFIG:
|
||||
up.file_config = optarg;
|
||||
return 1;
|
||||
case LONG_ARGS_PYTHONPATH:
|
||||
uwsgi_log("found PYTHONPATH\n");
|
||||
if (up.python_path_cnt < MAX_PYTHONPATH) {
|
||||
|
||||
@@ -32,6 +32,8 @@ static char *short_options = NULL;
|
||||
|
||||
static char *base_short_options = "s:p:t:x:d:l:v:b:mcaCTiMhrR:z:A:Q:L";
|
||||
|
||||
UWSGI_DECLARE_EMBEDDED_PLUGINS
|
||||
|
||||
static struct option long_base_options[] = {
|
||||
{"socket", required_argument, 0, 's'},
|
||||
{"processes", required_argument, 0, 'p'},
|
||||
@@ -452,7 +454,7 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
uwsgi.binary_path = argv[0];
|
||||
|
||||
// initialize embedded plugins
|
||||
//LEP(python)
|
||||
UWSGI_LOAD_EMBEDDED_PLUGINS
|
||||
|
||||
char *plugins_requested = getenv("UWSGI_PLUGINS");
|
||||
if (plugins_requested) {
|
||||
@@ -1550,12 +1552,6 @@ static int manage_base_opt(int i, char *optarg) {
|
||||
case LONG_ARGS_CHDIR2:
|
||||
uwsgi.chdir2 = optarg;
|
||||
return 1;
|
||||
case LONG_ARGS_PING:
|
||||
uwsgi.ping = optarg;
|
||||
return 1;
|
||||
case LONG_ARGS_PING_TIMEOUT:
|
||||
uwsgi.ping_timeout = atoi(optarg);
|
||||
return 1;
|
||||
#ifdef UWSGI_HTTP
|
||||
case LONG_ARGS_HTTP:
|
||||
uwsgi.http = optarg;
|
||||
@@ -1657,10 +1653,6 @@ static int manage_base_opt(int i, char *optarg) {
|
||||
case LONG_ARGS_BINARY_PATH:
|
||||
uwsgi.binary_path = optarg;
|
||||
return 1;
|
||||
case LONG_ARGS_WSGI_FILE:
|
||||
case LONG_ARGS_FILE_CONFIG:
|
||||
uwsgi.file_config = optarg;
|
||||
return 1;
|
||||
#ifdef UWSGI_PROXY
|
||||
case LONG_ARGS_PROXY_NODE:
|
||||
uwsgi_cluster_add_node(optarg, 1);
|
||||
|
||||
@@ -11,9 +11,22 @@
|
||||
|
||||
#define MAX_APPS 64
|
||||
|
||||
#define LEP(lepname) \
|
||||
extern struct uwsgi_plugin lepname##_plugin;\
|
||||
fill_plugin_table(lepup->modifier1, lepname);
|
||||
#define UDEP(pname) extern struct uwsgi_plugin pname##_plugin;
|
||||
|
||||
#define ULEP(pname)\
|
||||
uwsgi.shared->hook_init[pname##_plugin.modifier1] = pname##_plugin.init;\
|
||||
uwsgi.shared->hook_post_fork[pname##_plugin.modifier1] = pname##_plugin.post_fork;\
|
||||
uwsgi.shared->hook_options[pname##_plugin.modifier1] = pname##_plugin.options;\
|
||||
uwsgi.shared->hook_manage_opt[pname##_plugin.modifier1] = pname##_plugin.manage_opt;\
|
||||
uwsgi.shared->hook_short_options[pname##_plugin.modifier1] = pname##_plugin.short_options;\
|
||||
uwsgi.shared->hook_request[pname##_plugin.modifier1] = pname##_plugin.request;\
|
||||
uwsgi.shared->hook_after_request[pname##_plugin.modifier1] = pname##_plugin.after_request;\
|
||||
uwsgi.shared->hook_init_apps[pname##_plugin.modifier1] = pname##_plugin.init_apps;\
|
||||
uwsgi.shared->hook_enable_threads[pname##_plugin.modifier1] = pname##_plugin.enable_threads;\
|
||||
uwsgi.shared->hook_init_thread[pname##_plugin.modifier1] = pname##_plugin.init_thread;\
|
||||
uwsgi.shared->hook_manage_udp[pname##_plugin.modifier1] = pname##_plugin.manage_udp;\
|
||||
uwsgi.shared->hook_manage_xml[pname##_plugin.modifier1] = pname##_plugin.manage_xml;\
|
||||
|
||||
|
||||
#define fill_plugin_table(x, up)\
|
||||
uwsgi.shared->hook_init[x] = up->init;\
|
||||
@@ -702,9 +715,6 @@ struct uwsgi_server {
|
||||
char *ldap;
|
||||
#endif
|
||||
|
||||
char *ping;
|
||||
int ping_timeout;
|
||||
|
||||
int xml_round2;
|
||||
|
||||
char *cwd;
|
||||
|
||||
@@ -54,6 +54,21 @@ def build_uwsgi(uc):
|
||||
|
||||
gcc_list, cflags, ldflags, libs = uc.get_gcll()
|
||||
|
||||
if uc.get('embedded_plugins'):
|
||||
ep = uc.get('embedded_plugins').split(',')
|
||||
epc = "-DUWSGI_DECLARE_EMBEDDED_PLUGINS=\""
|
||||
eplc = "-DUWSGI_LOAD_EMBEDDED_PLUGINS=\""
|
||||
for p in ep:
|
||||
p = p.rstrip().lstrip()
|
||||
epc += "UDEP(%s);" % p
|
||||
eplc += "ULEP(%s);" % p
|
||||
epc += "\""
|
||||
eplc += "\""
|
||||
|
||||
cflags.append(epc)
|
||||
cflags.append(eplc)
|
||||
|
||||
|
||||
print("*** uWSGI compiling server core ***")
|
||||
for file in gcc_list:
|
||||
objfile = file
|
||||
@@ -67,6 +82,7 @@ def build_uwsgi(uc):
|
||||
if len(ep) > 0:
|
||||
print("*** uWSGI compiling embedded plugins ***")
|
||||
for p in ep:
|
||||
p = p.rstrip().lstrip()
|
||||
path = 'plugins/%s' % p
|
||||
path = path.rstrip('/')
|
||||
|
||||
@@ -98,6 +114,7 @@ def build_uwsgi(uc):
|
||||
print("*** uWSGI building plugins ***")
|
||||
|
||||
for p in plugins:
|
||||
p = p.rstrip().lstrip()
|
||||
print("*** building plugin: %s ***" % p)
|
||||
build_plugin("plugins/%s" % p, uc, cflags, ldflags, libs)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user