Was this page helpful?

Monitor and automatically restarting my site

    Table of contents
    No headers

    Here's how to set up a cron job that checks your wiki every 5 minutes, restarts the wiki and emails you if anything goes wrong.

    The cron job is created using crontab -e (for edit). The "*/5" means every 5 minutes. It will email you on any output.

    MAILTO=yourname@yourdomain.com
    # m h  dom mon dow   command
    */5 * * * *     $HOME/cron/check_wiki

    The cron script "check_wiki" is created in a directory called "cron". The script can be made smarter and smarter (some "todo" examples have been included - hopefully someone will update the following with more advanced examples), for now this will just restart the dekihost service if we fail to get a webpage.

    #!/bin/bash
    # This script keeps an eye on the wiki and restarts it on error
    
    # Try silently 3 times to access the wiki
    wget -T 10 -t 3 -q  http://www.yourwiki.org/ 
    
    # See if we have an error page or no page at all (grep error)
    checkresult=$(grep "Your wiki is down" index.html)
    
    # If we get something back we have an error
    if [ "$checkresult" != "" ]
    then
            # generate some output so the admin gets an email
            echo $checkresult
            # restart the wiki
            /etc/init.d/dekihost restart
    
            #todo: It would be nice to grep processes and logs
            # so that we have some idea I what went wrong
            echo "mono process info:"
            ps -ef | grep mono
    
            #todo: It would also be nice to escalate the issue
            # 1st: /etc/init.d/dekihost restart
            #
            # 2nd: /etc/init.d/dekihost restart
            #      /etc/init.d/apache restart
            #
            # 3rd: shutdown -n restart
    fi
    # remove the page we just retrieved
    rm index.html*

    Note: this will give your front page a high page count. If you are worried about that, you can remove the "wget" logic and try other things like poll the status of processes

    checkresult=$(/etc/init.d/dekihost status | grep FAILED)
    Was this page helpful?
    Tag page
    Viewing 1 of 1 comments: view all
    This looks outdated. I don't think this is how you restart Mindtouch at the moment.
    Posted 04:26, 15 Nov 2011
    Viewing 1 of 1 comments: view all
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by