Permalink
Browse files

added master_cleanup hook and carbon flush on stop/reload

  • Loading branch information...
1 parent e735b9e commit 5cea1de1bac82d49fa37d7dbfc9b581c6abaebd2 roberto@quantal64 committed Sep 12, 2012
Showing with 35 additions and 1 deletion.
  1. +2 −0 core/master.c
  2. +24 −0 core/master_utils.c
  3. +4 −1 plugins/carbon/carbon.c
  4. +5 −0 uwsgi.h
View
@@ -608,6 +608,8 @@ int master_loop(char **argv, char **environ) {
uwsgi_unix_signal(SIGURG, uwsgi_restore_auto_snapshot);
}
+ atexit(uwsgi_master_cleanup_hooks);
+
uwsgi.master_queue = event_queue_init();
/* route signals to workers... */
View
@@ -5,6 +5,27 @@ extern struct uwsgi_server uwsgi;
void worker_wakeup() {
}
+void uwsgi_master_cleanup_hooks(void) {
+
+ int j;
+
+ uwsgi.cleaning = 1;
+
+ for (j = 0; j < uwsgi.gp_cnt; j++) {
+ if (uwsgi.gp[j]->master_cleanup) {
+ uwsgi.gp[j]->master_cleanup();
+ }
+ }
+
+ for (j = 0; j < 256; j++) {
+ if (uwsgi.p[j]->master_cleanup) {
+ uwsgi.p[j]->master_cleanup();
+ }
+ }
+
+}
+
+
int uwsgi_calc_cheaper(void) {
int i;
@@ -240,6 +261,9 @@ void uwsgi_reload(char **argv) {
waitpid(WAIT_ANY, &waitpid_status, WNOHANG);
}
+ // call master cleanup hooks
+ uwsgi_master_cleanup_hooks();
+
// call atexit user exec
uwsgi_exec_atexit();
View
@@ -68,7 +68,7 @@ void carbon_master_cycle() {
if (last_update == 0) last_update = uwsgi_now();
// update
- if (uwsgi.current_time - last_update >= u_carbon.freq) {
+ if (uwsgi.current_time - last_update >= u_carbon.freq || uwsgi.cleaning) {
for (i = 0; i < uwsgi.numproc; i++) {
u_carbon.current_busyness_values[i] = uwsgi.workers[i+1].running_time - u_carbon.last_busyness_values[i];
@@ -203,10 +203,13 @@ void carbon_master_cycle() {
}
}
+
struct uwsgi_plugin carbon_plugin = {
.name = "carbon",
+ .master_cleanup = carbon_master_cycle,
+
.options = carbon_options,
.master_cycle = carbon_master_cycle,
.post_init = carbon_post_init,
View
@@ -713,6 +713,8 @@ struct uwsgi_plugin {
int (*mule)(char *);
int (*mule_msg)(char *, size_t);
+ void (*master_cleanup) (void);
+
};
#ifdef UWSGI_PCRE
@@ -1519,6 +1521,8 @@ struct uwsgi_server {
int to_hell;
int to_outworld;
+ int cleaning;
+
int ready_to_die;
int ready_to_reload;
@@ -3241,6 +3245,7 @@ ssize_t uwsgi_pipe(int, int, int);
ssize_t uwsgi_pipe_sized(int, int, size_t, int);
int uwsgi_buffer_send(struct uwsgi_buffer *, int);
+void uwsgi_master_cleanup_hooks(void);
void uwsgi_check_emperor(void);
#ifdef UWSGI_AS_SHARED_LIBRARY

0 comments on commit 5cea1de

Please sign in to comment.