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:


Code:
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:


Code:
ServerName localhost
NameVirtualHost *:80
ErrorDocument 404 /

<VirtualHost *:80>
    DocumentRoot /var/www/html/closed
</VirtualHost>
  • 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.


Code:
Include conf.d/websites.d/active/*.conf
  • 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.


Usage:

Code:
# ./web-store.sh open
# ./web-store.sh closed
Sample code for web-store.sh:

Code:
#!/bin/bash

LOCK_FILE="/var/lock/subsys/httpd"

#
# Remove symbolic link
#

if [ -d /etc/httpd/conf.d/websites.d/active ]; then
    /bin/rm -f /etc/httpd/conf.d/websites.d/active
fi

#
# Restore symbolic link
#

if [ $1 = "closed" ]; then
    ln -s /etc/httpd/conf.d/websites.d/closed /etc/httpd/conf.d/websites.d/active 
else
    ln -s /etc/httpd/conf.d/websites.d/open /etc/httpd/conf.d/websites.d/active 
fi

#
# Restart Apache
#

if [ -f "$LOCK_FILE" ]; then
    /sbin/service httpd stop
    /bin/sleep 30
    /sbin/service httpd start
fi