+ Reply to Thread
Results 1 to 3 of 3

Thread: Store Closed / Maintenance Web Page Script

  1. #1
    Administrator Advisor   peter's Avatar
    Join Date
    Apr 2004
    Posts
    878

    Store Closed / Maintenance Web Page Script

    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

    My sites: Linux Home Networking – Linux Quick Fix Notebook

  2. #2
      Good Guru trickster trickster's Avatar
    Join Date
    Mar 2002
    Posts
    4,147
    Neat! Thanks!

    You might want to stickify it.
    My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive.

  3. #3
    Here is an even EASIER way ………..

    This way allows you to rebuild apache, or do other maintenance to your webserver….. whatever…..

    Code:
    while true; do nc -l -p 80 -q 1 < downformaint.html; done
    Uses netcat……. simplest server you can do …… a one liner

+ Reply to Thread

Similar Threads

  1. Firewall script in RHEL 4
    By sud.tech in forum Programming
    Replies: 8
    Last Post: 06-12-2008, 02:07 PM
  2. Setting Up Pages in Visio
    By The Donald in forum Windows – General Topics
    Replies: 0
    Last Post: 01-05-2005, 07:25 AM
  3. Set Page Transitions on a Frames Page
    By regix in forum Windows – General Topics
    Replies: 0
    Last Post: 01-01-2005, 03:30 AM
  4. Create and Use a Frames Page in FrontPage 2k
    By regix in forum Windows – General Topics
    Replies: 0
    Last Post: 01-01-2005, 03:29 AM
  5. Shell Script to modify apachectl
    By gaxprels in forum Programming
    Replies: 6
    Last Post: 07-23-2002, 08:18 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts