Here's a script you can use to put up a "store closed" page while your website is undergoing maintenance work.
The script works by moving a symbolic link to point back and forth between configuration files in the /etc/httpd/conf.d/websites.d/closed and /etc/httpd/conf.d/websites.d/open directories depending on whether your website is closed or open.
- First, create these directories:
mkdir -p /etc/httpd/conf.d/websites.d/closed
mkdir -p /etc/httpd/conf.d/websites.d/open
- Next, move the .conf files for your domains into the /etc/httpd/conf.d/websites.d/open directory.
- Create a file /etc/httpd/conf.d/websites.d/closed/closed.conf which contains statements referring to the directory with your store closed index.html web page. For example:
ErrorDocument 404 /
- Now create the file /etc/httpd/conf.d/websites.conf and place the following code in it so that apache uses the files in the directory pointed to by the /etc/httpd/conf.d/websites.d/active symbolic link.
- Create this bash script which shifts the symbolic link "active" from the "open" and "closed" sub directories depending on the arguments "open" or "closed". It will only restart apache if it is already running by checking for the presence of a lock file. Notice that there is a long 30 second wait time between starting/stopping apache. Sometimes apache may not restart properly (usually Fedora) if there are a lot of outstanding web connections, so the delay ensures that the connections die completely before starting again.
Sample code for web-store.sh:
# ./web-store.sh open
# ./web-store.sh closed
# Remove symbolic link
if [ -d /etc/httpd/conf.d/websites.d/active ]; then
/bin/rm -f /etc/httpd/conf.d/websites.d/active
# Restore symbolic link
if [ $1 = "closed" ]; then
ln -s /etc/httpd/conf.d/websites.d/closed /etc/httpd/conf.d/websites.d/active
ln -s /etc/httpd/conf.d/websites.d/open /etc/httpd/conf.d/websites.d/active
# Restart Apache
if [ -f "$LOCK_FILE" ]; then
/sbin/service httpd stop
/sbin/service httpd start