linux - Proc::Daemon with mod_perl 不写入 STDOUT 或 STDERR

标签 linux perl apache2 mod-perl2 mod-perl-registry

因此我在 mod_perl 脚本中使用 Proc::Daemon:

$bindir、$ddir 是可执行文件/日志文件位置,$jid 是每个进程的唯一标识符(以避免多个进程打开同一个文件)。 $cmd 加载了任意 perl 脚本和参数。

   my $daemon = Proc::Daemon->new (
            work_dir        => $bindir,
            child_STDOUT    => $ddir.'/'.$jid.'_stdout.log',
            child_STDERR    => $ddir.'/'.$jid.'_stderr.log',
            pid_file        => $ddir.'/'.$jid.'_pid.txt',
            exec_command => $cmd,
    );

    my $pid = $daemon->Init();

当 Apache 与 cgi 脚本(无 mod_perl)一起使用时,上面的代码工作正常。在“$cmd”进程中,打印打印STDERR日志到上面定义的日志文件。

当我在 Ubuntu Linux 14.04 LTS 上使用 Apache2 使用 mod_perl2 运行上面的命令时,pid 文件被写入 PID 并创建了上面的日志文件,但没有任何内容被写入日志文件。我能够在 $cmd 中打开新文件描述符并写入它们,但在 mod_perl 下,它不会将输出发送到 child_STDOUT 和 child_STDERR 文件。

我想我遗漏了一些非常明显的东西。有没有其他人以前见过这个,或者有任何建议让它在 mod_perl 中工作。

附加信息 在 Apache 中使用 mpm_prefork 模块

相关的 Apache 配置

    <Files "*.pl">
            # SetHandler cgi-script # It works if I use cgi-script
            SetHandler perl-script
            PerlOptions -SetupEnv # Tried with and without this
            # PerlHandler ModPerl::RegistryPrefork # Using this made no difference
            PerlHandler ModPerl::Registry

    </Files>

最佳答案

好吧,有很多解决方案都不起作用这就是我最终要做的。我创建了一个名为 launchjob.pl 的脚本:

#!/usr/bin/perl -w

use strict;
use warnings;

use POSIX 'setsid';
use Proc::Daemon;

my $bindir = $ARGV[0];
my $ddir = $ARGV[1];
my $jid = $ARGV[2];
my $cmd = $ARGV[3];

setsid or die "Cannot start a new session: $!";

my $daemon = Proc::Daemon->new (
                work_dir        => $bindir,
                child_STDOUT    => $ddir.'/'.$jid.'_stdout.log',
                child_STDERR    => $ddir.'/'.$jid.'_stderr.log',
                pid_file        => $ddir.'/'.$jid.'_pid.txt',
                exec_command => $cmd,
             );

my $pid = $daemon->Init();

exit 1;

我在主线中替换了调用 Proc::Daemon 的代码:

以下无效。 Proc::Daemon 给了我一个 sh: No such file or directory 错误。

system('launchjob.pl', $bindir, $ddir, $jid, $cmd);

相反,我使用了似乎按预期运行的以下内容。

使用 IPC::Run3; run3("launchjob.pl ".$bindir."".$ddir."".$jid."".$cmd);

这似乎已经解决了问题。

关于linux - Proc::Daemon with mod_perl 不写入 STDOUT 或 STDERR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39381138/

相关文章:

linux - Linux 中的 Ffmpeg 错误

linux - 为什么 HashiCorp 的 Vault 需要启用 ipc_lock 功能?

linux - 无法在 VIM 中设置配色方案

Perl 的自动分割功能与就地编辑

PHP 通知 : A non well formed numeric value encountered in/var/www/zephyr/library/XenForo/Application. php on line 1534

amazon-web-services - AWS 颁发的证书连接到 EC2 实例

python - lightdm启动脚本使用curses更改树莓派上的区域设置

perl - Perl 5 有哪些可用的编译器/解释器?

perl - Starman 和 MovableType 5.2

django - 无法连接到 gmail smtp linode django apache2 安装程序