execute.cc (1116B)
1 #include "checkupthread" 2 3 void Checkupthread::execute() { 4 5 Threadlist::desc("Checkup thread"); 6 7 while (1) { 8 if (config.checkupsec()) { 9 msg("Running checkup thread\n"); 10 for (unsigned i = 0; i < balancer.nbackends(); i++) { 11 Backend target(balancer.backend(i).backenddef()); 12 try { 13 target.check(); 14 if (target.live()) { 15 balancer.backend(i).live(true); 16 msg("Checkup call: backend " << target.description() 17 << " is alive\n"); 18 } else { 19 balancer.backend(i).live(false); 20 balancer.backend(i).markconnecterror(); 21 msg("Checkup call: backend " << target.description() 22 << " is unavailable\n"); 23 if (config.onfail().length()) { 24 ostringstream o; 25 o << config.onfail() << " 0.0.0.0 " 26 << target.description() << ' ' 27 << balancer.backend(i).connections(); 28 sysrun(o.str()); 29 } 30 } 31 } catch (Error &e) { 32 debugmsg("Error in checkup thread: " << e.what() << 33 '\n'); 34 } catch (...) { 35 debugmsg("Error in checkup thread\n"); 36 } 37 } 38 sleep(config.checkupsec()); 39 } else 40 sleep(30); 41 } 42 } 43