]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add fsctl shutdown [elegant|restart] <- one or both keywords
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 2 Oct 2008 16:46:20 +0000 (16:46 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 2 Oct 2008 16:46:20 +0000 (16:46 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9788 d0543943-73ff-0310-b7d9-9358b9ac24b2

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

index 5fa11ce62692f22fec905f39f09bbb2ef33e744c..5e3def5d12a0f4f641a1397a48b0efba81bc870c 100644 (file)
@@ -210,7 +210,8 @@ typedef enum {
        SCF_NO_NEW_SESSIONS = (1 << 1),
        SCF_SHUTTING_DOWN = (1 << 2),
        SCF_CRASH_PROT = (1 << 3),
-       SCF_VG = (1 << 4)
+       SCF_VG = (1 << 4),
+       SCF_RESTART = (1 << 5)
 } switch_core_flag_enum_t;
 typedef uint32_t switch_core_flag_t;
 
@@ -1213,7 +1214,8 @@ typedef enum {
        SCSC_MAX_SESSIONS,
        SCSC_SYNC_CLOCK,
        SCSC_MAX_DTMF_DURATION,
-       SCSC_DEFAULT_DTMF_DURATION
+       SCSC_DEFAULT_DTMF_DURATION,
+       SCSC_SHUTDOWN_ELEGANT
 } switch_session_ctl_t;
 
 typedef struct apr_pool_t switch_memory_pool_t;
index 67b9e167603394eb455e0663e78d1bd52243c0da..4cc0d289beba77f3781f90ef5aafa63f6eaf29aa 100644 (file)
@@ -673,7 +673,7 @@ SWITCH_STANDARD_API(status_function)
        return SWITCH_STATUS_SUCCESS;
 }
 
-#define CTL_SYNTAX "[hupall|pause|resume|shutdown|sps|sync_clock|reclaim_mem|max_sessions|max_dtmf_duration [num]|loglevel [level]]"
+#define CTL_SYNTAX "[hupall|pause|resume|shutdown [elegant|restart]|sps|sync_clock|reclaim_mem|max_sessions|max_dtmf_duration [num]|loglevel [level]]"
 SWITCH_STANDARD_API(ctl_function)
 {
        int argc;
@@ -701,8 +701,21 @@ SWITCH_STANDARD_API(ctl_function)
                        switch_core_session_ctl(SCSC_PAUSE_INBOUND, &arg);
                        stream->write_function(stream, "+OK\n");
                } else if (!strcasecmp(argv[0], "shutdown")) {
+                       switch_session_ctl_t cmd = SCSC_SHUTDOWN;
+                       int x = 0;
                        arg = 0;
-                       switch_core_session_ctl(SCSC_SHUTDOWN, &arg);
+                       for (x = 1; x < 5; x++) {
+                               if (argv[x]) {
+                                       if (!strcasecmp(argv[x], "elegant")) {
+                                               cmd = SCSC_SHUTDOWN_ELEGANT;
+                                       } else if (!strcasecmp(argv[x], "restart")) {
+                                               arg = 1;
+                                       }
+                               } else {
+                                       break;
+                               }
+                       }
+                       switch_core_session_ctl(cmd, &arg);
                        stream->write_function(stream, "+OK\n");
                } else if (!strcasecmp(argv[0], "reclaim_mem")) {
                        switch_core_session_ctl(SCSC_RECLAIM, &arg);
@@ -2662,6 +2675,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
        switch_console_set_complete("add fsctl pause");
        switch_console_set_complete("add fsctl resume");
        switch_console_set_complete("add fsctl shutdown");
+       switch_console_set_complete("add fsctl shutdown restart");
+       switch_console_set_complete("add fsctl shutdown elegant");
+       switch_console_set_complete("add fsctl shutdown elegant restart");
        switch_console_set_complete("add fsctl sps");
        switch_console_set_complete("add fsctl sync_clock");
        switch_console_set_complete("add fsctl reclaim_mem");
index a8759b0784aa3bc7995039eeec1e24b1f09ffd9e..5d92f7b94fe70b3ef2cceb2acf14b9d3f204cd17 100644 (file)
@@ -270,6 +270,7 @@ int main(int argc, char *argv[])
        int high_prio = 0;
        switch_core_flag_t flags = SCF_USE_SQL;
        int ret;
+       switch_status_t destroy_status;
        switch_file_t *fd;
        switch_memory_pool_t *pool = NULL;
 
@@ -607,14 +608,20 @@ int main(int argc, char *argv[])
 
        switch_core_runtime_loop(nc);
 
-       ret = switch_core_destroy();
-
+       destroy_status = switch_core_destroy();
+       
        switch_file_close(fd);
 
        if (unlink(pid_path) != 0) {
                fprintf(stderr, "Failed to delete pid file [%s]\n", pid_path);
        }
 
+       if (destroy_status == SWITCH_STATUS_RESTART) {
+               printf("WTF\n");
+               execv(argv[0], argv);
+               ret = 0;
+       }
+
        return ret;
 }
 
index b328ff5ff766713d3969aed1fd8c42a3023acf41..9bc73e090288aaaa92ac7b73819958ceb35b0ff4 100644 (file)
@@ -1304,8 +1304,28 @@ 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_SHUTDOWN_ELEGANT:
+               {
+                       int x = 19;
+                       if (*val) {
+                               switch_set_flag((&runtime), SCF_RESTART);
+                       }
+                       switch_set_flag((&runtime), SCF_NO_NEW_SESSIONS);
+                       while(runtime.running && 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;
+               }
+               break;
        case SCSC_SHUTDOWN:
                runtime.running = 0;
+               if (*val) {
+                       switch_set_flag((&runtime), SCF_RESTART);
+               }
                break;
        case SCSC_CHECK_RUNNING:
                *val = runtime.running;
@@ -1347,6 +1367,7 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, int32_
                break;
        }
 
+
        return 0;
 }
 
@@ -1412,8 +1433,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_destroy(void)
                apr_pool_destroy(runtime.memory_pool);
                /* apr_terminate(); */
        }
-
-       return SWITCH_STATUS_SUCCESS;
+       
+       return switch_test_flag((&runtime), SCF_RESTART) ? SWITCH_STATUS_RESTART : SWITCH_STATUS_SUCCESS;
 }
 
 SWITCH_DECLARE(switch_status_t) switch_core_management_exec(char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen)