• Projects from Old Site
  • About Me
  • Archives
  • Categories
  • Archive for the ‘Miscellaneous’ Category

    Website Secondary Host


    2012 - 02.18

    In an effort to boost my website's reliability, I created the following remote mirror system for my website. This system allows for either host to go down without hosting being impacted. With any luck, this will prevent most website outages. This system consists of my primary webserver, hosted in North Bend, WA, and a secondary host: my dorm server running here at Cornell.

    My website is essentially a wordpress installation in addition to some other small php pages. In order to sync the two websites, I use the following script which syncs both the website's filesystem as well as wordpress's MySQL database. This script takes advantage of rsync, so only differences between the two websites are synced. This is essential since my home server has severely limited bandwidth and can't afford a massive transfer every hour.

    #!/bin/sh
    #======================================
    #=== Website synchronization script ===
    #======================================
    
    echo "Syncing website directory with rsync"
    rsync -e ssh -avz --exclude="local" --exclude="Stats.html" --exclude="wp-config.php" /var/www/ nexus:/var/www/
    
    echo "Syncing blog database"
    #Export the wordpress database
    mysqldump -u root -p$PASSWORD blog > /dbtmp/txfr.sql
    #Transfer database via rsync
    rsync -e ssh -avz /dbtmp/ nexus:/dbtmp/
    #Install the remote database
    ssh nexus 'mysql -u root -p$PASSWORD blog < /dbtmp/txfr.sql'
    

    A cron job on my home server runs this script every hour (at 5 minutes past the hour). This can be accomplished by running crontab -e and inserting the line:

    5 * * * * /root/sync_website.sh
    

    In order to switch jeffheidel.com to my backup server when my home server goes down, I use the following python script:

    #!/usr/bin/python
    
    #Script checks if jeffheidel.com is up
    #If down, we reassign the DNS records
    import urllib
    import sys
    import os
    
    def reset():
        print "Executing DNS bypass proceedure"
        os.system("/root/bin/updateip_home.sh")
        sys.exit(0)
    
    try:
        a=urllib.urlopen('http://www.jeffheidel.com').getcode()
        if(a!=200):
            reset()
    except:
        reset()
    
    print "All's good"
    

    The script /root/bin/updateip_home.sh uses FreeDNS's dyndns wget script to set the record for jeffheidel.com to the current IP address. The python script above script runs periodically using cron. Similarly, on my home server, I have a script which periodically runs this wget script so that the DNS record is restored once my home server is restored.

    If things are running normally (both servers are up) you will be able to see my primary server at jeffheidel.com and my backup server at cornell.jeffheidel.com. The only difference between the two websites will be the Server Statistics section.

    Update 02/21/12: My dorm server suffered a hard drive failure last night and is currently offline. I do have a replacement drive so it will be online as soon as I get a chance to reinstall the OS and set everything up again.

    Share

    Hello World!


    2011 - 11.19

    This is a test post on my 2nd generation website. This will eventually replace my root directory website. This website is hosted on my home server using an installation of WordPress. It is actually remarkably simple to install and I highly recommend using it. It works natively with any PHP enabled web server that has access to a MySQL database. Additionally, it is highly customizable and easy to use.

    I have begun the process of migrating old projects and content to this new website. Anything that is below this post has already been added to this site. I did my best to estimate posting dates, but they only serve as an approximation.

    In the mean time, the majority of my content is located at my root page.

     

    Share