Patch level : 10.0
Files correlati : lurch.exe Ricompilazione Demo : [ ] Commento : Ora il maggiordomo e' in grado di uccidere anche i servi precedenti la sua nomina, potrebbero fargli le scarpe... git-svn-id: svn://10.65.10.50/trunk@20011 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
2b4f86ae5c
commit
62742e9cdd
125
server/lurch.cpp
125
server/lurch.cpp
@ -17,7 +17,7 @@ class TLurchServer : public TBaseServerApp
|
||||
TProcessHashMap m_hmProcMap;
|
||||
wxSemaphore m_Semaphore;
|
||||
wxTimer m_PingTimer;
|
||||
wxArrayString m_aServers;
|
||||
wxArrayString m_aServers, m_aAutoRun;
|
||||
|
||||
DECLARE_EVENT_TABLE();
|
||||
|
||||
@ -31,6 +31,7 @@ protected:
|
||||
void EnumerateVariables(const wxString& strApp, wxArrayString& arr) const;
|
||||
|
||||
const wxArrayString& GetServersList();
|
||||
const wxArrayString& GetAutoRunList();
|
||||
const TProcessHashMap& GetRunningServers() { return m_hmProcMap; }
|
||||
|
||||
bool PingProcess(const wxString& strApp);
|
||||
@ -67,10 +68,6 @@ BEGIN_EVENT_TABLE(TLurchServer, TBaseServerApp)
|
||||
EVT_END_PROCESS(wxID_ANY, TLurchServer::OnEndProcess)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
#ifndef max
|
||||
#define max(a,b) ((a)>(b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
bool TLurchServer::PingProcess(const wxString& strApp)
|
||||
{
|
||||
bool bPinged = false;
|
||||
@ -78,8 +75,10 @@ bool TLurchServer::PingProcess(const wxString& strApp)
|
||||
const wxString strPort = GetConfigString("Port", "", strApp);
|
||||
if (!strPort.IsEmpty())
|
||||
{
|
||||
const int nInterval = m_PingTimer.GetInterval(); // msec
|
||||
const int nTimeOut = max(nInterval/4, 250); // msec
|
||||
int nTimeOut = m_PingTimer.GetInterval()/4; // msec
|
||||
if (nTimeOut < 250) nTimeOut = 250; else
|
||||
if (nTimeOut > 2000) nTimeOut = 2000;
|
||||
|
||||
wxIPV4address ipAddress;
|
||||
ipAddress.LocalHost();
|
||||
ipAddress.Service(strPort);
|
||||
@ -107,40 +106,43 @@ bool TLurchServer::PingProcess(const wxString& strApp)
|
||||
|
||||
void TLurchServer::OnTimer(wxTimerEvent& evt)
|
||||
{
|
||||
if (m_Semaphore.TryWait() != wxSEMA_NO_ERROR)
|
||||
const wxSemaError se = m_Semaphore.TryWait();
|
||||
if (se == wxSEMA_NO_ERROR)
|
||||
{
|
||||
evt.Skip();
|
||||
return;
|
||||
}
|
||||
|
||||
const TProcessHashMap& hmServers = GetRunningServers();
|
||||
const int nServers = hmServers.size();
|
||||
if (nServers > 0) // Is anybody out there?
|
||||
{
|
||||
const int nRandomIndex = rand() % nServers;
|
||||
wxString strApp; // Usually "Authorization"
|
||||
TProcessHashMap::const_iterator it;
|
||||
for (it = hmServers.begin(); it != hmServers.end(); ++it)
|
||||
strApp = it->first;
|
||||
|
||||
if (!PingProcess(strApp))
|
||||
const wxArrayString& aServers = GetAutoRunList();
|
||||
const size_t nServers = aServers.GetCount();
|
||||
if (nServers > 0) // Is anybody out there?
|
||||
{
|
||||
wxProcess* pProcess = m_hmProcMap[strApp];
|
||||
wxKillError ke = pProcess->Kill(pProcess->GetPid());
|
||||
if (ke == wxKILL_OK)
|
||||
WriteLog(strApp + _(" killed!"));
|
||||
else
|
||||
const int nRandomIndex = ::rand() % nServers;
|
||||
const wxString& strApp = aServers[nRandomIndex]; // Usually "Authorization"
|
||||
if (!PingProcess(strApp))
|
||||
{
|
||||
wxString strMsg;
|
||||
strMsg << _("Error ") << ke << _(" killing ") << strApp;
|
||||
WriteLog(strMsg);
|
||||
if (!strApp.IsEmpty()) // Dummy test
|
||||
{
|
||||
const wxSingleInstanceChecker sic(strApp);
|
||||
if (sic.IsAnotherRunning())
|
||||
{
|
||||
wxProcess* pProcess = m_hmProcMap[strApp];
|
||||
wxKillError ke = pProcess->Kill(pProcess->GetPid());
|
||||
if (ke == wxKILL_OK)
|
||||
WriteLog(strApp + _(" killed!"));
|
||||
else
|
||||
{
|
||||
wxString strMsg;
|
||||
strMsg << _("Error ") << ke << _(" killing ") << strApp;
|
||||
WriteLog(strMsg);
|
||||
}
|
||||
wxSleep(2);
|
||||
}
|
||||
}
|
||||
StartProcess(strApp);
|
||||
}
|
||||
wxSleep(2);
|
||||
StartProcess(strApp);
|
||||
}
|
||||
}
|
||||
|
||||
m_Semaphore.Post();
|
||||
m_Semaphore.Post();
|
||||
}
|
||||
else
|
||||
evt.Skip();
|
||||
}
|
||||
|
||||
void TLurchServer::OnEndProcess(wxProcessEvent& evt)
|
||||
@ -187,6 +189,22 @@ const wxArrayString& TLurchServer::GetServersList()
|
||||
return m_aServers;
|
||||
}
|
||||
|
||||
const wxArrayString& TLurchServer::GetAutoRunList()
|
||||
{
|
||||
if (m_aAutoRun.IsEmpty())
|
||||
{
|
||||
const wxArrayString& as = GetServersList();
|
||||
for (size_t i = 0; i < as.GetCount(); i++)
|
||||
{
|
||||
const bool bAutorun = GetConfigBool("Autorun", false, as[i]);
|
||||
if (bAutorun)
|
||||
m_aAutoRun.Add(as[i]);
|
||||
}
|
||||
}
|
||||
return m_aAutoRun;
|
||||
}
|
||||
|
||||
|
||||
TXmlItem& TLurchServer::AddMiniForm(TXmlItem& tr, const wxChar* action, const wxChar* app, const wxChar* prompt) const
|
||||
{
|
||||
TXmlItem& td = tr.AddChild("td").SetAttr("width", "10%");
|
||||
@ -242,12 +260,13 @@ void TLurchServer::GenerateFile(wxString& strFilename)
|
||||
TXmlItem& img = a.AddChild("img");
|
||||
img.SetAttr("src", strIcon); img.SetAttr("border", 0L); img.SetAttr("alt", arr[i]);
|
||||
|
||||
const bool bAutoRun = bLurch || GetAutoRunList().Index(arr[i]) != wxNOT_FOUND;
|
||||
TXmlItem& buttStart = AddMiniForm(tr, "start.cgi", arr[i], _("Start"));
|
||||
if (bRunning || bLurch)
|
||||
if (bRunning || bAutoRun)
|
||||
buttStart.SetAttr(wxT("type"), wxT("hidden"));
|
||||
|
||||
TXmlItem& buttStop = AddMiniForm(tr, "kill.cgi", arr[i], _("Stop"));
|
||||
if (!(bRunning || bLurch))
|
||||
if (!bLurch && (!bRunning || bAutoRun))
|
||||
buttStop.SetAttr(wxT("type"), wxT("hidden"));
|
||||
|
||||
TXmlItem& buttRestart = AddMiniForm(tr, "restart.cgi", arr[i], _("Restart"));
|
||||
@ -440,7 +459,7 @@ void TLurchServer::ProcessFormStop(const THashTable& args, wxSocketBase& sock)
|
||||
StopProcess(strApp);
|
||||
MessageBox("Server stopped", strApp, sock);
|
||||
|
||||
m_Semaphore.Post();
|
||||
m_Semaphore.Post(); // Inutile, ma cosi' non rompo la simmetria
|
||||
}
|
||||
}
|
||||
|
||||
@ -626,25 +645,19 @@ void TLurchServer::ProcessHttpPost(wxString cmd, wxSocketBase& outs)
|
||||
|
||||
bool TLurchServer::Initialization()
|
||||
{
|
||||
const wxArrayString& arr = GetServersList();
|
||||
for (size_t i = 0; i < arr.GetCount(); i++)
|
||||
{
|
||||
const wxString& strApp = arr[i];
|
||||
if (strApp != GetAppName())
|
||||
{
|
||||
const bool bAutorun = GetConfigBool("Autorun", false, strApp);
|
||||
if (bAutorun)
|
||||
StartProcess(strApp);
|
||||
}
|
||||
}
|
||||
|
||||
const int nFreq = GetConfigInt("PingFreq");
|
||||
if (nFreq > 0)
|
||||
const wxArrayString& arr = GetAutoRunList();
|
||||
const size_t nAuto = arr.GetCount();
|
||||
if (nAuto > 0)
|
||||
{
|
||||
m_PingTimer.Start(nFreq * 1000); // sec to msec
|
||||
m_Semaphore.Post(); // GREEN!
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < nAuto; i++)
|
||||
StartProcess(arr[i]);
|
||||
const int nFreq = GetConfigInt("PingFreq");
|
||||
if (nFreq > 0)
|
||||
{
|
||||
m_PingTimer.Start(nFreq * 1000); // sec to msec
|
||||
m_Semaphore.Post(); // GREEN!
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user