Skip to content

Commit

Permalink
add restart command and restart after adding/removing vhosts
Browse files Browse the repository at this point in the history
  • Loading branch information
zroger committed Oct 2, 2011
1 parent f33dc0b commit ae59a28
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
32 changes: 26 additions & 6 deletions feather.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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`.
*/
Expand Down Expand Up @@ -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');
}
}

Expand Down Expand Up @@ -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)) {
Expand All @@ -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');
}

}
Expand Down
6 changes: 6 additions & 0 deletions includes/conf-file.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
11 changes: 8 additions & 3 deletions includes/server.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit ae59a28

Please sign in to comment.