Launchd 代理未启动
我正在尝试编写一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定这是否是问题所在,但我认为您不应该同时指定 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
发现问题 - 显然
launchd
无法与旧式plist
文件正常工作。它加载正常,但不会运行任何东西。将上述文件重新创建为新样式的XML
文件解决了该问题。Found the problem - apparently
launchd
doesn't work properly with the old-styleplist
files. It loads OK, but won't run anything. Re-creating the above file as a new-styleXML
file solved the issue.