/** * Goes through the current running processes on the machine, and checks if $this->originalPid is part of the list * @return bool true if $this->originalPid is found in the process list; otherwise false * @throws CommandException */ private function doesPidExistInRunningProcessesList() { $psCmd = 'ps -ef'; $shellCmd = $this->shell->command($psCmd); $cmdResult = $shellCmd->getResult(); if ($cmdResult->wasOk()) { $processList = $cmdResult->getOutput(); } else { throw new CommandException("Command '{$psCmd}' did not run successfully, and exited with status code " . $cmdResult->getStatusCode()); } foreach ($processList as $process) { /* Split the process data into individualized components. * * Example Process: * UID PID PPID C STIME TTY TIME CMD * root 1 0 0 2014 ? 00:03:58 /sbin/init */ $processData = preg_split('/\\s+/', trim($process)); $currentPid = $processData[1]; $returnVal = preg_match('/\\b(' . $this->originalPid . ')\\b/', $currentPid); if ($returnVal == 1) { $this->logger->debug("Found process with pid: {$this->originalPid} in running processes list."); return true; } } $this->logger->debug("Did not find process with pid: {$this->originalPid} in running processes list."); return false; }
/** * Update server info */ public function update_server_info() { $cmd = $this->shell->command("{$this->git} update-server-info -f"); try { $cmd->run(); } catch (CommandException $e) { throw new GitException('Unable to update server info. ' . $e->getMessage()); } }
public function testShellAliasMethod() { $shell = new Shell(); $cActual = $shell->command('echo %s %s %d', 'hello', 'world', 42); $safeActual = self::getSafeCommandFrom($cActual); $safeExpected = Command::makeSafeString('echo %s %s %d', array('hello', 'world', 42)); $this->assertEquals($safeExpected, $safeActual, 'safe commands'); }