Launchd 代理未启动

发布于 2024-08-25 04:24:31 字数 1187 浏览 7 评论 0原文

我正在尝试编写一个 launchd 代理,为每个登录 Mac OS X 系统的用户运行一个简单的应用程序。

我创建了一个名为 com.mycompany.myapp.plist 的文件,并将其放置在 /Library/LaunchAgents 中。该文件的内容是:

{
    LimitLoadToSessionType = "Aqua";
    StartInterval = 10;
    OnDemand = NO;
    KeepAlive = YES;
    RunAtLoad = YES;
    Label = "com.mycompany.myapp";
    Program = "/Users/thomi/myapp";
    ProgramArguments = (
        "/Users/thomi/myapp",
        "-l",
        "-d",
    );
}

最初我没有设置 StartInterval 键,因为我认为代理会自动启动。问题是,除非我手动发出以下两个命令,否则代理不会启动:

launchctl load -S Aqua -D all
launchctl start com.mycompany.myapp

此外,当我运行 launchctl list com.mycompany.myapp 时,我会得到以下输出:

{
    "Label" = "com.mycompany.myapp";
    "LimitLoadToSessionType" = "System";
    "OnDemand" = true;
    "LastExitStatus" = 0;
    "TimeOut" = 30;
    "Program" = "/Users/thomi/myapp";
    ProgramArguments = (
        "/Users/thomi/myapp",
        "-l",
        "-d",
    );
};

请注意,LimitLoadToSessionType 参数已更改。

我在这里错过了什么吗?是否有不同的机制来启动这样的代理?为什么 LimitLoadToSessionType 属性发生了变化?

I'm attempting to write a launchd agent that runs a simple application for every user that logs in to the Mac OS X system.

I have created a file named com.mycompany.myapp.plist and placed it in /Library/LaunchAgents. The contents of that file are:

{
    LimitLoadToSessionType = "Aqua";
    StartInterval = 10;
    OnDemand = NO;
    KeepAlive = YES;
    RunAtLoad = YES;
    Label = "com.mycompany.myapp";
    Program = "/Users/thomi/myapp";
    ProgramArguments = (
        "/Users/thomi/myapp",
        "-l",
        "-d",
    );
}

Initially I didn't have the StartInterval key set, since I thought the agent would start automatically. The problem is that the agent does not start unless I manually issue the following two commands:

launchctl load -S Aqua -D all
launchctl start com.mycompany.myapp

Firther, when I run launchctl list com.mycompany.myapp I get the following output:

{
    "Label" = "com.mycompany.myapp";
    "LimitLoadToSessionType" = "System";
    "OnDemand" = true;
    "LastExitStatus" = 0;
    "TimeOut" = 30;
    "Program" = "/Users/thomi/myapp";
    ProgramArguments = (
        "/Users/thomi/myapp",
        "-l",
        "-d",
    );
};

Notice that the LimitLoadToSessionType parameter has changed.

Am I missing something here? Is there a different mechanism to start agents like this? Why has the LimitLoadToSessionType property changed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

标点 2024-09-01 04:24:31

不确定这是否是问题所在,但我认为您不应该同时指定 OnDemand/RunAtLoad 和 KeepAlive 。据我了解文档,KeepAlive 键取代了 OnDemand/RunAtLoad 组合。

http://developer.apple.com/mac/library/ technotes/tn2005/tn2083.html#SECCODINGRECOMMENDATIONS

Not sure if it's the problem, but I think you shouldn't be specifying both OnDemand/RunAtLoad and KeepAlive together. As I understand the documentation, the KeepAlive key replaces the OnDemand/RunAtLoad combo.

http://developer.apple.com/mac/library/technotes/tn2005/tn2083.html#SECCODINGRECOMMENDATIONS

盗琴音 2024-09-01 04:24:31

发现问题 - 显然 launchd 无法与旧式 plist 文件正常工作。它加载正常,但不会运行任何东西。将上述文件重新创建为新样式的 XML 文件解决了该问题。

Found the problem - apparently launchd doesn't work properly with the old-style plist files. It loads OK, but won't run anything. Re-creating the above file as a new-style XML file solved the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文