Status
Not open for further replies.

skinner

Active Member
741
2010
59
5,210
Hi, I'm looking for a script to put on crontab that check if my domain is on, otherway it restart apache.

Sometimes my apache get freeze and I need to manually restart it.

I found many scripts that check if httpd is running, but in my case apache is working but none can connect to it.

How can I check if it's working and I can connect to my web pages?

My actually code is:

Code:
#!/bin/bash
    # Apache Process Monitor
    # Restart Apache Web Server When It Goes Down
    # -------------------------------------------------------------------------
    # Copyright (c) 2003 nixCraft project <http://cyberciti.biz/fb/>
    # This script is licensed under GNU GPL version 2.0 or above
    # -------------------------------------------------------------------------
    # This script is part of nixCraft shell script http://en.wikipedia.org/wiki/Shell_script  collection (NSSC)
    # Visit http://bash.cyberciti.biz/ for more information.
    # -------------------------------------------------------------------------
    # RHEL / CentOS / Fedora http://en.wikipedia.org/wiki/Fedora  Linux restart command
    RESTART="/sbin/service httpd restart"

    # uncomment if you are using Debian / Ubuntu Linux
    #RESTART="/etc/init.d/apache2 restart"

    #path to pgrep command
    PGREP="/usr/bin/pgrep"

    # Httpd daemon name,
    # Under RHEL/CentOS/Fedora it is httpd
    # Under Debian 4.x it is apache2
    HTTPD="httpd"

    # find httpd pid
    $PGREP ${HTTPD}

    if [ $? -ne 0 ] # if apache not running
    then
     # restart apache
     $RESTART
    fi

Thanks...
 
15 comments
Why is Apache freezing on your server? This seems more like a duct tape fix. I would consider seeing what is causing your apache to stop responding, so you can render this method obsolete..
 
How can I check? In error log I don't see any specific error..

For example, I had just 1 hour downtime but it's gone online by itself.. I didn't restart apache..
 
What you describe sounds more like your server/cpu gets tied up on a process to the point where it cannot serve httpd processes; thus the temporary downtime/freeze.
 
How can I monitor what process freeze apache?

Edit: But if I restart apache, all come back normal.. maybe it's apache itself that for some reason (too much connections? too much requests?) get high cpu and freeze...
 
Last edited:
So, just to make all clear here is my error.log

Code:
[Tue May 17 23:10:43 2011] [info] mod_ssl/2.2.17 compiled against Server: Apache/2.2.17, Library: OpenSSL/0.9.8e-fips-rhel5
[Tue May 17 23:10:43 2011] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 0 in child 20148 for worker proxy:reverse
[Tue May 17 23:10:43 2011] [debug] proxy_util.c(1934): proxy: initialized single connection worker 0 in child 20148 for (*)
[Tue May 17 23:10:43 2011] [notice] Apache/2.2.17 (Unix) DAV/2 PHP/5.3.6 mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 configured -- resuming normal operations
[Tue May 17 23:10:43 2011] [info] Server built: Dec 29 2010 13:20:59
[Tue May 17 23:10:43 2011] [debug] prefork.c(1018): AcceptMutex: sysvsem (default: sysvsem)
[Tue May 17 23:10:44 2011] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 0 in child 20192 for worker proxy:reverse
[Tue May 17 23:10:44 2011] [debug] proxy_util.c(1837): proxy: worker proxy:reverse already initialized
[Tue May 17 23:10:44 2011] [debug] proxy_util.c(1934): proxy: initialized single connection worker 0 in child 20192 for (*)
[Tue May 17 23:10:47 2011] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 0 in child 20334 for worker proxy:reverse
[Tue May 17 23:10:47 2011] [debug] proxy_util.c(1837): proxy: worker proxy:reverse already initialized
[Tue May 17 23:10:47 2011] [debug] proxy_util.c(1934): proxy: initialized single connection worker 0 in child 20334 for (*)
[Tue May 17 23:10:48 2011] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 0 in child 20356 for worker proxy:reverse
[Tue May 17 23:10:48 2011] [debug] proxy_util.c(1837): proxy: worker proxy:reverse already initialized
[Tue May 17 23:10:48 2011] [debug] proxy_util.c(1934): proxy: initialized single connection worker 0 in child 20356 for (*)
[Tue May 17 23:10:48 2011] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 0 in child 20358 for worker proxy:reverse
[Tue May 17 23:10:48 2011] [debug] proxy_util.c(1837): proxy: worker proxy:reverse already initialized
[Tue May 17 23:10:48 2011] [debug] proxy_util.c(1934): proxy: initialized single connection worker 0 in child 20358 for (*)
[Tue May 17 23:10:48 2011] [info] [client 173.193.103.131] (32)Broken pipe: core_output_filter: writing data to the network
[Tue May 17 23:10:50 2011] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 0 in child 21507 for worker proxy:reverse
[Tue May 17 23:10:50 2011] [debug] proxy_util.c(1837): proxy: worker proxy:reverse already initialized
[Tue May 17 23:10:50 2011] [debug] proxy_util.c(1934): proxy: initialized single connection worker 0 in child 21507 for (*)
[Tue May 17 23:10:53 2011] [info] [client 208.88.8.22] (32)Broken pipe: core_output_filter: writing data to the network
<br />
<b>Deprecated</b>:  Directive 'register_long_arrays' is deprecated in PHP 5.3 and greater in <b>Unknown</b> on line <b>0</b><br />
[Tue May 17 23:11:04 2011] [info] [client 89.245.117.177] (104)Connection reset by peer: core_output_filter: writing data to the network
[Tue May 17 23:11:07 2011] [info] [client 89.245.117.177] (32)Broken pipe: core_output_filter: writing data to the network
[Tue May 17 23:11:14 2011] [info] [client 62.30.138.148] (104)Connection reset by peer: core_output_filter: writing data to the network
[Tue May 17 23:11:22 2011] [info] [client 208.88.8.22] (32)Broken pipe: core_output_filter: writing data to the network
[Tue May 17 23:11:41 2011] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 0 in child 23965 for worker proxy:reverse
[Tue May 17 23:11:41 2011] [debug] proxy_util.c(1837): proxy: worker proxy:reverse already initialized
[Tue May 17 23:11:41 2011] [debug] proxy_util.c(1934): proxy: initialized single connection worker 0 in child 23965 for (*)
<br />
<b>Deprecated</b>:  Directive 'register_long_arrays' is deprecated in PHP 5.3 and greater in <b>Unknown</b> on line <b>0</b><br />
[Tue May 17 23:11:52 2011] [info] [client 208.88.8.22] (32)Broken pipe: core_output_filter: writing data to the network
[Tue May 17 23:11:53 2011] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 0 in child 24368 for worker proxy:reverse
[Tue May 17 23:11:53 2011] [debug] proxy_util.c(1837): proxy: worker proxy:reverse already initialized
[Tue May 17 23:11:53 2011] [debug] proxy_util.c(1934): proxy: initialized single connection worker 0 in child 24368 for (*)
<br />
<b>Deprecated</b>:  Directive 'register_long_arrays' is deprecated in PHP 5.3 and greater in <b>Unknown</b> on line <b>0</b><br />
[Tue May 17 23:12:01 2011] [info] [client 93.143.170.193] (32)Broken pipe: core_output_filter: writing data to the network
[Tue May 17 23:12:04 2011] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 0 in child 25767 for worker proxy:reverse
[Tue May 17 23:12:04 2011] [debug] proxy_util.c(1837): proxy: worker proxy:reverse already initialized
[Tue May 17 23:12:04 2011] [debug] proxy_util.c(1934): proxy: initialized single connection worker 0 in child 25767 for (*)
<br />
<b>Deprecated</b>:  Directive 'register_long_arrays' is deprecated in PHP 5.3 and greater in <b>Unknown</b> on line <b>0</b><br />
[Tue May 17 23:12:08 2011] [info] [client 93.143.170.193] (104)Connection reset by peer: core_output_filter: writing data to the network
[Tue May 17 23:12:22 2011] [info] [client 208.88.8.22] (32)Broken pipe: core_output_filter: writing data to the network
[Tue May 17 23:12:53 2011] [info] [client 208.88.8.22] (32)Broken pipe: core_output_filter: writing data to the network
[Tue May 17 23:12:59 2011] [info] [client 123.125.71.16] (104)Connection reset by peer: core_output_filter: writing data to the network
[Tue May 17 23:13:22 2011] [info] [client 208.88.8.22] (104)Connection reset by peer: core_output_filter: writing data to the network

It's the same when server is up or down..
 
Is it normal?

1zXhDz.png
 
Status
Not open for further replies.
Back
Top