Added restart command in rmanager and also by signals.

Added a global child reaper to avoid zombies.


git-svn-id: http://yate.null.ro/svn/yate/trunk@530 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2005-09-29 19:34:23 +00:00
parent bd3a33710e
commit 0126e0c86a
5 changed files with 47 additions and 8 deletions

View File

@ -94,6 +94,15 @@ static void sighandler(int signal)
{
switch (signal) {
#ifndef _WINDOWS
case SIGCHLD:
::waitpid(-1,0,WNOHANG);
break;
case SIGUSR1:
Engine::restart(0,true);
break;
case SIGUSR2:
Engine::restart(0,false);
break;
case SIGHUP:
case SIGQUIT:
if (s_nextinit <= Time::now())
@ -313,6 +322,8 @@ static int supervise(void)
::signal(SIGHUP,superhandler);
::signal(SIGQUIT,superhandler);
::signal(SIGABRT,superhandler);
::signal(SIGUSR1,superhandler);
::signal(SIGUSR2,superhandler);
int retcode = 0;
while (s_runagain) {
int wdogfd[2];
@ -492,6 +503,9 @@ int Engine::run()
::signal(SIGHUP,sighandler);
::signal(SIGQUIT,sighandler);
::signal(SIGPIPE,SIG_IGN);
::signal(SIGCHLD,sighandler);
::signal(SIGUSR1,sighandler);
::signal(SIGUSR2,sighandler);
#endif
Output("Yate engine is initialized and starting up");
while (s_haltcode == -1) {
@ -532,6 +546,7 @@ int Engine::run()
s_haltcode = 128;
break;
}
DDebug(DebugAll,"Engine busy - will try to restart later");
// If we cannot restart now try again in 10s
s_restarts = Time::now() + 10000000;
}
@ -742,11 +757,14 @@ void Engine::halt(unsigned int code)
s_haltcode = code;
}
bool Engine::restart(unsigned int code)
bool Engine::restart(unsigned int code, bool gracefull)
{
if ((s_super_handle < 0) || (s_haltcode != -1))
return false;
s_haltcode = code | 0x80;
if (gracefull)
s_restarts = 1;
else
s_haltcode = (code & 0xff) | 0x80;
return true;
}

View File

@ -636,15 +636,15 @@ void ExtModReceiver::cleanup()
Thread::yield();
int w = ::waitpid(m_pid, 0, WNOHANG);
if (w == 0) {
Debug(DebugWarn, "Process %d has not exited on closing stdin - we'll kill it",m_pid);
Debug(DebugWarn,"Process %d has not exited on closing stdin - we'll kill it",m_pid);
::kill(m_pid,SIGTERM);
Thread::yield();
w = ::waitpid(m_pid, 0, WNOHANG);
}
if (w == 0)
Debug(DebugWarn, "Process %d has still not exited yet?",m_pid);
else if (w < 0)
Debug(DebugMild, "Failed waitpid on %d: %s",m_pid,strerror(errno));
Debug(DebugWarn,"Process %d has still not exited yet?",m_pid);
else if ((w < 0) && (errno != ECHILD))
Debug(DebugMild,"Failed waitpid on %d: %s",m_pid,strerror(errno));
m_pid = 0;
}
unuse();

View File

@ -45,6 +45,7 @@ static const char s_helpmsg[] =
" drop {chan|*|all}\n"
" call chan target\n"
" reload\n"
" restart [now]\n"
" stop [exitcode]\n";
static Configuration s_cfg;
@ -414,10 +415,25 @@ bool Connection::processLine(const char *line)
writeStr(m_machine ? "%%=reload\n" : "Reinitializing...\n");
Engine::init();
}
else if (str.startSkip("restart"))
{
bool gracefull = (str != "now");
bool ok = Engine::restart(0,gracefull);
if (ok) {
if (m_machine) {
writeStr("%%=restart\n");
return gracefull;
}
writeStr(gracefull ? "Restart scheduled - please disconnect\n" : "Engine restarting - bye!\n");
}
else
writeStr(m_machine ? "%%=restart:fail\n" : "Cannot restart - no supervisor or already shutting down\n");
}
else if (str.startSkip("stop"))
{
unsigned code = 0;
str >> code;
code &= 0xff;
writeStr(m_machine ? "%%=shutdown\n" : "Engine shutting down - bye!\n");
Engine::halt(code);
}

6
yate.8
View File

@ -16,7 +16,7 @@
.\" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
.\"
.\"
.TH YATE 8 "March 2004" "YATE" "Telephony Engine"
.TH YATE 8 "September 2005" "YATE" "Telephony Engine"
.SH NAME
\fByate\fP \- launch the YATE telephony engine
.SH SYNOPSIS
@ -96,6 +96,10 @@ the documentation for each module.
\- SIGTERM and SIGINT (Ctrl\-C) will cleanly stop the engine
.TP
\- SIGHUP and SIGQUIT (Ctrl\-\\) will reinitialize the modules
.TP
\- SIGUSR1 will initiate a gracefull restart (when no plugin is busy)
.TP
\- SIGUSR2 will initiate an immediate restart
.SH BUGS
Under various
.B *BSD

View File

@ -737,9 +737,10 @@ public:
/**
* Stop and restart the engine and the entire program
* @param code Return code of the program
* @param gracefull Attempt to wait until no plugin is busy
* @return True if restart was initiated, false if exiting or no supervisor
*/
static bool restart(unsigned int code);
static bool restart(unsigned int code, bool gracefull = false);
/**
* Check if the engine is currently exiting