Created
January 9, 2012 21:58
-
-
Save halcyonCorsair/1585181 to your computer and use it in GitHub Desktop.
My slightly ugly reference implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implementation of hook_provision_drupal_create_directories(). | |
* | |
* Make the directory create phase of a site install web cluster ready. | |
* A patch to provision is needed. | |
* @url http://drupal.org/files/issues/provision_drupal_create_directories.patch | |
*/ | |
function mymodule_provision_drupal_create_directories(&$dirs, $url) { | |
$web_group = d('@server_master')->web_group; | |
$path = "sites/$url"; | |
if (!is_dir($path)) { | |
provision_file()->mkdir($path) | |
->succeed('Created <code>@path</code>') | |
->fail('Could not create <code>@path</code>', 'DRUSH_PERM_ERROR'); | |
} | |
provision_file()->chmod($path, $dirs[$path], false) | |
->succeed('Changed permissions of <code>@path</code> to @perm') | |
->fail('Could not change permissions <code>@path</code> to @perm'); | |
unset($dirs[$path]); | |
$dir = '/var/lib/sitedata/aegir/cache'; | |
$link = 'cache'; | |
$path = d()->root . '/' . $link; | |
if (!is_link($path) && !preg_match("/hostmaster/", $path)) { | |
drush_set_error("cache directory $realpath is not a link"); | |
provision_file()->symlink($dir, d()->root . '/' . $link) | |
->succeed('linked <code>@path</code> to <code>@target</code>') | |
->fail('Could not create link to <code>@path</code> from <code>@target</code>', 'DRUSH_PERM_ERROR'); | |
} | |
$symlink = array( | |
"sites/$url/files", | |
"sites/$url/private", | |
); | |
foreach ($symlink as $link) { | |
if (isset($dirs[$link])) { | |
unset($dirs[$link]); | |
} | |
$dir = '/var/lib/sitedata/aegir/' . "$url/" . basename($link); | |
if (!is_dir($dir)) { | |
provision_file()->mkdir($dir) | |
->succeed('Created <code>@path</code>') | |
->fail('Could not create <code>@path</code>', 'DRUSH_PERM_ERROR'); | |
$path = '/var/lib/sitedata/aegir/' . $url; | |
$perm = 0755; | |
provision_file()->chmod($path, $perm, FALSE) | |
->succeed('Changed permissions of <code>@path</code> to @perm') | |
->fail('Could not change permissions <code>@path</code> to @perm'); | |
} | |
if (is_link($link)) { | |
$realpath = realpath($link); | |
if ($realpath == $dir) { | |
$group_id = filegroup($dir); | |
$group_info = posix_getgrgid($group_id); | |
if (!empty($group_info['name']) && $group_info['name'] != $web_group) { | |
provision_file()->chgrp($dir, $web_group, FALSE) | |
->succeed('Changed group ownership of <code>@path</code> to @gid') | |
->fail('Could not change group ownership <code>@path</code> to @gid'); | |
} | |
continue; | |
} | |
else { | |
drush_log(t('Link <code>@link</code> does\'t point to sitedata directory <code>@dir</code>, hopefully fixing now...', array('@link' => $link, '@dir' => $dir)), 'error'); | |
provision_file()->symlink($dir, d()->root . '/' . $link) | |
->succeed('linked <code>@path</code> to <code>@target</code>') | |
->fail('Could not create link to <code>@path</code> from <code>@target</code>', 'DRUSH_PERM_ERROR'); | |
continue; | |
} | |
} | |
// If the directory already exists, then we need to move all the existing | |
// contents into the sitedata directory before we remove it. | |
$realpath = realpath($link); | |
if ($realpath && !is_link($realpath)) { | |
if (!drush_shell_exec('cd %s && tar -c * | tar -x -C %s', $realpath, $dir)) { | |
drush_set_error("Cannot move contents out from $realpath"); | |
drush_set_error(print_r(drush_shell_exec_output(), true)); | |
continue; | |
} | |
// Delete the old <platform>/sites/<site>/<directory> | |
if (!drush_shell_exec('rm -rf %s', $realpath)) { | |
drush_set_error("Cannot rm $realpath"); | |
drush_set_error(print_r(drush_shell_exec_output(), true)); | |
continue; | |
} | |
} | |
// Finally, make the symlink. | |
provision_file()->symlink($dir, d()->root . '/' . $link) | |
->succeed('linked <code>@path</code> to <code>@target</code>') | |
->fail('Could not create link to <code>@path</code> from <code>@target</code>', 'DRUSH_PERM_ERROR'); | |
//provision_file()->chgrp($dir, $web_group, FALSE) | |
provision_file()->chgrp($dir, $web_group, TRUE) | |
->succeed('Changed group ownership of <code>@path</code> to @gid') | |
->fail('Could not change group ownership <code>@path</code> to @gid'); | |
// Ensure correct permissions | |
$perm = 02770; | |
//provision_file()->chmod($dir, $perm, TRUE) | |
provision_file()->chmod($dir, $perm, FALSE) | |
->succeed('Changed permissions of <code>@path</code> to @perm') | |
->fail('Could not change permissions <code>@path</code> to @perm'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/platform/backup.provision.inc b/platform/backup.provision.inc | |
index 6bceb49..e552927 100644 | |
--- a/platform/backup.provision.inc | |
+++ b/platform/backup.provision.inc | |
@@ -87,9 +87,9 @@ function drush_provision_drupal_provision_backup() { | |
} | |
if (substr($backup_file, -2) == 'gz') { | |
// same as above: some do not support -z | |
- $command = "tar cpf - . | gzip -c > %s"; | |
+ $command = "tar hcpf - . | gzip -c > %s"; | |
} else { | |
- $command = "tar cpf %s ."; | |
+ $command = "tar hcpf %s ."; | |
} | |
$result = drush_shell_exec($command, $backup_file); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/platform/deploy.provision.inc b/platform/deploy.provision.inc | |
index aff2d27..b670b88 100644 | |
--- a/platform/deploy.provision.inc | |
+++ b/platform/deploy.provision.inc | |
@@ -74,6 +74,8 @@ function drush_provision_drupal_pre_provision_deploy($backup_file) { | |
// We have already created a new database. Save the info to the config files. | |
provision_prepare_environment(); | |
+ // _provision_drupal_create_directories() is needed here to make sure the files restored from backup are moved to the shared data export and replaced with symlinks | |
+ _provision_drupal_create_directories(); | |
provision_save_site_data(); | |
// Load the newly created information, including re-loading the new db creds. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/platform/provision_drupal.drush.inc b/platform/provision_drupal.drush.inc | |
index 071806e..e4baaff 100644 | |
--- a/platform/provision_drupal.drush.inc | |
+++ b/platform/provision_drupal.drush.inc | |
@@ -237,6 +237,9 @@ function _provision_drupal_create_directories($url = NULL, $profile = NULL) { | |
"sites/$url/private/temp" | |
); | |
+ // Allow other commands to add or alter the directories to be created. | |
+ drush_command_invoke_all('provision_drupal_create_directories', $mkdir, $url); | |
+ | |
foreach ($mkdir as $path => $perm) { | |
if (!is_dir($path)) { | |
provision_file()->mkdir($path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment