【问题标题】:How to check if launchd has started the script?如何检查launchd是否启动了脚本?
【发布时间】:2013-05-18 09:28:48
【问题描述】:

我在我的 mac pro 上将 launchd 配置为每天晚上 18 点启动一个命令,但它不起作用。

我想检查 launchd 是否运行了命令。我尝试了系统控制台,没有发现任何有价值的东西。

我的 mac os 版本是 mac os x 10.8.3

我的 plist 文件:

<?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>mytask</string>
    <key>Program</key>
    <string>/opt/local/bin/node</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/xxx/My/task.js</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>18</integer>
        <key>Minute</key>
        <integer>0</integer>
    </dict>
    <key>StandardOutPath</key>
    <string>/Users/xxx/launchd.stdout.log</string>
    <key>StandardErrorPath</key>
    <string>/Users/xxx/launchd.stderr.log</string>
</dict>
</plist>

【问题讨论】:

标签: launchd


【解决方案1】:

您定义了StartCalendarInterval,因此该作业在加载时已执行并且它将在每天的18:00执行。

查询 launchd(8) 以了解其退出状态:

launchctl list | grep mytask

这将返回一行:

<pid> <status> mytask

pid 是一个数字时,作业当前正在运行。否则看看status,这是程序的退出代码,在你的情况下是节点。退出代码 0 表示程序已成功完成或尚未启动。程序错误返回正数,负数表示作业因信号而终止。

我认为这项工作失败了。您可能需要检查程序标准输出/错误。指定 StandardOutPathStandardErrorPath 来执行此操作。这些文件的内容可能会告诉您程序失败的原因。

【讨论】:

  • 我运行了launchctl list并得到状态0。我将StandardOutPath和StandardErrorPath添加到上面的plist中,但是在我用launchctl start运行任务后没有找到文件。所以我觉得任务似乎还没有开始。
  • 确保在更改后重新加载作业定义(unload,然后是 load)。仅仅修改文件并发出启动命令是不行的。
  • 谢谢。上传并加载任务后,StandardOutPath 和 StandardErrorPath 工作正常。
  • 在我从 plist 中删除“Program”并将 /opt/local/bin/node 移动到 ProgramArguments 之后,任务运行成功,启动启动。
猜你喜欢
  • 2013-05-01
  • 2021-06-07
  • 2022-11-28
  • 2013-10-21
  • 2010-11-20
  • 2016-05-06
  • 2011-09-14
  • 2011-11-03
  • 1970-01-01
相关资源
最近更新 更多