如何在 MacOS 上加载系统范围的守护进程

发布于 2024-08-15 04:15:56 字数 965 浏览 4 评论 0原文

我正在尝试使用此命令加载我的守护程序应用程序 launchctl load /Library/LaunchDaemons/myPlistFileName 它工作正常,但仅当我的用户登录系统时。

我如何加载我的守护程序应用程序,它将在没有任何用户登录系统(如 Windows 服务)的情况下保持加载状态?

命令 sudo launchctl load /Library/LaunchDaemons/myPlistFileName 给我一个错误 -> 没有找到要加载的内容

哪种方法是正确的?


编辑:我的 Plist 文件

<key>Label</key>
<string>com.myCompany.myApplication</string>
<key>ProgramArguments</key>
<array>
    <string>open</string>
    <string>-g</string>
    <string>/Applications/myAppDir/myApplication.app</string>
</array>
<key>UserName</key>
<string>root</string>
<key>GroupName</key>
<string>wheel</string>
<key>KeepAlive</key>
<true/>
<key>OnDemand</key>
<false/>

目前是这样:在系统启动时,我的守护进程以 root 权限启动。当我使用我的用户帐户登录后,守护进程将重新启动,并且我的用户是该进程的新所有者

I'm trying to load my daemon-app with this command launchctl load /Library/LaunchDaemons/myPlistFileName It works fine, but only while my user is logged in on system.

How can i load my deamon-app, which will stay loaded without any user logged into the system (like the windows-services)??

The command sudo launchctl load /Library/LaunchDaemons/myPlistFileName give me an error -> nothing found to load

Which is the right way to do this?


EDIT: My Plist-File

<key>Label</key>
<string>com.myCompany.myApplication</string>
<key>ProgramArguments</key>
<array>
    <string>open</string>
    <string>-g</string>
    <string>/Applications/myAppDir/myApplication.app</string>
</array>
<key>UserName</key>
<string>root</string>
<key>GroupName</key>
<string>wheel</string>
<key>KeepAlive</key>
<true/>
<key>OnDemand</key>
<false/>

Currently it is so: at system-start my daemon starts with root-permissions. After i've logged in with my user-account, the daemon-process restarts and my user is the new owner of the process

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

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

发布评论

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

评论(1

疯了 2024-08-22 04:15:56

使用“sudo launchctl load; sudo launchctl start”或者,在较新版本的 launchctl 上,“sudo launchctl Submit -l <​​label> --[...]”是可行的方法。

在没有实际看到 PLIST 的情况下,很难诊断为什么你的“sudo launchctl”命令失败,但是你应该确保 PLIST 的权限对每个人都是可读的(但只能由 root:wheel 或 root:admin 写入),你应该确保已给出“UserName”和“GroupName”字段,您应该确保“Program”给出了相关程序的绝对路径(例如,不依赖于用户的 PATH 的特定设置)环境变量),并且应正确定义“WorkingDirectory”和“EnvironmentVariables”字段(如果适用)。

另请参阅: man launchd。 plist

编辑:
在尝试执行“sudo ... load”之前,您还可以尝试运行“stop”和“unload”命令。

编辑:
现在您已经上传了 PLIST 文件,很清楚您的问题是什么......以其他用户身份运行时无法使用 open 命令。请参阅以 root 身份运行 OS X GUI 应用程序。另外,我很确定,KeepAlive 和 OnDemand 密钥是免费的。我认为这些可以删除。

Using "sudo launchctl load <name-of-plist-file>; sudo launchctl start <job-name>" or, on newer versions of launchctl, "sudo launchctl submit -l <label> -- <command> [<arg0> ... <argN>]" is the way to go.

It is hard to diagnose why your "sudo launchctl" command failed without actually seeing the PLIST, but you should make sure that the permissions for the PLIST are readable for everyone (but writeable only by root:wheel or root:admin), you should be sure that the "UserName" and "GroupName" fields have been given, you should make sure that "Program" gives an absolute path to the program in question (and does not, for example, rely on the user's particular setting of the PATH environment variable), and the "WorkingDirectory" and "EnvironmentVariables" fields should be properly defined if applicable.

See Also: man launchd.plist

EDIT:
You might also try running the "stop" and "unload" commands before attempting to do the "sudo ... load".

EDIT:
Now that you've uploaded your PLIST file it is clear what your problem is... you cannot use the open command when running as another user. See running OS X GUI app as root. Also, the KeepAlive and OnDemand keys are, I'm pretty sure, gratuitous. I think those can be deleted.

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