From ae59a28181a64fca7699ddc607697682e2bfecd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20L=C3=B3pez?= Date: Sat, 1 Oct 2011 23:12:52 -0400 Subject: [PATCH] add restart command and restart after adding/removing vhosts --- feather.drush.inc | 32 ++++++++++++++++++++++++++------ includes/conf-file.inc | 6 ++++++ includes/server.inc | 11 ++++++++--- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/feather.drush.inc b/feather.drush.inc index 8b71e03..c0f4400 100644 --- a/feather.drush.inc +++ b/feather.drush.inc @@ -32,6 +32,10 @@ function feather_drush_command() { 'description' => 'Stop the web server.', 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, ); + $items['feather-restart'] = array( + 'description' => 'Restart the web server.', + 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, + ); $items['feather-status'] = array( 'description' => 'Display the current status (running/not running) of the server.', 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, @@ -117,6 +121,19 @@ function drush_feather_stop() { } } +/** + * Command callback for `drush feather-restart`. + */ +function drush_feather_restart() { + $server = feather_get_server(); + + $server->stop(); + while ($server->is_running()) { + sleep(1); + } + $server->start(); +} + /** * Command callback for `drush feather-status`. */ @@ -222,8 +239,8 @@ function drush_feather_add($alias = NULL) { drush_log("[Added] {$vhost->name} -> {$vhost->doc_root}", 'ok'); if ($server->is_running()) { - $server->stop(); - $server->start(); + drush_feather_restart(); + drush_log('Server restarted.', 'ok'); } } @@ -264,7 +281,7 @@ function drush_feather_remove($alias = NULL) { $options[$name] = $vhost->uri; } - $choice = drush_choice($options, 'Choose a virtual host configuration to delete'); + $choice = drush_choice($options, 'Choose a virtual host configuration to delete:'); // Cancelled. if (empty($choice)) { @@ -274,9 +291,12 @@ function drush_feather_remove($alias = NULL) { $vhost = $vhosts[$choice]; } - if ($vhost->exists()) { - $vhost->delete(); - drush_log(dt('!host:!port removed.', array('!host' => $vhost->host, '!port' => $vhost->port)), 'ok'); + $vhost->delete(); + drush_log(dt('!host:!port removed.', array('!host' => $vhost->host, '!port' => $vhost->port)), 'ok'); + + if ($server->is_running()) { + drush_feather_restart(); + drush_log('Server restarted.', 'ok'); } } diff --git a/includes/conf-file.inc b/includes/conf-file.inc index 5acde9f..f1c22c1 100644 --- a/includes/conf-file.inc +++ b/includes/conf-file.inc @@ -170,4 +170,10 @@ class FeatherVhostConfFile extends FeatherConfFile { $httpd_conf = feather_get_conf_file(); $httpd_conf->save(); } + + public function delete() { + parent::delete(); + $httpd_conf = feather_get_conf_file(); + $httpd_conf->save(); + } } diff --git a/includes/server.inc b/includes/server.inc index 4c90a53..e55dd5d 100644 --- a/includes/server.inc +++ b/includes/server.inc @@ -93,9 +93,14 @@ class FeatherServer { return FALSE; } - $vhost = reset($vhosts); - $url = "http://{$vhost->host}:{$vhost->port}/server-status?auto"; - return drush_shell_exec("curl -s %s", $url); + foreach ($vhosts as $vhost) { + $url = "http://{$vhost->host}:{$vhost->port}/server-status?auto"; + $running = drush_shell_exec("curl -s %s", $url); + if ($running) { + return TRUE; + } + } + return FALSE; } public function get_vhosts() {