Commit 649686e9 authored by Jon Pugh's avatar Jon Pugh

Fix restartService method to use getProperty and throw an exception if restart...

Fix restartService method to use getProperty and throw an exception if restart command is missing. Use try catch and $this->provider->shell_exec() to run the command so we don't have to worry about what directory or output. Add a setProperty() method to Services so we can easily override them.
parent abeb15ad
......@@ -137,22 +137,18 @@ class Service implements BuilderAwareInterface
* @return bool
*/
protected function restartService() {
if (empty($this->properties['restart_command'])) {
return TRUE;
if (empty($this->getProperty('restart_command'))) {
throw new \Exception('Unable to restart service: There is no restart_command specified.');
}
else {
$task = $this->getProvision()->getTasks()->taskExec($this->getProperty('restart_command'))
->silent(!$this->getProvision()->getOutput()->isVerbose())
;
/** @var \Robo\Result $result */
$result = $task->run();
if (!$result->wasSuccessful()) {
throw new \Exception('Unable to restart service using command: ' . $this->getProperty('restart_command'));
}
else {
try {
$this->provider->shell_exec($this->getProperty('restart_command'));
return TRUE;
}
catch (\Exception $e) {
throw new \Exception('Unable to restart service: ' . $e->getMessage());
}
}
}
......@@ -263,7 +259,18 @@ class Service implements BuilderAwareInterface
throw new \Exception("Property '$name' on service '$this->type' does not exist.");
}
}
/**
* Set a specific property.
*
* @param $name
* @return mixed
* @throws \Exception
*/
public function setProperty($name, $value) {
$this->properties[$name] = $value;
}
/**
* Return the SERVICE_TYPE
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment