apachectl : Beauty of apache controller interface

Every tired to change apache config from a program and then wondered how to restart apache. Here’s a solution. APACHECTL.

When you do restart of apache, it will kill all the current sessions. But with apachectl you have option to restart the server gracefully without killing any previous sessions. This way all further connections will take up the new settings.

I’ve been doing this for a small little experiment, I wanted to add dynamic subdomains, So I had to edit the apache host httpd.conf files and we all know we have to restart the server after any config file is changed. So here’s an alternative. Change the config files from your PHP or CGI etc, and then call this apachectl.

The command is :  apachectl graceful

For Ubuntu and debian system the command would be : apache2ctl graceful

Here are some quick references from Apache’s official page:

start
Start the Apache httpd daemon. Gives an error if it is already running. This is equivalent to apachectl -k start.
stop
Stops the Apache httpd daemon. This is equivalent to apachectl -k stop.
restart
Restarts the Apache httpd daemon. If the daemon is not running, it is started. This command automatically checks the configuration files as in configtest before initiating the restart to make sure the daemon doesn’t die. This is equivalent to apachectl -k restart.
fullstatus
Displays a full status report from mod_status. For this to work, you need to have mod_status enabled on your server and a text-based browser such as lynx available on your system. The URL used to access the status report can be set by editing the STATUSURL variable in the script.
status
Displays a brief status report. Similar to the fullstatus option, except that the list of requests currently being served is omitted.
graceful
Gracefully restarts the Apache httpd daemon. If the daemon is not running, it is started. This differs from a normal restart in that currently open connections are not aborted. A side effect is that old log files will not be closed immediately. This means that if used in a log rotation script, a substantial delay may be necessary to ensure that the old log files are closed before processing them. This command automatically checks the configuration files as in configtest before initiating the restart to make sure Apache doesn’t die. This is equivalent to apachectl -k graceful.
configtest
Run a configuration file syntax test. It parses the configuration files and either reports Syntax Ok or detailed information about the particular syntax error. This is equivalent to apachectl -t.

The following additional option is available, but deprecated.

startssl
This is equivalent to apachectl -k start -DS

Leave a Reply

Your email address will not be published. Required fields are marked *