Module: sems Branch: master Commit: 434cba1cc77d1870b5451254c19aa956862d6c61 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=434cba1cc77d1870b5451254c19aa956862d6c61
Author: Stefan Sayer <[email protected]> Committer: Stefan Sayer <[email protected]> Date: Wed Feb 2 17:35:54 2011 +0100 SIGTERM stops server without sending BYE SIGHUP - broadcast shutdown, usually sends BYE and stops all calls. The server does not terminate. SIGINT - broadcast shutdown (usually sends BYE and stops all calls), and stop. SIGTERM - stop the server, without broadcasting shutdown (no BYEs sent). --- core/AmSessionContainer.cpp | 36 ++++++++++++++++++++++-------------- core/AmSessionContainer.h | 6 ++++++ core/sems.cpp | 4 ++++ doc/src/doc_signals.h | 3 ++- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/core/AmSessionContainer.cpp b/core/AmSessionContainer.cpp index 1dd9f06..0bf1bb3 100644 --- a/core/AmSessionContainer.cpp +++ b/core/AmSessionContainer.cpp @@ -44,7 +44,7 @@ AmSessionContainer* AmSessionContainer::_instance=NULL; _MONITORING_DECLARE_INTERFACE(AmSessionContainer); AmSessionContainer::AmSessionContainer() - : _run_cond(false), _container_closed(false) + : _run_cond(false), _container_closed(false), enable_unclean_shutdown(false) { } @@ -149,23 +149,27 @@ void AmSessionContainer::on_stop() { _container_closed.set(true); - broadcastShutdown(); + if (enable_unclean_shutdown) { + INFO("unclean shutdown requested - not broadcasting shutdown\n"); + } else { + broadcastShutdown(); - DBG("waiting for active event queues to stop...\n"); + DBG("waiting for active event queues to stop...\n"); - for (unsigned int i=0; - (!AmEventDispatcher::instance()->empty() && - (!AmConfig::MaxShutdownTime || - i < AmConfig::MaxShutdownTime * 1000 / 10));i++) - usleep(10000); + for (unsigned int i=0; + (!AmEventDispatcher::instance()->empty() && + (!AmConfig::MaxShutdownTime || + i < AmConfig::MaxShutdownTime * 1000 / 10));i++) + usleep(10000); - if (!AmEventDispatcher::instance()->empty()) { - WARN("Not all calls cleanly ended!\n"); - } + if (!AmEventDispatcher::instance()->empty()) { + WARN("Not all calls cleanly ended!\n"); + } - DBG("cleaning sessions...\n"); - while (clean_sessions()) - usleep(10000); + DBG("cleaning sessions...\n"); + while (clean_sessions()) + usleep(10000); + } _run_cond.set(true); // so that thread stops } @@ -434,3 +438,7 @@ bool AmSessionContainer::addSession(const string& local_tag, return AmEventDispatcher::instance()-> addEventQueue(local_tag,(AmEventQueue*)session); } + +void AmSessionContainer::enableUncleanShutdown() { + enable_unclean_shutdown = true; +} diff --git a/core/AmSessionContainer.h b/core/AmSessionContainer.h index 121629b..82ee08c 100644 --- a/core/AmSessionContainer.h +++ b/core/AmSessionContainer.h @@ -67,6 +67,9 @@ class AmSessionContainer : public AmThread /** We are a Singleton ! Avoid people to have their own instance. */ AmSessionContainer(); + + bool enable_unclean_shutdown; + /** * Tries to stop the session and queue it destruction. */ @@ -148,6 +151,9 @@ class AmSessionContainer : public AmThread */ void broadcastShutdown(); + /** enable unclean shutdown (will not broadcastShutdown event) */ + void enableUncleanShutdown(); + _MONITORING_DEFINE_INTERFACE; }; diff --git a/core/sems.cpp b/core/sems.cpp index 8f6b093..f0cabb2 100644 --- a/core/sems.cpp +++ b/core/sems.cpp @@ -226,6 +226,10 @@ static void signal_handler(int sig) return; } + if (sig == SIGTERM) { + AmSessionContainer::instance()->enableUncleanShutdown(); + } + if (main_pid == getpid()) { if(!is_shutting_down.get()) { is_shutting_down.set(true); diff --git a/doc/src/doc_signals.h b/doc/src/doc_signals.h index 5033b38..9ade007 100644 --- a/doc/src/doc_signals.h +++ b/doc/src/doc_signals.h @@ -6,7 +6,8 @@ The execution of the server can be controlled by sending signals to the process. \li SIGHUP - broadcast shutdown, usually sends BYE and stops all calls. The server does not terminate. - \li SIGTERM, SIGINT - broadcast shutdown (usually sends BYE and stops all calls), and stop. + \li SIGINT - broadcast shutdown (usually sends BYE and stops all calls), and stop. This also happens when sems is run in foreground and Ctrl-C is pressed. + \li SIGTERM - stop the server, without broadcasting shutdown (no BYEs sent). \li SIGUSR1, SIGUSR2 - broadcast a system event with id User1 or User2, can for example be used in DSM with system(#type=="User2") condition \section see_also See also _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
