slow /etc/init.d/apache2 script (Etch)
Testing Etch out, and i tried to restart my apache2 server, and i noticed it took ages compared to Sarge, so i looked at the init.d script for apache2 and noticed a sleep 10 command, anyone now why it's waiting this long to restart the server? and if i can comment it out?
|
Typically sleep statements are added to give some process time to run before the next one is run.
So to know the answer to your question would depend on WHERE the sleep is in the script. If its at the very beginning then you'd want to know what init script was running right before it. (Unlikely but just used as an example.) If it is in the body of the script you'd need to figure out what it was doing before the sleep (e.g. is it removing some old file(s), executing a command line to start a process (e.g. httpd) or what? Then what does it do after the sleep. It's very likely the item after the sleep is dependent on successful completion of the item before the sleep. You may be able to reduce the amount of sleep (e.g. sleep 1) if you know the item before the sleep is actually completing more quickly than 10. You should be sure though - people seldom add sleeps without a reason - 10 seconds isn't really a high cost to pay for being sure your web server starts up correctly. Of course if you're not running a web server at all you can just disable the start of apache altogether and avoid this. |
Usually, when there's a line of code, it's for something. I wouldn't tweak it before understanding exactly what you do.
Anyway, do you restart your apache every hour or what? :) |
no, it's just annoying since sarge did not wait that long,
|
I think that the offending code he is talking about is here:
Code:
restart | force-reload) If this delay didn't occur, and it tried to start the Apache process before the old one had completed shutting down, things like lock files have a tendency to get in the way and the new process will not start. This can cause havoc if you are trying to restart a live web server and only want it to be down for the minimal amount of time. If you were to restart it only to have it die because there was still a lock file in the way that two seconds later would have been removed. Better to wait the ten seconds and only have that down time than risk not having the service start up again and waste even more time. |
That's a surprising piece of code.
Putting sleep here and there is in general bad programming. What if it takes 11seconds to stop? There is no shell command for waiting for a process to stop in bash? Well then if they don't keep track of all PIDs, maybe it's the only solution.. Humm |
it appears to be in the way that the stop section of the code is written.
Code:
apache_stop() { The restart portion of the init.d script then moves on to the starting portion, which would probably break if there were not a time delay. This is not really a problem with the init script as it is with Apache2 itself. The real solution would be for Apache2 to have a signal that allows it to re-start cleanly and properly instead of stopping everything and starting fresh. Typically when you restart Apache2 like this, the reason you are doing so is because you have changed something in a configuration file (such as adding a new virtual site or something like that), so a simple re-reading of the configuration file would be a nice thing, ala postfix. |
Quote:
The question was answered by more than one person saying that sleeps are seldom added without a reason. If you don't like the damn sleep then just comment it out and don't bother the rest of us since you're obviously going to ignore the responses you get. |
Quote:
the "no" was the answer to this question: "do you restart your apache every hour or what?" |
All times are GMT -5. The time now is 07:53 PM. |