1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Automatic start Apache when it died/down!

Discussion in 'Apache' started by thuankkk, Jun 24, 2009.

  1. #1
    Hi,

    Recently my Apache web server down for unknown reason. Luckily, I'm online at that time to start Apache.
    When this problem occured more than two times, I tried searching internet and found the way to automatic start Apache when it died.

    - Create a .sh file, e.g /usr/local/startapache.sh with this contents:
    
    #!/bin/sh
    pgrep httpd
    if [ $? -ne 0 ];
    then
      service httpd start
    fi
    
    Code (markup):
    - Chmod it to 0777
    - Set a cron job every minute with that file
    crontab -e
    Code (markup):
    Enter
    * * * * * /usr/local/startapache.sh
    Code (markup):
    Press Esc -> :x -> enter
    Restart crond
    service crond restart
    Code (markup):
    And done!

    Hope this help :)
     
    thuankkk, Jun 24, 2009 IP
    st1905 likes this.
  2. gary4gar

    gary4gar Peon

    Messages:
    496
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Good post!
     
    gary4gar, Jun 25, 2009 IP
  3. thuankkk

    thuankkk Active Member

    Messages:
    503
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    95
    #3
    Thanks :)

    Just found it somewhere in the internet, and slightly edit it :D
     
    thuankkk, Jun 25, 2009 IP
  4. thuankkk

    thuankkk Active Member

    Messages:
    503
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    95
    #4
    Hey you guys,

    I just found a simpler way:
    - Set cron job every minute with this command:
    pgrep httpd || service httpd start
    Code (markup):
    So, your crontab entry will look like this:
    * * * * * pgrep httpd || service httpd start
    Code (markup):
    Very simple :D
     
    thuankkk, Jul 9, 2009 IP