Auto Shutdown and Restart Apache HTTPD Service Daemon at Preset Time

The core component of any websites, blogs, web services and web applications is the web server. And Apache is the most popular HTTP server that powers the websites worldwide. It’s important to ensure that the uptime and continuous running of Apache service or daemon on the server, as if HTTPD service is down, your website will be unaccessible to the visitors. Other than using monitoring service, script or utility to check if the HTTPD daemon is up, server administrator also has a choice to restart the Apache service periodically.

Shutdown and restart Apache periodically at specific interval helps to ensure that Apache web service is always running in top notch condition, without effect of possible memory leak and resource hogging by persistent connections. It also ensure that the web sites downtime is limited to the next restart schedule, just in case it’s so unlucky that Apache hangs indefinitely and your monitoring service can’t pick up the incident.

To shutdown and start Apache automatically, we can make use of crontab (or Scheduled Task or Task Scheduler in Windows Server) to schedule the task at the time prefer. Simply edit the cron jobs with a root or whell user, and add in the following line:

m h d m w /usr/local/apache/bin/apachectl restart

Replace m, h, d, m and w with value of your preference, where they represent the following meaning:

m: min (0 - 59)
h: hour (0 - 23)
d: day of month (1 - 31)
m: month (1 - 12)
w: day of week (0 - 6) (Sunday=0)

For variables that you want to happen every time, set it as * (asterisk).

For example, to kill the Apache daemon and start it immediately at 1 AM every night, set the crontab line to:

0 1 * * * /usr/local/apache/bin/apachectl restart

To restart Apache HTTPD service on weekend, such as Sunday 12 noon, use the following cron job:

0 12 * * 0 /usr/local/apache/bin/apachectl restart

You can input “man crontab” to learn more about cron jobs in Linux/Unix/FreeBSD/CentOS. To edit the crontab job list, simply enter “crontab -e” on the shell. Existing crontab will appear on a text editor, such as GNU nano. If this is the case, make the necessary changes, then press “Ctrl-X”, follow by “Y” to save the file, and follow by Enter press to accept the default file name. The new crontab will be installed and in effect immediately.

Note that the path to apachectl may be different on different variant of Unix, Linux or BSD flavors. Use one of the following command to find out where is Apache installed:

find / apachectl | grep apachectl
whereis apachectl

Some Apache may install in /usr/sbin/apachectl, or you can use the httpd or apachectl symbolic links in /etc/rc.d/init.d/apachectl or /etc/rc.d/init.d/httpd.

Share and contribute or get technical support and help at My Digital Life Forums.



Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to comments feature has been disabled. To receive notification of latest comments posted, subscribe to My Digital Life Comments RSS feed or register to receive new comments in daily email digest.
Custom Search

New Articles

Incoming Search Terms for the Article

shutdown apache - Apache shutdown - restart apache auto - start apache at reboot - how to start Apache service - apache daemon - auto start apache in linux - windows apache auto restart script - apache restart - apache auto restart - apache services down - apache service restart - auto shutdown search engine - centos service auto start - centos scheduling reboot - crontab centos how to edit - cron job apache restart - cron apache reset - freebsd 'automatic service restart' - freebsd restart apache command - how to stop apache on shutdown - how to restart httpd daemon - how to set service auto start in reboot windows - restart jboss vms crontab - scheduled apache restart windows - schedule a task to restart a service - start apache daemon freebsd - use logwatcher to auto restart apache - apachectl shutdown - automatic httpd restart - auto start apache centos - centos auto start service - centos auto start services - centos httpd autostart - cpanel how to shut off apache - cron file to start a service automatically in freebsd - cron restart service - cron automatic shutdown - guide linux auto start service when reboot - how to start apache services - how to apache shutdown - httpd shutdown - apache periodically lock - apache autorun on restart - apachectl centos cpanel - centos httpd service restart - centos cron reboot - how to schedule a restart service in linux - linux auto stop at shutdown - reload appache http service -