mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-02 11:19:28 +00:00
add fsctl shutdown [elegant|restart] <- one or both keywords
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9788 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
3c2699ec2a
commit
f23c88d9fa
@ -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;
|
||||
|
@ -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");
|
||||
|
11
src/switch.c
11
src/switch.c
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user