LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Debian (https://www.linuxquestions.org/questions/debian-26/)
-   -   slow /etc/init.d/apache2 script (Etch) (https://www.linuxquestions.org/questions/debian-26/slow-etc-init-d-apache2-script-etch-531298/)

mastrboy 02-22-2007 05:35 AM

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?

MensaWater 02-24-2007 07:52 AM

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.

nx5000 02-27-2007 06:21 AM

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? :)

mastrboy 02-28-2007 06:28 AM

no, it's just annoying since sarge did not wait that long,

Wells 02-28-2007 08:27 AM

I think that the offending code he is talking about is here:
Code:

        restart | force-reload)
                log_begin_msg "Forcing reload of web server (apache2)..."
                if ! apache_stop; then
                        log_end_msg 1
                fi
                sleep 10
                if $APACHE2CTL start; then
                        log_end_msg 0
                else
                        log_end_msg 1
                fi
        ;;

That sleep there is to ensure that all of the currently running Apache processes have in fact stopped running. I have seen (with Apache2) that the processes can sometimes take a little while to close up shop properly, so this delay is to make sure that they have in fact closed up shop before they get started again.

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.

nx5000 02-28-2007 08:33 AM

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

Wells 02-28-2007 08:49 AM

it appears to be in the way that the stop section of the code is written.

Code:

apache_stop() {
        if `apache2 -t > /dev/null 2>&1`; then
                # if the config is ok than we just stop normaly
                $APACHE2 -k stop
        else
                # if we are here something is broken and we need to try
                # to exit as nice and clean as possible
...

That first bit there (I am going to ignore the abnormal situation that is mentioned there...) basically sends a signal to the Apache service telling it to shut down. That process then ends immediately and the Apache service takes over. At this point, the init.d script has no idea what is going on with Apache2, so it immediately falls through.

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.

MensaWater 02-28-2007 11:41 AM

Quote:

Originally Posted by mastrboy
no, it's just annoying since sarge did not wait that long,

Why start with "no"?

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.

mastrboy 03-01-2007 01:30 AM

Quote:

Originally Posted by jlightner
Why start with "no"?

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.


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.