| @@ 68-85 (lines=18) @@ | ||
| 65 | */ |
|
| 66 | class ExpectsSupervisor extends HostAwareModule |
|
| 67 | { |
|
| 68 | public function programIsRunning($programName) |
|
| 69 | { |
|
| 70 | // what are we doing? |
|
| 71 | $log = Log::usingLog()->startAction("make sure program '{$programName}' is running on host '{$this->args[0]}'"); |
|
| 72 | ||
| 73 | // make sure we have valid host details |
|
| 74 | $hostDetails = $this->getHostDetails(); |
|
| 75 | ||
| 76 | // is it running? |
|
| 77 | $running = Supervisor::fromSupervisor($hostDetails->hostId)->getProgramIsRunning($programName); |
|
| 78 | if (!$running) { |
|
| 79 | $log->endAction(); |
|
| 80 | throw Exceptions::newExpectFailedException(__METHOD__, 'program is running', 'program is not running'); |
|
| 81 | } |
|
| 82 | ||
| 83 | // all done |
|
| 84 | $log->endAction(); |
|
| 85 | } |
|
| 86 | ||
| 87 | public function programIsNotRunning($programName) |
|
| 88 | { |
|
| @@ 87-104 (lines=18) @@ | ||
| 84 | $log->endAction(); |
|
| 85 | } |
|
| 86 | ||
| 87 | public function programIsNotRunning($programName) |
|
| 88 | { |
|
| 89 | // what are we doing? |
|
| 90 | $log = Log::usingLog()->startAction("make sure program '{$programName}' is not running on host '{$this->args[0]}'"); |
|
| 91 | ||
| 92 | // make sure we have valid host details |
|
| 93 | $hostDetails = $this->getHostDetails(); |
|
| 94 | ||
| 95 | // is it running? |
|
| 96 | $running = Supervisor::fromSupervisor($hostDetails->hostId)->getProgramIsRunning($programName); |
|
| 97 | if ($running) { |
|
| 98 | $log->endAction(); |
|
| 99 | throw Exceptions::newExpectFailedException(__METHOD__, 'program is not running', 'program is running'); |
|
| 100 | } |
|
| 101 | ||
| 102 | // all done |
|
| 103 | $log->endAction(); |
|
| 104 | } |
|
| 105 | } |
|
| 106 | ||
| @@ 69-88 (lines=20) @@ | ||
| 66 | */ |
|
| 67 | class UsingSupervisor extends HostAwareModule |
|
| 68 | { |
|
| 69 | public function startProgram($programName) |
|
| 70 | { |
|
| 71 | // what are we doing? |
|
| 72 | $log = Log::usingLog()->startAction("start program '{$programName}' on host '{$this->args[0]}'"); |
|
| 73 | ||
| 74 | // get the host details |
|
| 75 | $hostDetails = $this->getHostDetails(); |
|
| 76 | ||
| 77 | // start the program |
|
| 78 | $result = Host::onHost($hostDetails->hostId)->runCommand("sudo supervisorctl start '{$programName}'"); |
|
| 79 | ||
| 80 | // did the command succeed? |
|
| 81 | if ($result->didCommandFail()) { |
|
| 82 | throw Exceptions::newActionFailedException(__METHOD__, "failed to start process '{$programName} (via supervisord)'"); |
|
| 83 | } |
|
| 84 | ||
| 85 | // all done |
|
| 86 | $log->endAction(); |
|
| 87 | return true; |
|
| 88 | } |
|
| 89 | ||
| 90 | public function stopProgram($programName) |
|
| 91 | { |
|
| @@ 90-109 (lines=20) @@ | ||
| 87 | return true; |
|
| 88 | } |
|
| 89 | ||
| 90 | public function stopProgram($programName) |
|
| 91 | { |
|
| 92 | // what are we doing? |
|
| 93 | $log = Log::usingLog()->startAction("stop program '{$programName}' on host '{$this->args[0]}'"); |
|
| 94 | ||
| 95 | // get the host details |
|
| 96 | $hostDetails = $this->getHostDetails(); |
|
| 97 | ||
| 98 | // stop the program |
|
| 99 | $result = Host::onHost($hostDetails->hostId)->runCommand("sudo supervisorctl stop '{$programName}'"); |
|
| 100 | ||
| 101 | // did the command succeed? |
|
| 102 | if ($result->didCommandFail()) { |
|
| 103 | throw Exceptions::newActionFailedException(__METHOD__, "failed to start process '{$programName} (via supervisord)'"); |
|
| 104 | } |
|
| 105 | ||
| 106 | // all done |
|
| 107 | $log->endAction(); |
|
| 108 | return true; |
|
| 109 | } |
|
| 110 | } |
|
| 111 | ||