in reply to Proc::Daemon not detaching

Hi Dave,

I used to start daemons with Apache 1.x.x, but those days seem over. With Apache 2.x.x, I have not been able to do this. Maybe there is a Apache configuration parameter to allow this, but I have had to change a lot of cgi scripts because of this.

My solution was to start a long running daemon before or at Apache startup that monitors a file for commands from the cgi scripts. This daemon does not execute the commands, but forks a copy to execute the command. Note: Make sure you put a 'sleep' or 'usleep' in the test loop.

Apache2 doesn't know the daemon exists, and it works.

Regards...Ed

"Well done is better than well said." - Benjamin Franklin

Replies are listed 'Best First'.
Re^2: Proc::Daemon not detaching (exec perl)
by tye (Sage) on Mar 20, 2014 at 14:53 UTC

    If the problem is Apache's doing, then you should first get Apache out of your hair before you daemonize. That will prevent Apache from having replaced fork() or POSIX::setsid() or other shenanigans that I wouldn't put past them.

    if( ! @ARGV ) { # CGI code here my $pid = CORE::fork(); die "Can't fork: $!\n" if ! defined $pid; exit # or return, or whatever makes most sense to finish CGI p +art if $pid; CORE::exec( 'perl', $0, 'daemon' ); die "Can't exec perl: $!\n"; } # Rest of code here

    - tye