Ejemplo n.º 1
0
/**
 * Executes locally a file
 * 
 * @param type $workdir the working directory
 * @param type $script_path the script file, with path relative to the study_dir
 */
function execute_script_local($workdir, $cmd, $study, $jobid)
{
    include 'config.inc.php';
    if (chdir($workdir)) {
        $outfile = get_absolute_path(get_job_output_file($study, $jobid));
        # things that are needed to proc_open, see http://it2.php.net/manual/en/function.proc-open.php
        $pipes = 0;
        $descriptors = array(0 => array('pipe', 'r'), 1 => array('file', $outfile, 'a'), 2 => array('file', $outfile, 'a'));
        $env = array();
        $env["HOME"] = get_local_exec_dir(OC_User::getUser());
        $env["PATH"] = $_SERVER["PATH"];
        # use a UNIX command to get the current user name
        $env["USER"] = exec("whoami");
        chmod($cmd, 0755);
        $cmd = str_replace(" ", "\\ ", $cmd);
        $ph = proc_open($cmd . " &", $descriptors, $pipes, $workdir, $env);
        if ($ph) {
            /**
             * @var $status array
             */
            $status = proc_get_status($ph);
            $pid = $status["pid"];
            proc_close($ph);
            //
            // UGLY HACK , I increase the PID returned by proc_get_status by 1
            // why ? because proc_open() spawns a process /bin/sh, that in turn launches our script.
            // the full command is /bin/sh -c $command $args
            // Our process is the direct child of such shell process.
            // The $pid returned above is the PID of the shell process, not the script launched by that shell.
            //
            // Since in Unix the child process is always parent_pid + 1, it's mostly safe to increment that value by 1
            // to obtain the real PID
            //
            if ($pid) {
                $pid = (int) $pid + 1;
                $jobinfo = array("jobid" => $jobid, "pid" => $pid, "start_date" => date("Y-m-d H:i:s"), "script" => $cmd, "exec_dir" => $workdir, "exec_type" => "local");
                save_job_info($study, $jobid, $jobinfo);
                // TODO: here we should check if the job is effectively running with that PID
            }
            return $pid;
        }
        return false;
    } else {
        return false;
    }
}
Ejemplo n.º 2
0
if (!OC_User::isLoggedIn()) {
    exit;
}
$job = $_GET['jobid'];
$file = $_GET['study'];
$outputid = $_GET['outputid'];
$rowid = $_GET['rowid'];
# check if we have to print the <tr> elements (we do not print them if this file is called from a AJAX call
if (isset($_GET["print_tr"])) {
    $print_tr = $_GET["print_tr"];
} else {
    $print_tr = true;
    // default true
}
$filelink = OC_Helper::linkTo('files', '', array("dir" => "{$file}/results/{$job}"));
$output_file = get_job_output_file($file, $job);
$jobinfo = get_job_info($file, $job);
// obtain the precedent status
$precstatus = isset($jobinfo['status']) ? $jobinfo['status'] : JobStatus::$RUNNING;
$qsub_jobname = $jobinfo["qsub_jobname"];
// obtain the current status (potentially slow operation, calls ssh/qstat)
$status = get_job_status($jobinfo);
$sgequeued = 0;
$sgerunning = 0;
if ($status == JobStatus::$FINISHED || $status === JobStatus::$KILLED) {
    if ($precstatus !== $status) {
        $jobinfo['status'] = $status;
        // get_job_status returned FINISHED or KILLED, we save that info in the job JSON
        save_job_info($file, $job, $jobinfo);
    }
    if (!isset($jobinfo["usedspace"])) {