Restart Apache without closing open connections

Contributor Icon Contributed by qmchenry Date Icon September 24, 2003  
Tag Icon Tagged: Apache web server

After making changes to Apache’s configuration file (httpd.conf), it is necessary to restart Apache for the changes to take effect. A normal restart will close active connections which may cause problems for users.


To restart Apache gracefully without aborting open connections or to start Apache if it is not running:

apachectl graceful

If apachectl is not in your PATH and you don’t know where it is, refer to the recipe Find a file by name to find the location of apachectl, then run it with the fully qualified path, for example:

/usr/local/apache/bin/apachectl graceful

Previous recipe | Next recipe |
 
  • bofh468
    Failing to find apachectl, one could just find the PID of the parent httpd process and send a -USR1 signal to it.

    For example:


    $ ps -ef | grep httpd
    root 17723 1 0 Sep23 ? 00:00:01 /usr/sbin/httpd -DHAVE_ACCESS -D
    apache 3666 17723 0 Nov09 ? 00:00:00 /usr/sbin/httpd -DHAVE_ACCESS -D
    apache 3667 17723 0 Nov09 ? 00:00:00 /usr/sbin/httpd -DHAVE_ACCESS -D
    apache 3668 17723 0 Nov09 ? 00:00:00 /usr/sbin/httpd -DHAVE_ACCESS -D
    apache 3669 17723 0 Nov09 ? 00:00:00 /usr/sbin/httpd -DHAVE_ACCESS -D
    apache 3670 17723 0 Nov09 ? 00:00:00 /usr/sbin/httpd -DHAVE_ACCESS -D
    apache 3671 17723 0 Nov09 ? 00:00:00 /usr/sbin/httpd -DHAVE_ACCESS -D
    apache 3672 17723 0 Nov09 ? 00:00:00 /usr/sbin/httpd -DHAVE_ACCESS -D
    apache 3673 17723 0 Nov09 ? 00:00:00 /usr/sbin/httpd -DHAVE_ACCESS -D

    $ kill -USR1 17723



    a -USR1 signal will cause any new children to run with a new configuration, but leave the current children running as-is. A -HUP signal will kill off all current children and cause new requests to be serviced under the new configuration.

    Of course, one could be a little more sophisticated:



    $ ps -ef | grep httpd | grep root | awk '{print $2}' | xargs kill -HUP




    That said, apachectl is a lot cleaner.
blog comments powered by Disqus