#12: Restarting web server gracefully

Posted by | Comments (0) | Trackbacks (2)

After upgrading your web server you need to restart it, but how is this done correctly? Just killing the server would interrupt all connections and that could cause problems such as inconsistent data and angry users. So what we need to do is to restart the web server gracefully so that all connections being served can finish. Once all connections are closed, the server restarts.

This graceful restart is already implemented in many init scripts. For instance

/etc/init.d/apache2 graceful

to restart Apache gracefully or

/etc/init.d/lighttpd graceful

to restart Lighttpd. But this might not be available on all distributions. Therefore, we want to restart our server manually.

For graceful Apache restart we use apache2ctl, which is shipped alongside Apache. To restart, run

apache2ctl graceful

Instead of using apache2ctl, you might also send a signal (SIGUSR1) to the Apache parent process:

kill -USR1 `cat /var/run/apache2.pid`

Apache also supports a graceful stop if you want to shut down the server instead of restarting it:

apache2ctl graceful-stop

As an alternative you may send the signal SIGWINCH. Note that the Apache manual still documents apachectl instead of apache2ctl, but you should go with apache2ctl as it has been renamed.

To do a manual graceful restart of Lighttpd, send the parent process a SIGINT and then restart.

kill -INT `cat /var/run/lighttpd.pid` ; \
    lighttpd -f /etc/lighttpd/lighttpd.conf

Read more about graceful restart:

Trackbacks

Manko10 sent a Trackback on : (permalink)

RT @reflinux: #Advent series “24 Short #Linux #Hints”, day 12: Restarting #webserver #gracefully http://bit.ly/f6bJKH

robo47 sent a Trackback on : (permalink)

RT @reflinux: #Advent series “24 Short #Linux #Hints”, day 12: Restarting #webserver #gracefully http://bit.ly/f6bJKH

Comments

No comments have been submitted yet. Be the first!

Write a comment:

HTML-Tags will be converted to Entities.
Textile-formatting allowed
Standard emoticons like :-) and ;-) are converted to images.
Design and Code Copyright © 2010-2017 Janek Bevendorff Content on this site is published under the terms of the GNU Free Documentation License (GFDL). You may redistribute content only in compliance with these terms. tweetbackcheck