Slow Apache Starts on Ubuntu

      by Wyatt Walter

An Apache server that I was working with was having an issue starting in a reasonable amount of time. This particular server was running on Ubuntu 8.04 on top of VMware ESX 3.5. The service would start eventually, but would hang for a fairly significant amount of time. In the Apache error logs it would show the following line:
[notice] Digest: generating secret for digest authentication ...

Eventually, the digest generation would finish and my websites would come back. Sometimes it would take just a few seconds and other times it would take about 30 seconds. After doing a little digging, I found that a number of people were having this issue, with very few answers.

The root problem, as I found out, was that the OS was running out of entropy. One can see how much entropy is available with the following command:
sudo cat /proc/sys/kernel/random/entropy_avail

My system was returning a value somewhere around 150-200 and went down to nothing while Apache was generating its digtest. When I looked at the same file on other systems, they were all 2000+, an obvious problem.

According to a couple of blog posts, installing rng-tools and running the rngd daemon seemed to be the answer.

I did a quick install of rng-tools:
sudo apt-get install rng-tools

However, rngd failed to start, reporting that it couldn’t find the hardware generator:
/etc/init.d/rng-tools: Cannot find a hardware RNG device to use.
invoke-rc.d: initscript rng-tools, action "start" failed.

After a little more searching, I found out that you simply have to change the source for the generation to /dev/urandom:
sudo vim /etc/default/rng-tools

And changed the line:
#HRNGDEVICE=/dev/hwrng

To:
HRNGDEVICE=/dev/urandom

Save the changes and start rngd:
sudo /etc/init.d/rngd start

Now, ‘catting’ my entropy_avail file displayed over 2000 like my other systems and Apache starts right up on a restart.

Tags: , ,
Filed under How-Tos / Tips : Comments (4) : Mar 17th, 2009

  • Brian

    Was experiencing this w/ Jetty (Java Web Server) on Ubuntu. Restarted /etc/init.d/rng-tools as a /etc/init.d/rngd did not exist. Thanks.

  • Ken

    I’m having the same issue, I’ve done exactly as you said, step by step, all seemed to go fine, but I also didn’t have the rngd, so I started rng-tools. however I still get very low numbers around, 130. could you suggest anything that I maybe missing?

  • http://www.ghidinelli.com/2011/01/11/cold-fusion-slow-start-messagebrokerservlet ColdFusion hangs or slow on startup due to MessageBrokerServlet » ghidinelli.com

    [...] the Ubuntu connection from Stack Overflow, this post on slow Apache starts described the same symptoms and the use of rngd (a random number generator daemon) to populate the [...]

  • http://junior-aei.com Thomas

    Thank you very much, it works great !