【问题标题】:macOS launchd fails to redirect stdout to the file after log rotationmacOS launchd 在日志轮换后无法将标准输出重定向到文件
【发布时间】:2022-07-30 07:52:42
【问题描述】:

我使用launchd 配置服务以将日志写入文件。 这是已启动的配置。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>my.label</string>
    <key>ProgramArguments</key>
    <array>
        <string>/path/to/binary</string>
        <string>param</string>
    </array>
    <key>KeepAlive</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/path/to/logfile.log</string>
    <key>StandardOutPath</key>
    <string>/path/to/logfile.log</string>
    <key>UserName</key>
    <string>root</string>
</dict>
</plist> 

我使用 newsyslog 来轮换上面目录中的日志。然后是 newsyslog 配置行

/path/to/logfile.log 644 10 10000 * Z

newsyslog 能够轮换日志。但是,在轮换之后,launchd 不再写入日志文件。日志文件中的最后一个日志行是。 newsyslog[2662]: logfile turned over due to -F request. 是bug还是用法有问题?

【问题讨论】:

    标签: macos launchd launchctl


    【解决方案1】:

    这可能是一个愚蠢的问题,但是您的脚本会在轮换日志之前停止服务吗?

    在我看来很明显,您需要在轮换日志之前停止服务,然后再重新启动服务。

    您可以在安排服务时调整开始/停止时间。

    更强大的是从您的日志轮换脚本中启动和停止它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-09
      • 2010-10-14
      • 1970-01-01
      • 2015-05-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多