【问题标题】:launchd doesn't launch my daemonlaunchd 没有启动我的守护进程
【发布时间】:2013-05-24 11:24:59
【问题描述】:

我试图弄清楚为什么我的守护程序没有自动启动(在 Mac 10.8.3 上)。但是,它在其他机器上运行良好。这是我在 /Library/LaunchDaemons/ 下的 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.MyApp.tmsm.launcher</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Library/Application Support/MyApp/tmsmLauncher</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <false/>
    <key>StartInterval</key>
    <integer>60</integer>
  </dict>
</plist>

我在/var/log/system.log 中没有看到任何错误消息。我检查了我的daemonpermissionowner。如果我将我的 plist 放在/System/Library/LaunchDaemons/ 下,它可以在reboot 之后启动。但这对我来说不是一个好的解决方案。如果我使用“launchctl load /Library/LaunchDaemons/com.MyApp.tmsm.launcher”,效果很好。如果我安装了其他商业软件,它是一个守护进程,并且在/Library/LaunchDaemons/ 下有一个 plist,它也无法启动。

/Library/LaunchDaemons/ 下的任何 plist 似乎都没有被系统加载。我还尝试使用命令“launchctl log level debug”打开launchctl 调试级别,但重启后没有更多消息。重启后调试级别是否重置?我可以检查其他日志或配置吗??

谢谢。

【问题讨论】:

  • 请查看作业定义文件。在以下情况下,launchd(8) 将拒绝加载作业: - 作业定义文件可由 groupother 写入 - 作业定义不属于 root(或作业定义中指定的用户) - 作业定义文件名不以.plist结尾
  • 定义文件的权限和所有者正确。 -rw-r--r-- 1 root wheel

标签: macos launchd daemons


【解决方案1】:

我找到了根本原因...这很愚蠢... 我在 /Library/LaunchDaemons/ 下的 plist 的权限是正确的。但是/Library/LaunchDaemons/的权限被修改为755。这就是为什么/Library/LaunchDaemons/下注册的任何守护进程都不能自动加载...

【讨论】:

  • /Library/LaunchDaemons 在我的系统上的权限是 755,它工作正常。我自己没有更改它,所以我假设它是默认值。
  • 在 10.11 上,它们显示默认为 644。
  • 目录必须有 x 位,所以 644 没有意义
【解决方案2】:

尝试使用 -w 参数加载它:sudo launchctl load -w /Library/LaunchDaemons/blablabla.plist。看起来像禁用键中的问题。详情请见man launchctl

如果这不起作用,我建议你在你的守护进程中启用一些日志记录以查看它是否启动(可能它只是立即退出?)

【讨论】:

  • 手动加载我的守护进程(带/不带 -w 参数)很好。系统启动时无法自动加载我的守护进程。我的守护进程在开始时确实有日志,但没有显示。我还使用launchctl list 检查我的守护进程是否已加载,我在列表中看不到我的守护进程。我检查了 /var/db/launchd.db/com.apple.launchd/overrides.plist 中的 Disabled 键,但我在这个 plist 上看不到我的守护进程。
  • 在你的守护进程在系统启动时自动启动之前,你需要先用-w参数加载它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-07
  • 2017-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多