launchctl无法运行二进制文件,并退出并显示代码78

时间:2019-02-03 13:29:34

标签: macos plist root daemon launchctl

我一直在使用系统托盘GUI构建golang app。我希望launchctl每次登录时都运行我的程序。程序编译并运行时没有任何错误,但是,当launchctl运行它时,我看到的是:Service exited with abnormal code: 78。也许与权利有关。

  • 首先,我尝试将当前用户的权限设置为plist文件和二进制文件。仍然错误78

  • 然后,我将plist文件和二进制文件的权限更改为 root 并运行sudo launchctl。我仍然看到错误78

/var/log/system.log出现以下错误:

14:46:00 Macchiato com.apple.xpc.launchd[1] (com.test.test[519]): Service could not initialize: 18A391: xpcproxy + 11291 [1534][8188841E-6D08-3F80-8488-9B5D7462BACB]: 0xd
14:46:00 Macchiato com.apple.xpc.launchd[1] (com.test.test[519]): Service exited with abnormal code: 78
14:46:00 Macchiato com.apple.xpc.launchd[1] (com.test.test): Service only ran for 0 seconds. Pushing respawn out by 10 seconds.

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>com.test.test</string>
        <key>ProgramArguments</key>
        <array>
                <string>/Users/test-user/test/test</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>ProcessType</key>
        <string>Standard</string>
        <key>KeepAlive</key>
        <true/>
        <key>StandardErrorPath</key>
        <string>/var/log/test-err.log</string>
        <key>StandardOutPath</key>
        <string>/var/log/test-out.log</string>
</dict>
</plist>

错误日志为空。

当我手动运行binary时,应用程序的图标将按预期方式显示在系统托盘上。

有一个有趣的时刻 –如果我手动输入launchctl load -w com.test.test.plist,应用运行良好–直到重新启动。重新启动后,launchctl会引发78错误。

为什么会这样?

1 个答案:

答案 0 :(得分:0)

我想我解决了自己的问题。我使用时似乎出现了错误78

<key>StandardErrorPath</key>
<string>/var/log/test-err.log</string>
<key>StandardOutPath</key>
<string>/var/log/test-out.log</string>

当我删除这些行时,错误消失了。这尤其奇怪,因为plist文件具有root权限,而launchd也以root用户身份运行...