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; }
error_log("jobrun 8\n", 3, "/tmp/php_errors"); $zmq_socket->connect("tcp://" . $json->messaging->zmqhostip . ":" . $json->messaging->zmqport); error_log("jobrun 9\n", 3, "/tmp/php_errors"); logjobupdate("running"); error_log("jobrun 10\n", 3, "/tmp/php_errors"); $zmq_socket->send('{"_uuid":"' . $id . '","_status":"running"}'); error_log("jobrun 11\n", 3, "/tmp/php_errors"); logrunning(); error_log("jobrun 12\n", 3, "/tmp/php_errors"); $results = exec($cmd); error_log("{$cmd}\n", 3, "/tmp/php_errors"); error_log("{$results}\n", 3, "/tmp/php_errors"); // logjobupdate("finished", true); error_log("jobrun 14\n", 3, "/tmp/php_errors"); logstoprunning(); error_log("jobrun 15\n", 3, "/tmp/php_errors"); if (!$GLOBALS['wascancelled']) { $results = str_replace("/var/www/html/abhishektest/", "", $results); ob_start(); if (FALSE === file_put_contents("{$logdir}_stdout_" . $_REQUEST['_uuid'], $results)) { $cont = ob_get_contents(); error_log(date("Y M d H:i:s T", time()) . " : " . $argv[0] . " : error writing _stdout results\n", 3, "/tmp/php_errors"); } ob_end_clean(); } if ($checkrunning == 1) { if (!clearprojectlock($GLOBALS['getmenumoduledir'])) { // error ignored since there may not be job control // error_log( date( "Y M d H:i:s T", time() ) . " : " . $argv[ 0 ] . " : " . $GLOBALS[ 'getmenumoduledir' ] . " : error clearprojectlock " . $GLOBALS[ 'lasterror' ] . "\n", 3, "/tmp/php_errors" ); }