]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add shutdown cancel
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 3 Oct 2008 14:58:36 +0000 (14:58 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 3 Oct 2008 14:58:36 +0000 (14:58 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9807 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_types.h
src/mod/applications/mod_commands/mod_commands.c
src/switch_core.c

index cfc532931b68d777b663c9c4deba13e97b371d16..761a027e1acfb4be45ce54e07c1d33acdb78c81f 100644 (file)
@@ -211,7 +211,8 @@ typedef enum {
        SCF_SHUTTING_DOWN = (1 << 2),
        SCF_CRASH_PROT = (1 << 3),
        SCF_VG = (1 << 4),
-       SCF_RESTART = (1 << 5)
+       SCF_RESTART = (1 << 5),
+       SCF_SHUTDOWN_REQUESTED = (1 << 6)
 } switch_core_flag_enum_t;
 typedef uint32_t switch_core_flag_t;
 
@@ -1219,7 +1220,8 @@ typedef enum {
        SCSC_SYNC_CLOCK,
        SCSC_MAX_DTMF_DURATION,
        SCSC_DEFAULT_DTMF_DURATION,
-       SCSC_SHUTDOWN_ELEGANT
+       SCSC_SHUTDOWN_ELEGANT,
+       SCSC_CANCEL_SHUTDOWN
 } switch_session_ctl_t;
 
 typedef struct apr_pool_t switch_memory_pool_t;
index 43502428de796244d977827aa0421db6b67c87ba..ccd8a4cfeed68e3cc19b55d4bb70aa7c320db1be 100644 (file)
@@ -673,7 +673,7 @@ SWITCH_STANDARD_API(status_function)
        return SWITCH_STATUS_SUCCESS;
 }
 
-#define CTL_SYNTAX "[hupall|pause|resume|shutdown [elegant|restart]|sps|sync_clock|reclaim_mem|max_sessions|max_dtmf_duration [num]|loglevel [level]]"
+#define CTL_SYNTAX "[hupall|pause|resume|shutdown [cancel|elegant|restart]|sps|sync_clock|reclaim_mem|max_sessions|max_dtmf_duration [num]|loglevel [level]]"
 SWITCH_STANDARD_API(ctl_function)
 {
        int argc;
@@ -706,7 +706,11 @@ SWITCH_STANDARD_API(ctl_function)
                        arg = 0;
                        for (x = 1; x < 5; x++) {
                                if (argv[x]) {
-                                       if (!strcasecmp(argv[x], "elegant")) {
+                                       if (!strcasecmp(argv[x], "cancel")) {
+                                               arg = 0;
+                                               cmd = SCSC_CANCEL_SHUTDOWN;
+                                               break;
+                                       } else if (!strcasecmp(argv[x], "elegant")) {
                                                cmd = SCSC_SHUTDOWN_ELEGANT;
                                        } else if (!strcasecmp(argv[x], "restart")) {
                                                arg = 1;
@@ -2679,6 +2683,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
        switch_console_set_complete("add fsctl shutdown elegant");
        switch_console_set_complete("add fsctl shutdown elegant restart");
        switch_console_set_complete("add fsctl shutdown restart elegant");
+       switch_console_set_complete("add fsctl shutdown cancel");
        switch_console_set_complete("add fsctl sps");
        switch_console_set_complete("add fsctl sync_clock");
        switch_console_set_complete("add fsctl reclaim_mem");
index 99850ef768762db6ce0f6394e79c7c491f007e2b..8675cd33b6bfef8474d2d072299ff870150559ff 100644 (file)
@@ -1304,28 +1304,46 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, int32_
        case SCSC_HUPALL:
                switch_core_session_hupall(SWITCH_CAUSE_MANAGER_REQUEST);
                break;
+       case SCSC_CANCEL_SHUTDOWN:
+               switch_clear_flag((&runtime), SCF_SHUTDOWN_REQUESTED);
+               break;
        case SCSC_SHUTDOWN_ELEGANT:
                {
                        int x = 19;
-                       if (*val) {
-                               switch_set_flag((&runtime), SCF_RESTART);
-                       }
+                       
+                       switch_set_flag((&runtime), SCF_SHUTDOWN_REQUESTED);
                        switch_set_flag((&runtime), SCF_NO_NEW_SESSIONS);
-                       while(runtime.running && switch_core_session_count()) {
+
+                       while(runtime.running && switch_test_flag((&runtime), SCF_SHUTDOWN_REQUESTED) && switch_core_session_count()) {
                                switch_yield(500000);
                                if (++x == 20) {
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Shutdown in progress.....\n");
                                        x = 0;
                                }
                        }
-                       runtime.running = 0;
+                       
+                       if (switch_test_flag((&runtime), SCF_SHUTDOWN_REQUESTED)) {
+                               if (*val) {
+                                       switch_set_flag((&runtime), SCF_RESTART);
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Restarting\n");
+                               } else {
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Shutting down\n");
+                               }
+                               runtime.running = 0;
+                       } else {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Shutdown Cancelled\n");
+                               switch_clear_flag((&runtime), SCF_NO_NEW_SESSIONS);
+                       }
                }
                break;
        case SCSC_SHUTDOWN:
-               runtime.running = 0;
                if (*val) {
                        switch_set_flag((&runtime), SCF_RESTART);
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Restarting\n");
+               } else {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Shutting down\n");
                }
+               runtime.running = 0;
                break;
        case SCSC_CHECK_RUNNING:
                *val = runtime.running;
@@ -1431,7 +1449,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_destroy(void)
 
        if (runtime.memory_pool) {
                apr_pool_destroy(runtime.memory_pool);
-               /* apr_terminate(); */
+               if (switch_test_flag((&runtime), SCF_RESTART)) {
+                       apr_terminate();
+               }
        }
        
        return switch_test_flag((&runtime), SCF_RESTART) ? SWITCH_STATUS_RESTART : SWITCH_STATUS_SUCCESS;