| @@ 65-82 (lines=18) @@ | ||
| 62 | */ |
|
| 63 | class ExpectsSupervisor extends HostBase |
|
| 64 | { |
|
| 65 | public function programIsRunning($programName) |
|
| 66 | { |
|
| 67 | // what are we doing? |
|
| 68 | $log = usingLog()->startAction("make sure program '{$programName}' is running on host '{$this->args[0]}'"); |
|
| 69 | ||
| 70 | // make sure we have valid host details |
|
| 71 | $hostDetails = $this->getHostDetails(); |
|
| 72 | ||
| 73 | // is it running? |
|
| 74 | $running = fromSupervisor($hostDetails->hostId)->getProgramIsRunning($programName); |
|
| 75 | if (!$running) { |
|
| 76 | $log->endAction(); |
|
| 77 | throw Exceptions::newExpectFailedException(__METHOD__, 'program is running', 'program is not running'); |
|
| 78 | } |
|
| 79 | ||
| 80 | // all done |
|
| 81 | $log->endAction(); |
|
| 82 | } |
|
| 83 | ||
| 84 | public function programIsNotRunning($programName) |
|
| 85 | { |
|
| @@ 84-101 (lines=18) @@ | ||
| 81 | $log->endAction(); |
|
| 82 | } |
|
| 83 | ||
| 84 | public function programIsNotRunning($programName) |
|
| 85 | { |
|
| 86 | // what are we doing? |
|
| 87 | $log = usingLog()->startAction("make sure program '{$programName}' is not running on host '{$this->args[0]}'"); |
|
| 88 | ||
| 89 | // make sure we have valid host details |
|
| 90 | $hostDetails = $this->getHostDetails(); |
|
| 91 | ||
| 92 | // is it running? |
|
| 93 | $running = fromSupervisor($hostDetails->hostId)->getProgramIsRunning($programName); |
|
| 94 | if ($running) { |
|
| 95 | $log->endAction(); |
|
| 96 | throw Exceptions::newExpectFailedException(__METHOD__, 'program is not running', 'program is running'); |
|
| 97 | } |
|
| 98 | ||
| 99 | // all done |
|
| 100 | $log->endAction(); |
|
| 101 | } |
|
| 102 | } |
|
| 103 | ||
| @@ 66-85 (lines=20) @@ | ||
| 63 | */ |
|
| 64 | class UsingSupervisor extends HostBase |
|
| 65 | { |
|
| 66 | public function startProgram($programName) |
|
| 67 | { |
|
| 68 | // what are we doing? |
|
| 69 | $log = usingLog()->startAction("start program '{$programName}' on host '{$this->args[0]}'"); |
|
| 70 | ||
| 71 | // get the host details |
|
| 72 | $hostDetails = $this->getHostDetails(); |
|
| 73 | ||
| 74 | // start the program |
|
| 75 | $result = usingHost($hostDetails->hostId)->runCommand("sudo supervisorctl start '{$programName}'"); |
|
| 76 | ||
| 77 | // did the command succeed? |
|
| 78 | if ($result->didCommandFail()) { |
|
| 79 | throw Exceptions::newActionFailedException(__METHOD__, "failed to start process '{$programName} (via supervisord)'"); |
|
| 80 | } |
|
| 81 | ||
| 82 | // all done |
|
| 83 | $log->endAction(); |
|
| 84 | return true; |
|
| 85 | } |
|
| 86 | ||
| 87 | public function stopProgram($programName) |
|
| 88 | { |
|
| @@ 87-106 (lines=20) @@ | ||
| 84 | return true; |
|
| 85 | } |
|
| 86 | ||
| 87 | public function stopProgram($programName) |
|
| 88 | { |
|
| 89 | // what are we doing? |
|
| 90 | $log = usingLog()->startAction("stop program '{$programName}' on host '{$this->args[0]}'"); |
|
| 91 | ||
| 92 | // get the host details |
|
| 93 | $hostDetails = $this->getHostDetails(); |
|
| 94 | ||
| 95 | // stop the program |
|
| 96 | $result = usingHost($hostDetails->hostId)->runCommand("sudo supervisorctl stop '{$programName}'"); |
|
| 97 | ||
| 98 | // did the command succeed? |
|
| 99 | if ($result->didCommandFail()) { |
|
| 100 | throw Exceptions::newActionFailedException(__METHOD__, "failed to start process '{$programName} (via supervisord)'"); |
|
| 101 | } |
|
| 102 | ||
| 103 | // all done |
|
| 104 | $log->endAction(); |
|
| 105 | return true; |
|
| 106 | } |
|
| 107 | } |
|
| 108 | ||
| @@ 99-116 (lines=18) @@ | ||
| 96 | $log->endAction(); |
|
| 97 | } |
|
| 98 | ||
| 99 | public function packageIsInstalled($packageName) |
|
| 100 | { |
|
| 101 | // what are we doing? |
|
| 102 | $log = usingLog()->startAction("make sure package '{$packageName}' is installed on host '{$this->args[0]}'"); |
|
| 103 | ||
| 104 | // make sure we have valid host details |
|
| 105 | $hostDetails = $this->getHostDetails(); |
|
| 106 | ||
| 107 | // is it installed? |
|
| 108 | $details = fromHost($hostDetails->hostId)->getInstalledPackageDetails($packageName); |
|
| 109 | if (!isset($details->version)) { |
|
| 110 | $log->endAction(); |
|
| 111 | throw Exceptions::newExpectFailedException(__METHOD__, "package installed", "package is not installed"); |
|
| 112 | } |
|
| 113 | ||
| 114 | // all done |
|
| 115 | $log->endAction(); |
|
| 116 | } |
|
| 117 | ||
| 118 | public function packageIsNotInstalled($packageName) |
|
| 119 | { |
|
| @@ 118-136 (lines=19) @@ | ||
| 115 | $log->endAction(); |
|
| 116 | } |
|
| 117 | ||
| 118 | public function packageIsNotInstalled($packageName) |
|
| 119 | { |
|
| 120 | // what are we doing? |
|
| 121 | $log = usingLog()->startAction("make sure package '{$packageName}' is not installed on host '{$this->args[0]}'"); |
|
| 122 | ||
| 123 | // make sure we have valid host details |
|
| 124 | $hostDetails = $this->getHostDetails(); |
|
| 125 | ||
| 126 | // is it installed? |
|
| 127 | $details = fromHost($hostDetails->hostId)->getInstalledPackageDetails($packageName); |
|
| 128 | ||
| 129 | if (isset($details->version)) { |
|
| 130 | $log->endAction(); |
|
| 131 | throw Exceptions::newExpectFailedException(__METHOD__, "package not installed", "package is installed"); |
|
| 132 | } |
|
| 133 | ||
| 134 | // all done |
|
| 135 | $log->endAction(); |
|
| 136 | } |
|
| 137 | ||
| 138 | public function processIsRunning($processName) |
|
| 139 | { |
|