Commit 06ca5a01 authored by drumm's avatar drumm Committed by Neil Drumm

Add provisionServer::shell_exec()

parent 4b2ebc70
......@@ -72,33 +72,17 @@ class provisionService_http_apache extends provisionService_http {
$this->parse_configs();
}
function parse_configs($cause_error = FALSE) {
function parse_configs() {
d()->service('file')->sync();
// This is required to be configurable, due to the fact that different
// hosts might need to do this differently.
if (drush_is_local_host($this->remote_host)) {
$return = drush_shell_exec(escapeshellcmd($this->restart_cmd));
}
else {
$return = drush_shell_exec('ssh ' . drush_get_option('ssh-options', '-o PasswordAuthentication=no') . ' %s %s', $this->script_user . '@' . $this->remote_host, escapeshellcmd($this->restart_cmd));
}
if (!$return) {
$msg = join("\n", drush_shell_exec_output());
if ($cause_error) {
return drush_set_error('PROVISION_WEB_RESTART_FAILED', dt("Web server could not be restarted. Changes might not be available until this has been done. (error: %msg)", array("%msg" => $msg)));
}
else {
drush_log(dt("Web server could not be restarted. Changes might not be available until this has been done. (error: %msg)", array("%msg" => $msg)), "warning");
}
if (d()->service('http')->server()->shell_exec($this->restart_cmd)) {
drush_log(dt('Apache has been restarted'));
}
else {
drush_log(dt('Apache has been restarted'));
drush_log(dt('Web server could not be restarted. Changes might not be available until this has been done. (error: %msg)', array('%msg' => join("\n", drush_shell_exec_output()))), 'warning');
}
return $return;
}
}
class provisionConfig_apache extends provisionConfig {
......
......@@ -11,9 +11,7 @@ function drush_http_provision_delete() {
}
else {
provision_service('http')->delete_platform_config();
}
}
return provision_service('http')->parse_configs();
provision_service('http')->parse_configs();
}
......@@ -294,6 +294,25 @@ class provisionServer extends provisionEnvironment {
function verify() {
$this->services_invoke('verify');
}
/**
* Execute $command on this server, using SSH if necessary.
*
* @param $command
* Shell command to execute.
*
* @return
* Same as drush_shell_exec(). Use drush_shell_exec_output() for standard
* out and error.
*/
function shell_exec($command) {
if (drush_is_local_host($this->remote_host)) {
return drush_shell_exec(escapeshellcmd($command));
}
else {
return drush_shell_exec('ssh ' . drush_get_option('ssh-options', '-o PasswordAuthentication=no') . ' %s %s', $this->script_user . '@' . $this->remote_host, escapeshellcmd($command));
}
}
}
/**
......
......@@ -41,6 +41,16 @@ class provisionService {
d($this->server)->setProperty($field, $default);
}
/**
* Find the server environment this service is running on.
*
* @return
* A provisionServer object.
*/
function server() {
return d($this->server);
}
/**
* Clear internal state
*/
......
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