$bots = $db->getActiveBotList(); $botCount = 0; if ($bots) { exec('ps -e | grep php', $output); $pidList = []; foreach ($output as $line) { $data = explode(' ', trim(preg_replace('/[ ]+/', ' ', $line))); if ($data[3] === 'php') { $pidList[] = $data[0]; } } foreach ($bots as $bot) { if (in_array($bot['pid'], $pidList, true) === true) { $botCount++; Cerberus::sysinfo('Bot ' . $bot['id'] . ' is running. PID: ' . $bot['pid']); } else { $db->cleanupBot($bot['id']); $db->shutdownBot($bot['id']); Cerberus::sysinfo('Bot ' . $bot['id'] . ' is not running.'); } } } if ($botCount === 0) { Cerberus::sysinfo('start a new bot.'); $logDirectory = rtrim(trim($config['log']['directory']), '/'); if (is_dir($logDirectory) === false) { mkdir($logDirectory); } exec(Cerberus::getPath() . '/bin/bot.php -noconsole > ' . $logDirectory . '/log.txt 2>&1 &'); } }