Skip to content

Commit

Permalink
implemented graceful shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
unbit committed Sep 18, 2013
1 parent f249153 commit 1535b8e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/fifo.c
Expand Up @@ -31,6 +31,7 @@ void uwsgi_master_fifo_prepare() {
uwsgi_fifo_table['L'] = uwsgi_log_rotate;
uwsgi_fifo_table['p'] = suspend_resume_them_all;
uwsgi_fifo_table['P'] = uwsgi_update_pidfiles;
uwsgi_fifo_table['q'] = gracefully_kill_them_all;
uwsgi_fifo_table['Q'] = kill_them_all;
uwsgi_fifo_table['r'] = grace_them_all;
uwsgi_fifo_table['R'] = reap_them_all;
Expand Down
22 changes: 22 additions & 0 deletions core/uwsgi.c
Expand Up @@ -1227,6 +1227,28 @@ void kill_them_all(int signum) {
uwsgi_destroy_processes();
}

// gracefully destroy
void gracefully_kill_them_all(int signum) {

if (uwsgi_instance_is_dying) return;
uwsgi.status.gracefully_destroying = 1;

// unsubscribe if needed
uwsgi_unsubscribe_all();

uwsgi_log_verbose("graceful shutdown triggered...\n");

int i;
for (i = 1; i <= uwsgi.numproc; i++) {
if (uwsgi.workers[i].pid > 0) {
uwsgi_curse(i, SIGHUP);
}
}

uwsgi_destroy_processes();
}


// graceful reload
void grace_them_all(int signum) {
if (uwsgi_instance_is_reloading || uwsgi_instance_is_dying)
Expand Down
1 change: 1 addition & 0 deletions uwsgi.h
Expand Up @@ -4326,6 +4326,7 @@ void uwsgi_reload_workers();
void uwsgi_chain_reload();
void uwsgi_refork_master();
void uwsgi_update_pidfiles();
void gracefully_kill_them_all(int);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 1535b8e

Please sign in to comment.