LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 02-22-2007, 06:35 AM   #1
mastrboy
Member
 
Registered: Aug 2005
Distribution: Debian, OpenBSD, PFsense
Posts: 73

Rep: Reputation: 15
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?
 
Old 02-24-2007, 08:52 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,127
Blog Entries: 14

Rep: Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264
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.
 
Old 02-27-2007, 07:21 AM   #3
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 55
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?
 
Old 02-28-2007, 07:28 AM   #4
mastrboy
Member
 
Registered: Aug 2005
Distribution: Debian, OpenBSD, PFsense
Posts: 73

Original Poster
Rep: Reputation: 15
no, it's just annoying since sarge did not wait that long,
 
Old 02-28-2007, 09:27 AM   #5
Wells
Member
 
Registered: Nov 2004
Location: Florida, USA
Distribution: Debian, Redhat
Posts: 416

Rep: Reputation: 53
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.
 
Old 02-28-2007, 09:33 AM   #6
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 55
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
 
Old 02-28-2007, 09:49 AM   #7
Wells
Member
 
Registered: Nov 2004
Location: Florida, USA
Distribution: Debian, Redhat
Posts: 416

Rep: Reputation: 53
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.
 
Old 02-28-2007, 12:41 PM   #8
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,127
Blog Entries: 14

Rep: Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264
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.
 
Old 03-01-2007, 02:30 AM   #9
mastrboy
Member
 
Registered: Aug 2005
Distribution: Debian, OpenBSD, PFsense
Posts: 73

Original Poster
Rep: Reputation: 15
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?"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
etch - kde - slow :( morphixrocks Debian 7 11-19-2006 09:26 PM
Webmin causes Apache2 server to slow down to a crawl PlymWS Linux - Server 4 09-05-2006 05:43 AM
need a new apache2 init script.. lost mine Bremsstrahlung Debian 4 03-22-2006 11:32 PM
Apache2 Linux Mandrake 10.2 init (SysV) startup script RomanG Mandriva 0 06-13-2005 01:15 AM
Slow ethernet card init... bfloeagle Linux - Newbie 9 10-12-2004 08:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 06:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration