fixed bot retire\add all

This commit is contained in:
tom-orrow 2011-04-05 00:59:50 +04:00
parent fcdaf458cd
commit 134873e50c

View File

@ -8,6 +8,7 @@ $bots = array();
foreach ($tmp as $bfile) { foreach ($tmp as $bfile) {
$bots[str_replace('.json', '', $bfile)] = json_decode(file_get_contents(Config::get('app:Parser:bot_stats_dir').$bfile)); $bots[str_replace('.json', '', $bfile)] = json_decode(file_get_contents(Config::get('app:Parser:bot_stats_dir').$bfile));
} }
foreach ($bots as $name => $bot) { foreach ($bots as $name => $bot) {
$tmp = exec("ps ".$bot->pid); $tmp = exec("ps ".$bot->pid);
$bot->active = (int) (strpos($tmp, strval($bot->pid)) !== false); $bot->active = (int) (strpos($tmp, strval($bot->pid)) !== false);
@ -35,22 +36,17 @@ switch ($argv[1]) {
if (!$bot->active) { if (!$bot->active) {
echo "Launching ". $name ."\n"; echo "Launching ". $name ."\n";
shell_exec(ROOT_DIR ."/bin/parser/worker_html_grabber.php ". $name ." > /www/parser_data/log/". $name .".log &"); shell_exec(ROOT_DIR ."/bin/parser/worker_html_grabber.php ". $name ." > /www/parser_data/log/". $name .".log &");
die; if ($bot_name != 'All') {
die;
}
} }
} }
echo "All bots are working already\n"; echo "All bots are working.\n";
} }
break; break;
case 'retire': case 'retire':
$bot_name = (isset($argv[2]) ? ucfirst($argv[2]) : false); $bot_name = (isset($argv[2]) ? ucfirst($argv[2]) : false);
if ($bot_name == 'all') { if ($bot_name && isset($bots[$bot_name])) {
foreach ($bots as $name => $bot) {
if ($bot->active) {
echo "Stopping ". $name ."\n";
shell_exec("kill ". $bot->pid);
}
}
} elseif ($bot_name && isset($bots[$bot_name])) {
$bot = $bots[$bot_name]; $bot = $bots[$bot_name];
if(!$bot->active) { if(!$bot->active) {
echo $bot_name ." is not working now\n"; echo $bot_name ." is not working now\n";
@ -64,10 +60,12 @@ switch ($argv[1]) {
if ($bot->active) { if ($bot->active) {
echo "Stopping ". $name ."\n"; echo "Stopping ". $name ."\n";
shell_exec("kill ". $bot->pid); shell_exec("kill ". $bot->pid);
die; if ($bot_name != 'All') {
die;
}
} }
} }
echo "All bots are working already\n"; echo "All bots are stopped.\n";
} }
break; break;
case 'list': case 'list':