It's very common for larger sites to want to store their files directory on some shared filesystem. The pack module was supposed to help with this, however, I've done two fairly large Aegir deployments for clients, and having /var/aegir on an NFS volume was a no-go. It's simply too slow.

So I propose adding a storage service to Aegir that will allow moving the "files" and "private" directory to some other location, and then symlink them into place. I have posted a proof-of-concept implementation of this at http://drupal.org/project/provision_storage (the frontend module is http://drupal.org/project/hosting_storage).

This implementation creates /var/aegir/filestorage. When a site "mysite.com" is created, provision_storage creates /var/aegir/filestorage/mysite.com, and then creates /var/aegir/filestorage/files/* and /var/aegir/filestorage/mysite.com/private. Then, in /var/aegir/platforms/drupal-7.26/sites/mysite.com, this extension creates a symlink from /var/aegir/platforms/drupal-7.26/sites/mysite.com/files to /var/aegir/filestorage/mysite.com/files (and same for the private directory).

This all works as intended until remote servers are added to the mix. When using the "basic" storage service, /var/aegir/platforms/drupal-7.26/sites/mysite.com/files is synced to the remote server as a directory, rather than as a symlink.

In this simple example, the assumption is that /var/aegir/filestorage would be mounted on all servers from an NFS volume or something. More complicated storage services could be written later to automatically provision NFS volumes on a storage server, and then mount them appropriately for sites that want to use that storage engine.

I'd love some feedback on 1) the current iteration of the (provision|hosting)_storage code, and 2) the possibility of adding something like this to Aegir

Comments

ergonlogic’s picture

re. (2) I'd say it would make a good candidate for #2180053: Include more "golden" contrib.

ergonlogic’s picture

Is the intention here mostly to remove files from backups to speed up clones and migrations? That's always been our use-case for doing something like this.

Some documentation would also be nice. Presumably the various scripts are to allow setup and tear-down of NFS mounts or such?

cweagans’s picture

No, the use case is to move the files/private directory to a filesystem that's mounted on all servers. This is so that the files are available to all web servers in a cluster.

omega8cc’s picture

Wow! That is really golden! :) I'm going to test this this weekend.

ergonlogic’s picture

Ok, well then bear in mind that backups don't follow symlinks. Perhaps we'll also need to expose whether to follow symlinks in backups as a drush option, so it can be overridden.

cweagans’s picture

Oh, yeah, that would be good :)

If it doesn't happen, though, I guess that's okay. In my particular case, the shared filesystem is backed up separately by the server admins, so that might be okay.

cweagans’s picture

Does anyone know why the symlinks aren't being synced to the remote server appropriately? I really have no idea what the problem is :(

cweagans’s picture

I figured out why I'm having a problem with this, I think. It's because the target of the symlink is outside the root of the rsync operation...so maybe this approach won't work.

I've come up with a different idea, though, which is to use a rewrite rule to map /sites/sitename.whatever.com/files to /var/aegir/filestorage/sitename.whatever.com/files. This breaks other things though.

I strongly feel that support for storing Drupal files in a different location + still allowing backups, etc. is a pretty important thing. Maybe if I have time, I'll circle back around to this in a couple months.

cweagans’s picture

Jon Pugh’s picture

Title: Add a storage service » Add a storage service: Allow configurable file_directory_path per site.
Version: 6.x-2.x-dev » 7.x-3.x-dev

I strongly feel that support for storing Drupal files in a different location + still allowing backups, etc. is a pretty important thing.

YES. Strongly Agree.

I am constantly apologizing to people for aegir forcing you to store your files in sites/yourcrappyoriginalsitename.com/files.

First step is to stop forcing the site files path, but still save whatever path that is to the Site context.

Next would be improving clusters to setup NFS automatically.

Not sure, but I don't see a need to "symlink them into place" if we can set the 'file_directory_path' variable.

anarcat’s picture

for backups: we could make backup in two stages. first backup the site directory, then add the files on top of that. that way we don't need to follow symlink, which is inherently insecure (i could just `ln -s /var/aegir/platform/foo/sites/victim.com /var/aegir/platform/foo/sites/attacker.com/files/hahaha` to read all files from victim.com).

that said, i don't think we should split files out of the directory, but move the whole directory completely, as in #1205458: Move modules/themes/libraries/files/private directories out of /sites/example.com. that way we don't need to follow symlinks for backups and things are more consistent. ergonlogic did a lot of good work there and we were pretty much done with that.

i do prefer the approach of having a generic storage service. that's a long standing goal of the project. so i would suggest to focus on this issue for now.

i think the remaining steps here would be:

  1. make this work for settings.php and friends (ie. move all of sites/example.com out and keep symlinks back
  2. make an upgrade path (i would propose to make "verify" detect if there's a filestorage configured and move files into it when relevant)
  3. make sure we don't backup and deploy in migrate (that's the whole point of this optimisation - just backup so we can rollback!)
  4. (we probably need to fix rollbacks as well in that regard)
  5. fix remote server support (i suspect this could be fixed the same way as for backups: just rsync the symlink target)
anarcat’s picture

alright, so first tests on this show that this extension cannot be installed in a site-specific directory, so that's bad, see #2185627: Add a storage service: Allow configurable file_directory_path per site. for what seems to be a bug in the aegir API. we're also trying to port the module to d7 so it works with aegir3.

next I postponed #1205458: Move modules/themes/libraries/files/private directories out of /sites/example.com for now while we shake down this specific tree.

mvc’s picture

ergonlogic’s picture

I believe the issues we were seeing with hosting_ and provision_storage were largely due to #2374841: weird bootstrapping problem when defining services in sites. I have an almost complete port of these to Aegir3, and we'll be further testing them this week. I also merged the provision component into the hosting module, as per #2300537: Merge Provision extensions into Hosting modules.

We're considering whether to use this approach to move the entire site out of the platform, as in #1205458: Move modules/themes/libraries/files/private directories out of /sites/example.com.

euk’s picture

Just a thought:
Why to synch symlinks?
Would it be easier to exclude necessary folders from synch, and once everything is pushed to remotes - create symlinks to those folders on each remote server?

Cheers!

Jon Pugh’s picture

This is something we've wanted for devshop for a long time. Since we don't use multisite we want to be able to just use sites/default/files, like so many other hosting systems use.
There are a few small steps we should take immediately:

Make file_directory_path a Site context property, so whatever is saved in the drush alias gets written to the settings.php file. (defaults to site/domain/files, but should also be optional).
Create a property on site nodes for this, and default it to site/domain/files.

Those two things could be acceptable changes to provision and hosting.module. We don't need a UI change in aegir core. Any module can use nodeapi to alter the site node property.

No need to overcomplicate it at this point. Let's start by taking these first steps.

Jon Pugh’s picture

Status: Active » Closed (outdated)

Here's a newer issue I used to store the work in progress: #3016995: Make file directories first class context properties.