Results 1 to 11 of 11
  1. #1
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    57

    How to start apache automatically when down

    Hi,

    Is there a way to start apache in linux if it goes down automatically?

    Thanks

  2. #2
    Join Date
    Dec 2004
    Location
    New York, NY
    Posts
    10,574
    You might want to look into SIM, or you could also write your own script if you prefer.

  3. #3
    Join Date
    Mar 2003
    Location
    Canada
    Posts
    8,910
    Here's a simple yet effective shell script that will restart Apache if it's down:

    #!/bin/sh
    #
    # Apache Process Monitor
    #
    checkapache=`ps ax | grep -v grep | grep -c httpd`
    if [ $checkapache -le 0 ]
    then
    /usr/local/apache/bin/apachectl startssl
    fi
    Put that in a file called /etc/monitor-apache.sh and create a crontab entry, similar to:

    */1 * * * * sh /etc/monitor-apache.sh >/dev/null 2>&1

    That will check Apache every minute, and if no httpd processes are running it will automatically restart the daemon.
    Patrick William | RACK911 Labs | Software Security Auditing
    400+ Vulnerabilities Found - Quote @ https://www.RACK911Labs.com

    www.HostingSecList.com - Security notices for the hosting community.

  4. #4
    Join Date
    Feb 2003
    Location
    Canada
    Posts
    958
    monit works great in these situations too, and can check for more than just the existence of the process in the ps tree (such as consuming too much cpu/ram).

  5. #5
    Join Date
    May 2006
    Location
    India
    Posts
    661
    Going for the proprietary monitoring program, bundled with the Control-panel(if using any..) would be the better bet !
    Also if your Apache gets restarted quite frequently, find its root-cause.
    SparkSupport.Com - The Premier Tech Company
    Cloud Solutions|Email Infra setup|VOIP|Video Streaming|Software Development
    Email: [email protected] Phone : 1- 408-600-1449 | Skype : shijils

  6. #6
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    57
    What does the "monitor" function do in whm?

  7. #7
    Join Date
    Mar 2003
    Location
    Canada
    Posts
    8,910
    Quote Originally Posted by mogsub View Post
    What does the "monitor" function do in whm?
    It will monitor the processes and if it detects a service down, such as Apache, attempt to restart it. It's not perfect and occasionally takes more than a few minutes to notice a service down, but it's better than nothing.
    Patrick William | RACK911 Labs | Software Security Auditing
    400+ Vulnerabilities Found - Quote @ https://www.RACK911Labs.com

    www.HostingSecList.com - Security notices for the hosting community.

  8. #8
    Join Date
    Aug 2007
    Location
    India
    Posts
    117
    If it is a cpanel server, it is better to enable apache in chkservd ( monitoring service provided by cpanel) so that the service will be monitored by chkservd and it will restart the service if it is down. You can enable it from WHM -> Service Manager.
    Anoop
    █ Freelance Linux Admin
    Email: tracerouteme [at] gmail.com

  9. #9
    Join Date
    Jan 2008
    Posts
    77
    Quote Originally Posted by Pat H View Post
    It will monitor the processes and if it detects a service down, such as Apache, attempt to restart it. It's not perfect and occasionally takes more than a few minutes to notice a service down, but it's better than nothing.
    sometimes its not working for me I have to manually restart apache then .. pretty strange, do you think we could modify it so that it will try to restart apache again if the first try failed?
    RLTT.com is for SALE Realtime Technologies is the way to go !

  10. #10
    Join Date
    Aug 2007
    Location
    India
    Posts
    117
    Make sure that chkservd is running in the server. Run the following command to check it.

    service chkservd status


    Also make sure that System Integrity Monitor (SIM) is disabled in the server. SIM is in conflict with cPanel's chkservd.

    Of course, It is better to find the root cause of apache getting failed than searching for a script to restart it automatically
    Anoop
    █ Freelance Linux Admin
    Email: tracerouteme [at] gmail.com

  11. #11
    check the count of apache instances. If there is a load on apache, service will shut down by the server to free up memory. Investigations required if repeats.

    check the biggest domain logs. Hope you find a clue

Posting Permissions

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