Skip site navigation (1)Skip section navigation (2)
Date:      13 Jun 2002 15:19:20 -0700
From:      Jon Noack <noackjr@compgeek.com>
To:        freebsd-questions@freebsd.org
Subject:   apache and background process silent death
Message-ID:  <20020613221920.26784.cpmta@c015.snv.cp.net>

next in thread | raw e-mail | index | archive | help
I have several Java network processes I need to be able to start and stop
through a web interface.  I am trying to do this with FreeBSD, Apache, and
Perl.  I also need to keep track of the PID (to stop it) and capture STDOUT
and STDERR for logging.  The following Perl snippet seems to do this
(modified from my actual code for conciseness):

if($pid = fork) {
    print "starting at PID $pid\n";
    open PIDFILE,">/var/run/foo.pid";
    print PIDFILE $pid;
    close PIDFILE;
} elsif(defined $pid) {
    #Close STDIN and redirect STDOUT and STDERR to foo.log
    close STDIN;
    exec "/usr/local/bin/sudo",@execArgs,">","/var/log/foo.log","2&>1";
} else {
    die "unable to fork!\n";
}

This succeeds in returning output and finishing via cgi-bin and the Java
process is running.  NOTE: sudo is necessary because the Java processes use
port 80 (on a different IP address from Apache) -- it is setup correctly
(group www has sudo rights to java).  The Java processes and Apache
correctly bind to unique IP addresses.

Everything works fine for a while, but eventually the java process dies a
silent death (nothing in log file, which is capturing STDERR, by the way),
as if Apache was periodically cleaning processes.  If I kill Apache while
the java process is still alive, it also dies silently.  If I run this
script from the command line, everything works perfectly -- I can log off
and on at will and stop/start apache all I want.

I've tried launching it from within PHP, as below, with the same results --
It displays and returns but the process silently dies in a similar manner.

echo "Starting Java Server...<br>";
$startout = `$basepath/startServer`;
echo "<pre>$startout</pre>";

It seems the forked process is still caught in the Apache process space.  Is
this correct?  If so, is there a way around this?

Jon Noack

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020613221920.26784.cpmta>