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
    882

    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

  2. #2
    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

Similar Threads

  1. Server Maintenance
    By beezlebubsbum in forum Linux - Hardware, Networking & Security
    Replies: 4
    Last Post: 08-01-2009, 11:12 PM
  2. Port 80 closed after 11pm
    By gmoreno in forum Linux - General Topics
    Replies: 5
    Last Post: 02-02-2003, 05:34 AM
  3. Hello & running a command when xsession is closed
    By Pierre_Lambion in forum Linux - Software, Applications & Programming
    Replies: 4
    Last Post: 08-27-2002, 09:10 PM
  4. Tux Racer going closed source?
    By JimH in forum Linux - Software, Applications & Programming
    Replies: 8
    Last Post: 12-23-2001, 09:45 AM

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
  •