public static function ensureBrokerRunning()
{
$client = (new Client(\Scalr::config('scalr.crontab.sockets.broker')))->setTimeout(100)->setRetries(1)->setLogger(\Scalr::getContainer()->logger('Mdp\\Client')->setLevel(\Scalr::config('scalr.crontab.log_level')))->connect();
$mmiReq = new Zmsg();
$mmiReq->push("system.healthcheck");
$mmiRep = $client->send("mmi.service", $mmiReq);
if ($mmiRep) {
$ok = $mmiRep->pop();
} else {
$ok = false;
//Make sure another broker process isn't hanging
self::terminateBroker();
//Broker has to be started in the separate process
$op = [];
$logFile = \Scalr::config('scalr.crontab.log');
exec(self::getStartBrokerCommand() . ' ' . ($logFile == '/dev/null' ? '> ' : '>> ') . escapeshellcmd($logFile) . ' 2>&1 & echo $!', $op);
$pid = intval($op[0]);
}
return $ok;
}