在 OSX 上使用 launchctl 启动和停止服务似乎很棒,但是我无论如何都看不到检查返回值以确保它确实启动了。即使服务无法启动,返回值似乎总是归零
此 plist 文件包含错误,因此不会按预期启动 Drizzle
% launchctl start /Library/LaunchDaemons/org.drizzlebad.plist
% echo $?
0
除了检查此服务的 pid 文件是否存在之外,还有什么建议吗?
你一定是做错了什么,因为launchctl
成功时只返回 0:
$ launchctl start foobar
launchctl start error: No such process
$ echo $?
1
此外,launchctl start
获取职位(通常是反向 DNS 样式的名称),而不是 plist 的路径。它launchctl load
采用unload
plist 路径。
如果您坚持认为它对您不起作用,您可以尝试仅使用 grepping 的输出来launchctl list
获取您的工作名称,并在必要时解析字段。
when you do a launchctl list
from the terminal, you'll notice - in the second column... there is a list of mostly 0's and -'s... if your program exited incorrectly, it will show the exit code in that second column.... usually a -1 or sometimes a -251, or whatever the case may be... and remember... just cause your launchd item might have crashed... launchctl may still feverishly be trying to "make it work" - every 10 seconds..... so don't let a borked launchd process linger forever, as it definitely impacts performance..
unload it with a -w.... and the full path to the plist, or at least stop (and optionally remove it) with the bundle identifier. -w will make a clandestine entry in a plist in your /var/db/launchd folder, telling the kernel not to load it next time the machine boots.. irrespective of what the "enabled" XML entry may say in the Plist.... so beware that there is more than just that flag at play as to whether the item is resurrected the next time you startup...
if you want you can back up that overrides.plist file deep in tat var folder and start over if it has gotten too convoluted with loads and unloads over time... there's other ways to do it, but i'm going to shut up now.. before I incidentally instruct you how to completely hose your computer...