Re: The question of Apache deamontools

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Rainer,

Thanks for your helps!


On 2012-08-09 20:10, Brett Maxfield wrote:




On 09/08/2012, at 1:43 PM, Liu JinGang <liujg@xxxxxxxxxxxxxx> wrote:

ApacheGroup Mem:

hello,boys~

I use the deamontools to control the apache.
run script as following(refer to the doc of www):
-------------------------------------
#!/bin/sh

CONF=/etc/httpd/conf/httpd.conf
DAEMON=/usr/sbin/httpd
DAEMON_ARGS="-f $CONF -DNO_DETACH -DFOREGROUND -d /etc/ahttpd -DHAVE_SSL"

exec 2>&1

exec pgrphack $DAEMON $DAEMON_ARGS
-------------------------------------

1.
exec 2>&1
This code redirect the stderr to stdout,
but what is the funcion of this code? why add it?(I find that the doc of internet almost all of them add the code)
when delete it, what is happened?

The 2>&1 takes all output of stderr (file descriptor 2) and redirects it to stdout (file descriptor 1)

In the context of starting a daemon, if stdout is redirected like 1>/dev/null then stderr will do the same. It frees the relationship between the invoking shell and the daemon program. Otherwise the program might exit when you close the shell you used to launch the daemon.

You can redirect stdout to a file eg 1>debug.log, but this is only helpful for testing. In your example all output of stderr and stdout, will go to the invoking shell as httpd is running in foreground mode for debugging.

Most long running programs will write thier own logs, so you probably want to use these, as they can be easily rolled. A log file made with redirection, can grow very large, and cant be rolled without stopping the owning daemon first.

2.
when use the deamontools to control the apache.
for example(process):
---------------------------
root 4418   4416       supervise ahttpd
                       |
root 20110  4418        /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -DNO_DETACH -DFOREGROUND -d /etc/httpd -DHAVE_SSL
                          |
ipcom 20113 20110          /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -DNO_DETACH -DFOREGROUND -d /etc/httpd -DHAVE_SSL
ipcom 20114 20110          /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -DNO_DETACH -DFOREGROUND -d /etc/httpd -DHAVE_SSL
ipcom 20115 20110          /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -DNO_DETACH -DFOREGROUND -d /etc/httpd -DHAVE_SSL
ipcom 20116 20110          /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -DNO_DETACH -DFOREGROUND -d /etc/httpd -DHAVE_SSL
--------------------------
If I only kill the parent httpd (20110), apache cannot restart.
If I kill all the  httpd (20110,20113 ...) , apache can restart.

The reason is?

You are running httpd in foreground mode, you dont usually do that unless you are debugging or testing something.

Out of interest, nearly every linux distribution comes with an init script for apache, why are you writing your own ?

All modern Apache's itself already has this functionality in the apachectl script ? Usually an init script would just call that for start/stop/restart etc., i'd look in an existing init script for an example..

Cheers
Brett


Thanks!


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux