X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=SHUTTLE%2FAliShuttleTrigger.cxx;h=9105d3559442db34aef7f3158d4b0f351f7156e0;hb=40196108124d83e49ffc422fc398a60da4346947;hp=d53ae7207e9906510999b371dccb890dfdfaaf9e;hpb=ff3781ad009f137ba9ce58f54427c6c25460da38;p=u%2Fmrichter%2FAliRoot.git diff --git a/SHUTTLE/AliShuttleTrigger.cxx b/SHUTTLE/AliShuttleTrigger.cxx index d53ae7207e9..9105d355944 100644 --- a/SHUTTLE/AliShuttleTrigger.cxx +++ b/SHUTTLE/AliShuttleTrigger.cxx @@ -108,12 +108,15 @@ #include "AliShuttleTrigger.h" #include +#include #include "AliLog.h" #include "AliShuttleConfig.h" #include "AliShuttle.h" #include "DATENotifier.h" +#include + ClassImp(TerminateSignalHandler) ClassImp(AliShuttleTrigger) @@ -134,7 +137,8 @@ AliShuttleTrigger::AliShuttleTrigger(const AliShuttleConfig* config): fNotified(kFALSE), fTerminate(kFALSE), fMutex(), fCondition(&fMutex), fQuitSignalHandler(0), - fInterruptSignalHandler(0) + fInterruptSignalHandler(0), + fLastMailDiskSpace(0) { // // config - pointer to the AliShuttleConfig object which represents @@ -148,8 +152,8 @@ AliShuttleTrigger::AliShuttleTrigger(const AliShuttleConfig* config): Int_t retries = fConfig->GetDCSRetries(); fShuttle = new AliShuttle(config, timeout, retries); - TerminateSignalHandler* fQuitSignalHandler = new TerminateSignalHandler(this, kSigQuit); - TerminateSignalHandler* fInterruptSignalHandler = new TerminateSignalHandler(this, kSigInterrupt); + fQuitSignalHandler = new TerminateSignalHandler(this, kSigQuit); + fInterruptSignalHandler = new TerminateSignalHandler(this, kSigInterrupt); gSystem->AddSignalHandler(fQuitSignalHandler); gSystem->AddSignalHandler(fInterruptSignalHandler); @@ -202,6 +206,24 @@ void AliShuttleTrigger::Terminate() { fCondition.Signal(); } +//______________________________________________________________________________________________ +void AliShuttleTrigger::CheckTerminate() +{ + // + // Checks if the Shuttle got an external terminate request by a created file + // This is an alternative to the signal which causes problems with the API libraries + // + + if (strlen(fConfig->GetTerminateFilePath()) == 0) + return; + + if (gSystem->AccessPathName(fConfig->GetTerminateFilePath()) == kFALSE) + { + AliInfo("Terminate file exists. Terminating Shuttle..."); + fTerminate = kTRUE; + } +} + //______________________________________________________________________________________________ void AliShuttleTrigger::Run() { // @@ -212,7 +234,7 @@ void AliShuttleTrigger::Run() { fTerminate = kFALSE; - DATENotifier* notifier = new DATENotifier(this, "/DATE/LOGBOOK/UPDATE"); + DATENotifier* notifier = new DATENotifier(this, "/LOGBOOK/SUBSCRIBE/ECS_EOR"); Int_t nTry=0; Int_t nMaxTry = fConfig->GetMaxRetries()+1; @@ -226,6 +248,7 @@ void AliShuttleTrigger::Run() { while (!(fNotified || fTerminate)) { received=fCondition.TimedWaitRelative(1000*fConfig->GetTriggerWait()); + CheckTerminate(); if (received==1) break; // 1 = timeout } @@ -264,6 +287,7 @@ void AliShuttleTrigger::Run() { } Collect(); + CheckTerminate(); } delete notifier; @@ -277,5 +301,119 @@ Bool_t AliShuttleTrigger::Collect(Int_t run) // then it checks if the shuttle is still running by checking the monitoring functions of the shuttle // - return fShuttle->Collect(run); + // first checking disk space + Long_t id = 0; + Long_t bsize = 0; + Long_t blocks = 0; + Long_t bfree = 0; + + gSystem->GetFsInfo(fConfig->GetShuttleFileSystem(), &id, &bsize, &blocks, &bfree); + + AliInfo(Form("n. of free blocks = %ld, total n. of blocks = %ld",bfree,blocks)); + Int_t spaceFree = (Int_t)(((Float_t)bfree/(Float_t)blocks)*100); + + if (spaceFree < fConfig->GetFreeDiskWarningThreshold()) { + AliWarning(Form("************** Free space left = %d%%, below the Warning Threshold (%d%%)",spaceFree,fConfig->GetFreeDiskWarningThreshold())); + if (TMath::Abs(time(0) - fLastMailDiskSpace) >= 86400){ // 86400 = n. of seconds in 1 d + SendMailDiskSpace(fConfig->GetFreeDiskWarningThreshold()); + fLastMailDiskSpace = time(0); // resetting fLastMailDiskSpace to time(0) = now + } + if (spaceFree < fConfig->GetFreeDiskFatalThreshold()){ + AliError(Form("*************** Free space left = %d%%, below the Fatal Threshold (%d%%), terminating....",spaceFree,fConfig->GetFreeDiskFatalThreshold())); + SendMailDiskSpace(fConfig->GetFreeDiskFatalThreshold()); + fTerminate = kTRUE; // terminating.... + } + } + + if (fTerminate) { + return kFALSE; + } + + return fShuttle->Collect(run); +} +//______________________________________________________________________________________________ +Bool_t AliShuttleTrigger::SendMailDiskSpace(Short_t percentage) +{ + // + // sends a mail to the shuttle experts in case of free disk space < theshold + // + + + AliInfo("******************* Sending the Mail!! *********************"); + if (!fConfig->SendMail()) + return kTRUE; + + Int_t runMode = (Int_t)fConfig->GetRunMode(); + TString tmpStr; + if (runMode == 0) tmpStr = " Nightly Test:"; + else tmpStr = " Data Taking:"; + void* dir = gSystem->OpenDirectory(fShuttle->GetShuttleLogDir()); + if (dir == NULL) + { + if (gSystem->mkdir(fShuttle->GetShuttleLogDir(), kTRUE)) + { + AliWarning(Form("SendMail - Can't open directory <%s>", fShuttle->GetShuttleLogDir())); + return kFALSE; + } + + } else { + gSystem->FreeDirectory(dir); + } + + // SHUTTLE responsibles in to + TString to=""; + TIter iterAdmins(fConfig->GetAdmins(AliShuttleConfig::kGlobal)); + TObjString *anAdmin=0; + while ((anAdmin = (TObjString*) iterAdmins.Next())) + { + to += Form("%s,", anAdmin->GetName()); + } + if (to.Length() > 0) + to.Remove(to.Length()-1); + AliDebug(2, Form("to: %s",to.Data())); + + // mail body + TString bodyFileName; + bodyFileName.Form("%s/mail.body", fShuttle->GetShuttleLogDir()); + gSystem->ExpandPathName(bodyFileName); + + ofstream mailBody; + mailBody.open(bodyFileName, ofstream::out); + + if (!mailBody.is_open()) + { + AliWarning(Form("Could not open mail body file %s", bodyFileName.Data())); + return kFALSE; + } + + TString subject; + TString body; + + Int_t percentage_used = 100 - percentage; + subject = Form("%s CRITICAL Disk Space usage exceeds %d%c!", + tmpStr.Data(),percentage_used,'%'); + AliDebug(2, Form("subject: %s", subject.Data())); + + body = "Dear SHUTTLE experts, \n\n"; + body += "The usage of the disk space on the shuttle machine has overcome \n"; + body += Form("the threshold of %d%%. \n \n",percentage_used); + body += "Please check! \n \n"; + body += "Please do not answer this message directly, it is automatically generated.\n\n"; + body += "Greetings,\n\n \t\t\tthe SHUTTLE\n"; + + AliDebug(2, Form("Body : %s", body.Data())); + + mailBody << body.Data(); + mailBody.close(); + + // send mail! + TString mailCommand = Form("mail -s \"%s\" %s < %s", + subject.Data(), + to.Data(), + bodyFileName.Data()); + AliDebug(2, Form("mail command: %s", mailCommand.Data())); + + Bool_t result = gSystem->Exec(mailCommand.Data()); + + return result == 0; }