You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Mike Behne <md...@yahoo.com> on 2006/04/11 16:24:03 UTC

apr_proc_create

I have a question about behavior of a process launched by apr_proc_create from within an Apache plugin module on Windows.
   
  The created process is intended to remain running regardless of whether the Apache server is running.  I'm noticing that after the process is created, and the Apache server is stopped and I attempt to restart it, I get an indication that the socket (port 80) is in use and Apache won't start.  Once I stop the created process, Apache can successfully start.  I tried a few things to change this behavior--apr_procattr_cmdtype_set,  apr_procattr_detach_set, apr_proc_detach--but no change.  Now I've implemented some techniques to take the created proc down when Apache stops to avoid the failed restart.  Is there anything I could do differently that would allow the created proc to stay up without preventing Apache from restarting?

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: apr_proc_create

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
Ryan Bloom wrote:
> You could on Unix, but on Windows there is no fork command.  It is
> done with CreateProc (or something like that), which doesn't have
> flexibility that fork has.

On windows, when we invoke CreateProc, the listeners should initially be
inherited.  But as they are initialized in the child, they should then be
flagged non-inherited.

This is simple for filesystem handles.  Unfortunately, with LSP (layered service
providers) the "socket handle" might not reflect a win32 handle (!)  This would
obviously mess up handle inheritence rules.

Going back to the first incident...

 > The created process is intended to remain running regardless of whether the
 > Apache server is running.  I'm noticing that after the process is created,
 > and the Apache server is stopped and I attempt to restart it, I get an
 > indication that the socket (port 80) is in use and Apache won't start.

When is this created process launched?  During the -parent- processing.  Of
course all of the shared resources between the parent->child are ALL inherited
by this process.

Other than waiting until the first child spins it off, I can't think of a simple
and portable solution.

Apache's really not the place to launch stand-alone, detached daemons, which is
what this developer appears to be doing.

Bill

Re: apr_proc_create

Posted by Ryan Bloom <rb...@gmail.com>.
You could on Unix, but on Windows there is no fork command.  It is
done with CreateProc (or something like that), which doesn't have
flexibility that fork has.

Ryan

On 4/11/06, Garrett Rooney <ro...@electricjellyfish.net> wrote:
> On 4/11/06, Ryan Bloom <rb...@gmail.com> wrote:
> > Garrett is right in theory, but doing what he suggests will break Apache.  :-)
> >
> > Basically, Apache relies on child processes to ensure that the server
> > keeps running.  If something happens to one child, the parent will
> > create another.  So, if you set the socket to be not inherited in
> > subsequent child processes, then everything will apear to work for a
> > while, and then it will just stop working when the child process dies
> > for some reason.
>
> Couldn't you only set the socket to not inherit in the child
> processes, after the fork?  The parent will still be set up so its
> next child inherits, right?
>
> -garrett
>


--
Ryan Bloom
rbb@apache.org
rbb@rkbloom.net
rbloom@gmail.com

Re: apr_proc_create

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 4/11/06, Ryan Bloom <rb...@gmail.com> wrote:
> Garrett is right in theory, but doing what he suggests will break Apache.  :-)
>
> Basically, Apache relies on child processes to ensure that the server
> keeps running.  If something happens to one child, the parent will
> create another.  So, if you set the socket to be not inherited in
> subsequent child processes, then everything will apear to work for a
> while, and then it will just stop working when the child process dies
> for some reason.

Couldn't you only set the socket to not inherit in the child
processes, after the fork?  The parent will still be set up so its
next child inherits, right?

-garrett

Re: apr_proc_create

Posted by Ryan Bloom <rb...@gmail.com>.
Garrett is right in theory, but doing what he suggests will break Apache.  :-)

Basically, Apache relies on child processes to ensure that the server
keeps running.  If something happens to one child, the parent will
create another.  So, if you set the socket to be not inherited in
subsequent child processes, then everything will apear to work for a
while, and then it will just stop working when the child process dies
for some reason.

On unix, I would tell you to use apr_fork(), and close the socket
yourself, but that isn't an option on Windows.  Probably your best
option is to figure out how the Apache child process on Windows finds
the listening socket, re-attach to that in your child process, and
then close that socket.  I used to know how this all works, but I
haven't played in Apache for a number of years at this point.

Also, while this is an apr question, it is more of an Apache module
question, and belongs on dev@httpd.apache.org.  There are developers
there that can tell you exactly what you need to know about how to
close the socket in your child process.

Ryan

On 4/11/06, Garrett Rooney <ro...@electricjellyfish.net> wrote:
> On 4/11/06, Mike Behne <md...@yahoo.com> wrote:
> >
> > I have a question about behavior of a process launched by apr_proc_create
> > from within an Apache plugin module on Windows.
> >
> > The created process is intended to remain running regardless of whether the
> > Apache server is running.  I'm noticing that after the process is created,
> > and the Apache server is stopped and I attempt to restart it, I get an
> > indication that the socket (port 80) is in use and Apache won't start.  Once
> > I stop the created process, Apache can successfully start.  I tried a few
> > things to change this behavior--apr_procattr_cmdtype_set,
> > apr_procattr_detach_set, apr_proc_detach--but no change.  Now I've
> > implemented some techniques to take the created proc down when Apache stops
> > to avoid the failed restart.  Is there anything I could do differently that
> > would allow the created proc to stay up without preventing Apache from
> > restarting?
>
> I suspect the problem is that the socket httpd is listening on is set
> to be inherited (as you'd expect, since it's created in a parent
> process and inherited by worker processes who do the accept), but what
> you want is for it to not be inheritted by subsequent child processes.
>  There are functions to control this inheritance,
> apr_socket_inherit_unset and apr_socket_inherit_set, but I'm not sure
> if there's an easy way to get at the appropriate socket to call them
> from your module.  It might need to be done inside the httpd core.  On
> the other hand, I could be wrong, I'm just theorizing at this point.
>
> -garrett
>


--
Ryan Bloom
rbb@apache.org
rbb@rkbloom.net
rbloom@gmail.com

Re: apr_proc_create

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 4/11/06, Mike Behne <md...@yahoo.com> wrote:
>
> I have a question about behavior of a process launched by apr_proc_create
> from within an Apache plugin module on Windows.
>
> The created process is intended to remain running regardless of whether the
> Apache server is running.  I'm noticing that after the process is created,
> and the Apache server is stopped and I attempt to restart it, I get an
> indication that the socket (port 80) is in use and Apache won't start.  Once
> I stop the created process, Apache can successfully start.  I tried a few
> things to change this behavior--apr_procattr_cmdtype_set,
> apr_procattr_detach_set, apr_proc_detach--but no change.  Now I've
> implemented some techniques to take the created proc down when Apache stops
> to avoid the failed restart.  Is there anything I could do differently that
> would allow the created proc to stay up without preventing Apache from
> restarting?

I suspect the problem is that the socket httpd is listening on is set
to be inherited (as you'd expect, since it's created in a parent
process and inherited by worker processes who do the accept), but what
you want is for it to not be inheritted by subsequent child processes.
 There are functions to control this inheritance,
apr_socket_inherit_unset and apr_socket_inherit_set, but I'm not sure
if there's an easy way to get at the appropriate socket to call them
from your module.  It might need to be done inside the httpd core.  On
the other hand, I could be wrong, I'm just theorizing at this point.

-garrett