// error_log( "\taltcmd:\n$altcmd\n", 3, "/tmp/mylog" ); error_log("base.php exec nohup jobrun\n", 3, "/tmp/php_errors"); exec($altcmd); if (isset($results["_fs_clear"])) { $fsc = $results["_fs_clear"]; $results = '{"_status":"started","_fs_clear":"' . $fsc . '"}'; } else { $results = '{"_status":"started"}'; } if ($do_logoff == 1) { $results = substr(trim($results), 0, -1) . ",\"_login\":\"\"}"; } echo $results; exit; $results = exec($cmd); logjobupdate("finished", true); $results = str_replace("/var/www/html/abhishektest/", "", $results); if ($do_logoff == 1) { $results = substr(trim($results), 0, -1) + ",\"_login\":\"\"}"; } ob_start(); file_put_contents("{$logdir}/_stdout_" . $_REQUEST['_uuid'], $results); ob_end_clean(); ob_start(); $test_json = json_decode($results); if ($test_json == NULL) { $cont = ob_get_contents(); ob_end_clean(); if (isset($checkrunning)) { try { $coll->remove(array("name" => $checkrunning), array("justOne" => true));
function jobcancel($jobs, $error_json_exit = false) { $GLOBALS['lasterror'] = ""; $GLOBALS['lastnotice'] = ""; global $use_db; global $db_errors; $appconfig = json_decode(file_get_contents("/home/abhishek/Desktop/GenApp/abhishektest/appconfig.json"), true); if (!isset($appconfig['resources'])) { $GLOBALS['lasterror'] = "Internal error: could not find resource configuration information in appconfig.json"; require_once "mail.php"; error_mail("[joblog.php jobcancel()] " . $GLOBALS['lasterror']); return false; } if (!db_connect($error_json_exit)) { $GLOBALS['lasterror'] = $db_errors; return false; } $context = new ZMQContext(); $zmq_socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'abhishektest udp pusher'); $zmq_socket->connect("tcp://" . $appconfig['messaging']['zmqhostip'] . ":" . $appconfig['messaging']['zmqport']); // $udp_socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); $runs = $use_db->abhishektest->running->find(array("_id" => array('$in' => $jobs))); $fjobs = array_flip($jobs); $projectdirs = array(); $tokillparent = array(); $tokill = array(); $kjobs = array(); foreach ($runs as $v) { $uuid = $v['_id']; $job = $use_db->abhishektest->jobs->findOne(array("_id" => $uuid)); $pids = $v['pid']; foreach ($pids as $k2 => $v2) { if ($v2['pid'] < 2) { require_once "mail.php"; error_mail("[joblog.php jobcancel()] invalid pid for kill! " . $v2['pid']); } else { $where = $v2['where']; if ($v2['what'] == "parent") { if (!isset($tokillparent[$where])) { $tokillparent[$where] = array($v2['pid']); } else { $tokillparent[$where][] = $v2['pid']; } } else { if (!isset($tokill[$where])) { $tokill[$where] = array($v2['pid']); } else { $tokill[$where][] = $v2['pid']; } } } } unset($fjobs[$uuid]); $kjobs[$uuid] = true; // send messages also if running about "cancelled" // also manually clear job locks and push update to jobs as in jobrun.php if (!logjobupdate("cancelled", true, $error_json_exit, $uuid)) { } logstoprunning(); $zmq_socket->send(json_encode(array("_uuid" => $uuid, "Notice" => "This job has been cancelled by user request", "_cancel" => "true", "_status" => "cancelled"))); // $jsonmsg = json_encode( array( "_uuid" => $uuid, // "Notice" => "This job has been cancelled by user request", // "_status" => "cancelled" ) ); // socket_sendto( $udp_socket, $jsonmsg, strlen( $jsonmsg ), 0, $appconfig['messaging'][ 'udphostip' ], $appconfig['messaging']['udpport'] ); if (getprojectdir($uuid)) { $projectdirs[$GLOBALS['getprojectdir']] = true; } } foreach ($tokill as $k => $v) { if (!isset($appconfig['resources'][$k])) { $GLOBALS['lasterror'] .= "Resource {$k} missing from resource configuration information in appconfig.json"; require_once "mail.php"; error_mail("[joblog.php jobcancel()] " . $GLOBALS['lasterror']); } else { $kill = $appconfig['resources'][$k] . " /var/www/html/abhishektest/util/ga_killprocs.pl /var/www/html/abhishektest/log {$k} all " . implode(' ', $v); ob_start(); exec($kill, $execout); ob_end_clean(); } } foreach ($tokillparent as $k => $v) { if (!isset($appconfig['resources'][$k])) { $GLOBALS['lasterror'] .= "Resource {$k} missing from resource configuration information in appconfig.json"; require_once "mail.php"; error_mail("[joblog.php jobcancel()] " . $GLOBALS['lasterror']); } else { $kill = $appconfig['resources'][$k] . " /var/www/html/abhishektest/util/ga_killprocs.pl /var/www/html/abhishektest/log {$k} child " . implode(' ', $v); ob_start(); exec($kill, $execout); ob_end_clean(); } } foreach ($projectdirs as $k => $v) { clearprojectlock($k); } $msgs = count($kjobs) ? "Job id" . (count($kjobs) > 1 ? "s " : " ") . implode(",", array_keys($kjobs)) . " cancelled." : ""; $msgs .= count($fjobs) ? "\nNotice; Job id" . (count($fjobs) > 1 ? "s " : " ") . implode(",", array_keys($fjobs)) . " not running so not cancelled." : ""; $GLOBALS['lastnotice'] = $msgs; return true; }