【问题标题】:launchctl - remove enabled/disabled overridelaunchctl - 删除启用/禁用覆盖
【发布时间】:2015-09-21 07:01:03
【问题描述】:

在 OS X Yosemite (10.10) 上,有没有办法删除服务的启用/禁用覆盖设置?

例如,要为 root 永久禁用不存在的服务“测试”,请执行以下操作:

sudo launchctl disable user/0/test

检查它是否已被添加到禁用列表中:

sudo launchctl print-disabled user/0

结果:

disabled services = {
    "test" => true
}
login item associations = {
}

现在,如何从禁用服务列表中删除“测试”?

(我知道我可以启用它,但我只想完全删除该条目。)

注意:

如果我重新启动计算机,我会看到“测试”覆盖已添加到 launchd disabled 文件中:

sudo cat /var/db/com.apple.xpc.launchd/disabled.0.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>test</key>
    <true/>
</dict>
</plist>

我已尝试运行此命令从.plist 文件中手动删除它:

sudo /usr/libexec/Plistbuddy /var/db/com.apple.xpc.launchd/disabled.0.plist -c Delete:test

这确实会从文件中删除它,但是当我重新启动计算机时它又会再次出现。有什么想法吗?

【问题讨论】:

标签: osx-yosemite launchd launchctl


【解决方案1】:

我刚刚在优胜美地上用 LaunchControl 解决了这个问题…… 它必须具有令人惊叹的小 GUI,用于在 OSX 上管理您的守护进程和代理。 它有很多功能…… 所以只需用木桶安装它

$ brew cask install launchcontrol

然后在左侧列表中找到您的服务(在 Use Agents 或 Global Daemons 或其他...下)。

选择它并在主菜单中转到 Job=>Override Disabled key=>Always False

然后重新启动并检查... 应该可以!

【讨论】:

  • 您所描述的是如何使用 LaunchControl 永久启用服务。这不是海报所要求的。他正在寻找的是 Job>Override Disabled Key>Don't Override,这在 OSX Yosemite 上还不起作用。
  • @LCC 我将此错误/我的解决方案报告给了 LaunchControl 的开发者 support@soma-zone.com(它很厉害)
  • @LCC BTW,开发人员报告了won't fix/can't fix 状态回复:此un-feature。 ?
  • 也许值得注意的是 LaunchControl (soma-zone.com/LaunchControl) 是商业软件,需要付费许可证才能保存更改。 Lingon (peterborgapps.com/lingon) 是相同的另一种选择,也需要购买许可证。
【解决方案2】:

过去overrides.plist 中的信息的性质似乎发生了变化..

根据launchctlman 页面的“旧版”load / unload 子命令..

-w 覆盖 Disabled 键并将其分别设置为 false 或 true 用于加载和卸载子命令。在以前的版本中,此选项会修改配置文件。现在 Disabled 键的状态存储在磁盘上的其他位置,除了 launchd 之外的任何进程都不能直接操作。

我想现在...信息存储在/var/db/com.apple.xpc.launchd目录中。

我的内容包含几个 plist。

config disabled.0.plist disabled.200.plist ... disabled.501.plist ... disabled.migrated loginitems.0.plist ... loginitems.501.plist ...

在这种情况下,文件名指的是不同用户的 id(501mine0root)。更改这些文件中的键(显然是 root)应该使用 dark-overlord launchd 删除相应的覆盖。

如果没有,请尝试在引导至恢复或其他驱动器时编辑这些相同的文件 - 这样您就可以在 launchd 没有运行/无情地试图成为老板时弄乱它们。

【讨论】:

  • 'dark-overlord launchd'... 太好了。 +1 散文。
【解决方案3】:

我可以使用单用户模式做到这一点。步骤是:

  1. 关闭您的计算机。
  2. 在启动时,进入单用户模式(Command + S)。
  3. 从命令行输入/sbin/mount -uw /
  4. 编辑适当的/var/db/com.apple.xpc.launchd/disabled.*.plist 文件,根据需要删除禁用的项目。
  5. 输入exit

【讨论】:

    【解决方案4】:

    “launchctl”使用的配置文件/脚本位于:

    # Location of the LaunchAgents which run under the user own name (and is logged in).
    $ cd $HOME/Library/LaunchAgents
    
    # Location for the Deamons for running jobs without logged in user.
    $ cd /Library/LaunchDaemons
    
    # Location for the LaunchAgents which run as root when the user is logged in.
    $ cd /Library/LaunchAgents
    

    以下用于 XML 脚本(以 .plist 结尾)的快捷命令是(假设您位于上述目录之一并且您可能需要 sudo):

    # Loads the specified configuration file.  
    # Jobs that are not on-demand will be started as soon as possible.
    $ The -w option overrides the disabled setting.
    # The -F option forces the loading and ignores the Disabled key.
    $ launchctl load <script-name.plist>
    
    # Unloads the specified configuration file from the current started session.
    $ The -w option overrides the disabled setting.
    # The -F option forces the loading and ignores the Disabled key.
    $ launchctl unload <script-name.plist>
    
    # Removes the specified configuration from the list and does not appear after rebooting
    $ launchctl remove <script-name.plist>
    

    有关详细信息,请参阅 https://ss64.com/osx/launchctl.html 的 launchctl 手册页。

    【讨论】:

      猜你喜欢
      • 2013-08-25
      • 1970-01-01
      • 2022-01-07
      • 2015-02-02
      • 1970-01-01
      • 2021-09-06
      • 1970-01-01
      • 2021-12-31
      • 2019-02-20
      相关资源
      最近更新 更多