Author: anthm Date: Thu Oct 2 12:46:20 2008 New Revision: 9788 Modified: freeswitch/trunk/src/include/switch_types.h freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c freeswitch/trunk/src/switch.c freeswitch/trunk/src/switch_core.c Log: add fsctl shutdown [elegant|restart] <- one or both keywords Modified: freeswitch/trunk/src/include/switch_types.h ============================================================================== --- freeswitch/trunk/src/include/switch_types.h (original) +++ freeswitch/trunk/src/include/switch_types.h Thu Oct 2 12:46:20 2008 @@ -210,7 +210,8 @@ 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 @@ 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; Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c ============================================================================== --- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c (original) +++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c Thu Oct 2 12:46:20 2008 @@ -673,7 +673,7 @@ 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_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_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"); Modified: freeswitch/trunk/src/switch.c ============================================================================== --- freeswitch/trunk/src/switch.c (original) +++ freeswitch/trunk/src/switch.c Thu Oct 2 12:46:20 2008 @@ -270,6 +270,7 @@ 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 @@ 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; } Modified: freeswitch/trunk/src/switch_core.c ============================================================================== --- freeswitch/trunk/src/switch_core.c (original) +++ freeswitch/trunk/src/switch_core.c Thu Oct 2 12:46:20 2008 @@ -1304,8 +1304,28 @@ 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 @@ break; } + return 0; } @@ -1412,8 +1433,8 @@ 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)