mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-05 13:11:33 +00:00
--stop and --reload, open by fifo and fd
This commit is contained in:
@@ -92,7 +92,7 @@ void uwsgi_ini_config(char *file, char *magic_table[]) {
|
||||
char *section_asked = "uwsgi";
|
||||
char *colon;
|
||||
|
||||
if (!uwsgi_startswith(file, "http://", 7) || !uwsgi_startswith(file, "data://", 7) || !uwsgi_startswith(file, "sym://", 6) ) {
|
||||
if (uwsgi_check_scheme(file)) {
|
||||
colon = uwsgi_get_last_char(file, '/');
|
||||
colon = uwsgi_get_last_char(colon, ':');
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ void uwsgi_json_config(char *file, char *magic_table[]) {
|
||||
char *colon;
|
||||
int i;
|
||||
|
||||
if (!uwsgi_startswith(file, "http://", 7) || !uwsgi_startswith(file, "data://", 7) || !uwsgi_startswith(file, "sym://", 6)) {
|
||||
if (uwsgi_check_scheme(file)) {
|
||||
colon = uwsgi_get_last_char(file, '/');
|
||||
colon = uwsgi_get_last_char(colon, ':');
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) {
|
||||
char *real_filename = filename;
|
||||
|
||||
|
||||
if (strncmp(filename, "http://", 7) && strncmp(filename, "sym://", 6) && strncmp(filename, "data://", 7)) {
|
||||
if (!uwsgi_check_scheme(filename)) {
|
||||
|
||||
pyfile = fopen(filename, "r");
|
||||
if (!pyfile) {
|
||||
|
||||
@@ -424,7 +424,7 @@ zipimporter_init(struct _symzipimporter *self, PyObject *args, PyObject *kwds)
|
||||
// avoid GC !!!
|
||||
name = uwsgi_concat2(name, "");
|
||||
|
||||
if (!uwsgi_startswith(name, "http://", 7) || !uwsgi_startswith(name, "data://", 7) || !uwsgi_startswith(name, "sym://", 6) ) {
|
||||
if (uwsgi_check_scheme(name)) {
|
||||
prefix = uwsgi_get_last_char(name, '/');
|
||||
prefix = uwsgi_get_last_char(prefix, ':');
|
||||
}
|
||||
|
||||
@@ -1697,6 +1697,32 @@ int uwsgi_file_exists(char *filename) {
|
||||
return !access(filename, R_OK);
|
||||
}
|
||||
|
||||
char *uwsgi_read_fd(int fd, int *size, int add_zero) {
|
||||
|
||||
char stack_buf[4096];
|
||||
ssize_t len;
|
||||
char *buffer = NULL;
|
||||
|
||||
len = 1;
|
||||
while(len > 0) {
|
||||
len = read(fd, stack_buf, 4096);
|
||||
if (len > 0) {
|
||||
*size += len;
|
||||
buffer = realloc(buffer, *size);
|
||||
memcpy(buffer+(*size-len), stack_buf, len);
|
||||
}
|
||||
}
|
||||
|
||||
if (add_zero) {
|
||||
*size = *size+1;
|
||||
buffer = realloc(buffer, *size);
|
||||
buffer[*size-1] = 0;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
|
||||
}
|
||||
|
||||
char *uwsgi_open_and_read(char *url, int *size, int add_zero, char *magic_table[]) {
|
||||
|
||||
int fd;
|
||||
@@ -1712,23 +1738,12 @@ char *uwsgi_open_and_read(char *url, int *size, int add_zero, char *magic_table[
|
||||
|
||||
// stdin ?
|
||||
if (!strcmp(url, "-")) {
|
||||
char stack_buf[4096];
|
||||
len = 1;
|
||||
while(len > 0) {
|
||||
len = read(0, stack_buf, 4096);
|
||||
if (len > 0) {
|
||||
*size += len;
|
||||
buffer = realloc(buffer, *size);
|
||||
memcpy(buffer+(*size-len), stack_buf, len);
|
||||
}
|
||||
}
|
||||
|
||||
if (add_zero) {
|
||||
*size = *size+1;
|
||||
buffer = realloc(buffer, *size);
|
||||
buffer[*size-1] = 0;
|
||||
}
|
||||
|
||||
buffer = uwsgi_read_fd(0, size, add_zero);
|
||||
}
|
||||
// fd ?
|
||||
else if (!strncmp("fd://", url, 5)) {
|
||||
fd = atoi(url+5);
|
||||
buffer = uwsgi_read_fd(fd, size, add_zero);
|
||||
}
|
||||
// http url ?
|
||||
else if (!strncmp("http://", url, 7)) {
|
||||
@@ -1971,6 +1986,10 @@ char *uwsgi_open_and_read(char *url, int *size, int add_zero, char *magic_table[
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (S_ISFIFO(sb.st_mode)) {
|
||||
buffer = uwsgi_read_fd(fd, size, add_zero);
|
||||
goto end;
|
||||
}
|
||||
|
||||
buffer = malloc(sb.st_size + add_zero);
|
||||
|
||||
@@ -1994,6 +2013,8 @@ char *uwsgi_open_and_read(char *url, int *size, int add_zero, char *magic_table[
|
||||
buffer[sb.st_size] = 0;
|
||||
}
|
||||
|
||||
end:
|
||||
|
||||
if (magic_table) {
|
||||
|
||||
magic_buf = magic_sub(buffer, *size, size, magic_table);
|
||||
|
||||
@@ -52,6 +52,8 @@ static struct option long_base_options[] = {
|
||||
{"set", required_argument, 0, 'S'},
|
||||
{"inherit", required_argument, 0, LONG_ARGS_INHERIT},
|
||||
{"daemonize", required_argument, 0, 'd'},
|
||||
{"stop", required_argument, 0, LONG_ARGS_STOP},
|
||||
{"reload", required_argument, 0, LONG_ARGS_RELOAD},
|
||||
{"listen", required_argument, 0, 'l'},
|
||||
{"max-vars", required_argument, 0, 'v'},
|
||||
{"buffer-size", required_argument, 0, 'b'},
|
||||
@@ -783,6 +785,22 @@ static void vacuum(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void signal_pidfile(int sig, char *filename) {
|
||||
|
||||
int size = 0;
|
||||
|
||||
char *buffer = uwsgi_open_and_read(filename, &size, 1, NULL);
|
||||
|
||||
if (size > 0) {
|
||||
if (kill((pid_t) atoi(buffer), sig)) {
|
||||
uwsgi_error("kill()");
|
||||
}
|
||||
}
|
||||
else {
|
||||
uwsgi_log("error: invalid pidfile\n");
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef UWSGI_AS_SHARED_LIBRARY
|
||||
int uwsgi_init(int argc, char *argv[], char *envp[]) {
|
||||
#else
|
||||
@@ -3036,6 +3054,12 @@ static int manage_base_opt(int i, char *optarg) {
|
||||
|
||||
usm->next = NULL;
|
||||
return 1;
|
||||
case LONG_ARGS_STOP:
|
||||
signal_pidfile(SIGINT, optarg);
|
||||
exit(0);
|
||||
case LONG_ARGS_RELOAD:
|
||||
signal_pidfile(SIGHUP, optarg);
|
||||
exit(0);
|
||||
case LONG_ARGS_ATTACH_DAEMON:
|
||||
if (uwsgi.startup_daemons_cnt < MAX_DAEMONS) {
|
||||
uwsgi.startup_daemons[uwsgi.startup_daemons_cnt] = optarg;
|
||||
|
||||
@@ -26,6 +26,8 @@ extern "C" {
|
||||
#define thunder_lock if (uwsgi.threads > 1) {pthread_mutex_lock(&uwsgi.thunder_mutex);}
|
||||
#define thunder_unlock if (uwsgi.threads > 1) {pthread_mutex_unlock(&uwsgi.thunder_mutex);}
|
||||
|
||||
#define uwsgi_check_scheme(file) (!uwsgi_startswith(file, "http://", 7) || !uwsgi_startswith(file, "data://", 7) || !uwsgi_startswith(file, "sym://", 6) || !uwsgi_startswith(file, "fd://", 5))
|
||||
|
||||
#define ushared uwsgi.shared
|
||||
|
||||
#define MAX_APPS 64
|
||||
@@ -486,6 +488,8 @@ struct uwsgi_opt {
|
||||
#define LONG_ARGS_FASTCGI_SOCKET 17133
|
||||
#define LONG_ARGS_THREADS_STACKSIZE 17134
|
||||
#define LONG_ARGS_EMPEROR_THROTTLE 17135
|
||||
#define LONG_ARGS_STOP 17136
|
||||
#define LONG_ARGS_RELOAD 17137
|
||||
|
||||
|
||||
#define UWSGI_OK 0
|
||||
|
||||
@@ -26,7 +26,7 @@ void uwsgi_xml_config(char *filename, struct wsgi_request *wsgi_req, int app_tag
|
||||
char *xml_content;
|
||||
int xml_size = 0;
|
||||
|
||||
if (!uwsgi_startswith(filename, "http://", 7) || !uwsgi_startswith(filename, "data://", 7) || !uwsgi_startswith(filename, "sym://", 6)) {
|
||||
if (uwsgi_check_scheme(filename)) {
|
||||
colon = uwsgi_get_last_char(filename, '/');
|
||||
colon = uwsgi_get_last_char(colon, ':');
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ void uwsgi_yaml_config(char *file, char *magic_table[]) {
|
||||
char *section_asked = "uwsgi";
|
||||
char *colon;
|
||||
|
||||
if (!uwsgi_startswith(file, "http://", 7) || !uwsgi_startswith(file, "data://", 7) || !uwsgi_startswith(file, "sym://", 6)) {
|
||||
if (!uwsgi_check_scheme(file)) {
|
||||
colon = uwsgi_get_last_char(file, '/');
|
||||
colon = uwsgi_get_last_char(colon, ':');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user