linux - 如何重定向 Debian 上以 start-stop-daemon 启动的进程的进程输出?

标签 linux bash logging debian start-stop-daemon

关于这个已经有几个问题,但似乎没有一个有效。我有一个当前已关闭的生产系统,我需要能够快速从守护程序获取 stderr 输出以对其进行调试。

我以为我可以从它被调用的点(在 init.d 脚本中)重定向输出,但事实证明这非常困难。

 start-stop-daemon -d $DDIR -b -m --start --quiet -pidfile $PIDFILE --exec $DAEMON -- \
                $DAEMON_ARGS > /var/log/daemon.log 2>&1 \
                || return 2

这是行不通的。我尝试运行一个调用可执行文件并重定向输出的 shell 脚本,但日志文件仍然为空(我知道该进程正在输出信息)。

如有任何帮助,我们将不胜感激。

最佳答案

如果您有 start-stop-daemon >= version 1.16.5,您只需使用 --no-close 调用它即可重定向 started 过程。

来自 man start-stop-daemon:

-C, --no-close

          Do not close any file descriptor when forcing the daemon into
          the background (since version 1.16.5).  Used for debugging
          purposes to see the process output, or to redirect file
          descriptors to log the process output.  Only relevant when
          using --background.

关于linux - 如何重定向 Debian 上以 start-stop-daemon 启动的进程的进程输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12787768/

相关文章:

regex - 带有正则表达式的 Bash 脚本在 Ubuntu 上不起作用

java - log4j2 错误无法识别的格式说明符 [t]

c++ - g++ 链接到外部库创建 undefined reference

linux - AWS 参数存储 - 如何在 Node App 中使用 Linux 访问值

bash - 如何在shell脚本中找到2个文件之间的差异

python - 在 python 中使用 WSL bash

java - 根据文件大小和时间回滚日志

eclipse - 如何为 Wildfly 的日志着色 - Eclipse 上的 Jboss Server 控制台

linux - 循环 Linux Shell 的空主体

python - 为什么远程部署路径中的 $PATH 与远程系统中的 $PATH 不同?