Mounted home directories on shared web servers

Overview

All site directories on web servers are located in the /home/sites directory and named after the control panel item_id for the particular web configuration (e.g. /home/sites/123).

To avoid creating a massively huge /home/sites partition that would be infeasible to fsck, the actual block devices supporting these sites are mounted under /media/dataNNNN (where NNNN is a four digit number) and kept to a maximum of 250GB each.

Each site directory under /home/sites is bind-mounted from its corresponding /media/dataNNN directory, e.g.

    mount --bind /media/data1234/sites/123 /home/sites/123

This method allows web applications to use a consistent path (/home/sites/123) while allowing us to move the site’s data between different partitions to balance load and space requirements.

Mounting method

We use systemd to manage the mounts. Each site has a file in /etc/systemd/system/ with the name home-sites-123.mount (123 refers to the item_id of the given site).

Using systemctl commands, we can mount, unmount, enable and disable the directory (systemtcl start|stop|enable|disable home-sites-123.mount).

Note: we preivously used symlinks to point the site directory to the correct filesystem. However, the PHP realpath function, used by many CMS’s, ignores the symlink and resolves to the actual directory, causing WordPress and others to incorrectly record the /media/dataNNNN/sites/123 as the absolute path of the application, instead of /home/sites/123, causing problems when a site is moved.

Apache problems

Unfortunately, when apache2 is reloaded, it will re-open all log files. And, when looking for log files, apache will not refresh it’s inode cache, so it won’t see the mounted filesystem. Therefore, it will fail to see the mounted logs directory and the refresh action will fail, causing apache to stop.

To resolve this problem, when the control panel creates a site’s directories, but before we mount them, we leave symlinks from logs, web, and cgi-bin, that exist underneath the mounted file system. The apache reload process sees the symlinks and doesn’t cause apache to crash.

For some reason, requests for web files correctly see the mounted file system, so avoid the PHP realpath problem.