Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2002
    Location
    Netherlands
    Posts
    12

    Question Apache auto-restart script (crontab)

    Hello,

    I have root ssh access to a server and we notice when doing a bash ./mysq-backup script to dump the data from the web site's databases into .sql and .tgz them that httpd goes down sometimes. That, and sometimes it seems that httpd goes down in other situations. All fine, we will figure out why. But ..

    It would be nice to run a crontab to check every 15 minutes if httpd is running, if not, to restart it.

    Right now I when I notice the site is down I log into the ssh as root and type: service httpd restart. If it is up it will then first stop it, and restart it. I can look at the screen and see it happen, so I feel pretty safe doing this. One of my concerns is that when I am not at the screen and it stays down .. I do not notice this and downtime increases. And we don't want to just crontab service httpd restart, so a bash script to check for the pid and restart if it down .. would be nice.

    I thought this would work:
    (chmod 755 httpdcheck)
    Code:
    delta:~ root# cat httpdcheck 
    #!/bin/bash
    
    if [ ! "$(pidof httpd)" ]
    then
    echo "Could not find pid of httpd - restarting"
      service httpd restart
    else
    echo "Found pid of httpd - NO need to restart"
    fi
    delta:~ root#
    And I have this crontab entry:
    Code:
    delta:~ root# crontab -l
    */5 * * * * /root/httpdcheck | mail my@email
    delta:~ root#
    When testing, I did service httpd stop and waited 5 minutes and I received the email : could not find it, restarting. But when I go to the web site in browser it remains down. I have to login to ssh and do service httpd start manually to really load it.

    Manually loading btw .. shows it works as bash script just fine, so I dont't know why it won't work when run from cron?
    Code:
    delta:~ root# ./httpdcheck 
    Could not find pid of httpd - restarting
    Stopping httpd:                                            [FAILED]
    Starting httpd:                                            [  OK  ]
    delta:~ root#
    So .. when is it going wrong? Am I forgetting something?

    Hopefully someone knows.
    The vBulletin Fans Network
    former Jelsoft Staff Member
    DeskPro Team Member

  2. #2
    Join Date
    Dec 2004
    Location
    New York, NY
    Posts
    10,710
    Don't know if it'll help but maybe try specifying the path;

    service httpd restart

    do

    /sbin/service httpd restart

  3. #3
    Join Date
    Mar 2002
    Location
    Netherlands
    Posts
    12
    That was exactly it. Thank you!
    The vBulletin Fans Network
    former Jelsoft Staff Member
    DeskPro Team Member

  4. #4
    Server Surgeon George
    http://www.serversurgeon.com
    Linux, BSD and Windows Administration Services
    Toll Free US 877-378-7436 International +1-213-291-9191

Posting Permissions

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