launchd 状态 78 是什么意思?为什么我的用户代理不是 运行?

what does launchd status 78 mean?? why my user agent not running??

我想在每次登录时运行后台同步服务运行。但是我代理的状态码是78。我不知道为什么,我尝试了网上发布的一些修复程序,但它就是不起作用。

有什么问题??下面是我的服务的 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>syncmyproject</string>
    <key>StandardOutPath</key>
    <string>/var/log/syncmyproject.log</string>
    <key>StandardErrorPath</key>
    <string>/var/log/syncmyproject.log</string>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>Debug</key>
    <true/>
    <key>EnableGlobbing</key>
    <true/>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/local/bin/unison</string>
      <string>-auto</string>
      <string>-batch</string>
      <string>-repeat watch</string>
      <string>~/home/project</string>
      <string>~/project</string>
    </array>
</dict>
</plist>

我看了man launchctl,发现78就是function not implemented。没什么用。

终于成功了,其实plist里面有错误,我推荐安装brew install --cask launchcontrol,这是一个launchctl的gui工具,它可以帮助检测错误和排除故障。

我在尝试 运行 单声道启动本地网络服务器时遇到此错误。结果发现修复是不使用 "which mono"(这是一个符号链接:/Library/Frameworks/Mono.framework/Versions/Current/Commands/mono)给出的单声道路径,而是使用 exe 的实际位置(在我的例子中是 /Library/Frameworks/Mono.framework/Commands/mono)。

[运行 也遇到了这个问题,所以记录下我发现的内容]

“78”是您 运行 工作的最后退出代码。来自 man launchctl:

With no arguments, list all of the jobs loaded into launchd in three columns. The first column displays the PID of the job if it is run- ning. The second column displays the last exit status of the job. If the number in this column is negative, it represents the negative of the signal which stopped the job. Thus, "-15" would indicate that the job was terminated with SIGTERM. The third column is the job's label. If [label] is specified, prints information about the requested job.

即无论您要开始什么工作,您都需要阅读文档(或源代码)。 (在我的例子中,mysqld)

值得注意的是,“78”在 Linux 中作为 standard exit code 提及,表示配置错误。因此,请查看您的作业配置(和错误日志?),看看您是否配置有误。

我发现错误与权限有关。 我试图将错误和日志重定向到我的用户无法写入的 /var/log 目录。 将路径更改为我的用户具有适当权限的 r+w 修复它。

另外,加载 LaunchAgent 时要小心。如果您在 ~/Library/LaunchAgents 目录中,请不要使用 sudo 加载 plist。

这是吸引我的地方:在 Mac OS X 中你可以从命令行 运行 shell-scripts 即使有 "just the script"文件。 但是,当您从 launchd 运行 它们时,您必须告诉哪个二进制文件应该 运行 脚本。 假设当你从命令行 运行 时,它只使用你当前所在的 shell(在我的例子中是 bash),但是当 运行ning 从 launchd 有没有 "surrounding script"。 我添加了

#!/bin/sh

作为脚本文件的第一行,然后它起作用了。

与上面类似,我的状态为 78,因为我的脚本路径中有符号链接。解决方法是使用绝对路径。

要查看所有错误代码的说明,请键入

launchctl error <insert numerical error code here>

例如:

% launchctl 错误 77 77: 没有可用的锁

由于 xml 格式问题,我一直在获取 78 代码:

起初,我的 emacs 会像这样自动重新格式化我的 xml:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>user.eric.g.autosyncdropbox.agent</string>
    <key>ProgramArguments</key>
    <array>
      <string>/Users/eric/G/bin/fswatchG.sh</string>
    </array>
    <key>KeepAlive</key>
    <true />
    <key>StandardOutPath</key>
    <string>
    /Users/eric/.tmp/user.eric.g.autosyncdropbox.out.log</string>
    <key>StandardErrorPath</key>
    <string>
    /Users/eric/.tmp/user.eric.g.autosyncdropbox.error.log</string>
  </dict>
</plist>

而且我没能找到返回的这两行...

    <string>
    /Users/eric/.tmp/user.eric.g.autosyncdropbox.out.log</string>
    <key>StandardErrorPath</key>
    <string>
    /Users/eric/.tmp/user.eric.g.autosyncdropbox.error.log</string>

那太糟糕了,绝对是在浪费生命...

在我的例子中,<ProgramArguments> 中的脚本不可执行,因此得到 78 function not implemented.

status 78错误我追了好久

我的 LaunchDamon 可以手动启动,状态为 0,但在系统重启后它 状态为 78。有时守护进程是 运行,有时不是。

在这种情况下,使用应用程序 LaunchControl(这很棒)没有帮助。 标准输出和错误文件中没有输出。

我可以通过向守护进程添加 KeepAlive 条件来解决问题 plist 文件,引用守护进程可执行文件所在的挂载文件系统。

<key>KeepAlive</key>
<dict>
    <key>PathState</key>
    <dict>
    <key>/Volumes/MountedFileSystem</key>
    <true/>
    </dict>
</dict>

我希望这个提示可能对某人有所帮助。