added support for systemd socket activation

This commit is contained in:
roberto@fedora15
2011-07-22 13:03:18 +02:00
parent c26861bff6
commit d590a189ed
2 changed files with 37 additions and 2 deletions
+12 -2
View File
@@ -808,7 +808,12 @@ void uwsgi_add_socket_from_fd(struct uwsgi_socket *uwsgi_sock, int fd) {
uwsgi_sock->family = AF_UNIX;
uwsgi_sock->bound = 1;
uwsgi_sock->name = uwsgi_concat2(usa.sa_un.sun_path+abstract, "");
uwsgi_log("uwsgi zerg socket %d attached to UNIX address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), usa.sa_un.sun_path+abstract, uwsgi_sock->fd);
if (uwsgi.zerg) {
uwsgi_log("uwsgi zerg socket %d attached to UNIX address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), usa.sa_un.sun_path+abstract, uwsgi_sock->fd);
}
else {
uwsgi_log("uwsgi socket %d attached to UNIX address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), usa.sa_un.sun_path+abstract, uwsgi_sock->fd);
}
return;
}
if (!strcmp(usa.sa_un.sun_path+abstract, uwsgi_sock->name+abstract)) {
@@ -843,7 +848,12 @@ void uwsgi_add_socket_from_fd(struct uwsgi_socket *uwsgi_sock, int fd) {
uwsgi_sock->family = AF_INET;
uwsgi_sock->bound = 1;
uwsgi_sock->name = uwsgi_concat2(computed_addr, "");
uwsgi_log("uwsgi zerg socket %d attached to INET address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), computed_addr, uwsgi_sock->fd);
if (uwsgi.zerg) {
uwsgi_log("uwsgi zerg socket %d attached to INET address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), computed_addr, uwsgi_sock->fd);
}
else {
uwsgi_log("uwsgi socket %d attached to INET address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), computed_addr, uwsgi_sock->fd);
}
free(computed_addr);
return;
}
+25
View File
@@ -1656,6 +1656,29 @@ int uwsgi_start(void *v_argv) {
if (!uwsgi.no_server) {
// systemd socket activation
if (!uwsgi.is_a_reload) {
char *listen_pid = getenv("LISTEN_PID");
if (listen_pid) {
if (atoi(listen_pid) == (int) getpid()) {
char *listen_fds = getenv("LISTEN_FDS");
if (listen_fds) {
int systemd_fds = atoi(listen_fds);
if (systemd_fds > 0) {
for(i=3;i<3+systemd_fds;i++) {
uwsgi_sock = uwsgi_new_socket(NULL);
uwsgi_add_socket_from_fd(uwsgi_sock, i);
}
}
unsetenv("LISTEN_PID");
unsetenv("LISTEN_FDS");
goto skipzero;
}
}
}
}
//check for inherited sockets
if (uwsgi.is_a_reload || uwsgi.zerg) {
@@ -1795,6 +1818,8 @@ int uwsgi_start(void *v_argv) {
}
}
skipzero:
// check for auto_port socket
uwsgi_sock = uwsgi.sockets;