Reloading of the uWSGI server

The uWSGI server can be restarted without closing the main sockets.

This function allows to patch/upgrade the uWSGI server without closing connection with the webserver.

To obtain this behaviour when you send the SIGHUP to the master process it will try to gracefully stop all the workers (waiting for completion of currently running requests). SIGTERM will obtain the same result but will not wait for running requests completion.

Then it closes all the eventually opened file descriptor not related to uWSGI.

Lastly it assign the server socket descriptor to a fixed fd (3) and call execve with the original args and environment.

When the process image is overwritten the new server is alive and check if it is a "respawned" instance:

if (!getsockopt(3, SOL_SOCKET, SO_TYPE, &socket_type, &socket_type_len)) {
    fprintf(stderr, "...fd 3 is a socket, i suppose this is a graceful reload of uWSGI, i will try to do my best...\n");
    is_a_reload = 1 ;
    serverfd = 3;
}

Now the server knows that it is a reloaded instance and will skip all the socket initialization.