1

我创建了一个如下所示的 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\">
<!-- My version "1.2.3" -->
<plist version=\"1.0\">
<dict>
<key>Disabled</key>
<false/>
<key>Label</key>
<string>MyPlistName</string>
<key>ProgramArguments</key>
<array>
<string>MyDaemonBinPath</string>
<string>-log</string>
<string>MyLogLevel</string>
<string>-launchd</string>
</array>
<key>Sockets</key>
<dict>
<key>Listeners</key>
<dict>
<key>SockFamily</key>
<string>Unix</string>
<key>SockPathMode</key>
<integer>438</integer>
<key>SockPathName</key>
<string>MySocketName</string>
</dict>
</dict>
<key>StandardErrorPath</key>
<string>MySTDERRLogPath</string>
<key>WaitForDebugger</key>
<false/>
<key>inetdCompatibility</key>
<dict>
<key>Wait</key>
<false/>
</dict>
</dict>
</plist>

我把它放在 /Library/LaunchDaemons

然后我运行命令:

/bin/launchctl unload /Library/LaunchDaemons/MyPlistName.plist
/bin/launchctl load /Library/LaunchDaemons/MyPlistName.plist

当我连接到 plist 中指定的套接字并键入以下内容时,我的守护程序会启动:

launchctl list

守护程序已注册,但是当我注销并重新登录并再次询问列表时,它不再注册,我无法通过连接到套接字来启动我的守护程序

是否需要在 plist 或守护程序上设置一些特殊权限才能使其在会话之间持续存在?

4

1 回答 1

0

你检查过你/var/log/system.log的错误吗?常规 plist 在/Library/LaunchDaemons/启动时以 root 身份运行。您可能想检查sudo launchctl list它们是否运行。如果没有,您可能需要更改 plist 的所有权/读写属性以匹配根目录。最后,您可以包括以下内容来改进日志记录:

<key>StandardErrorPath</key>
  <string>/logs/launchd_myprogram_stderr.log</string>
<key>StandardOutPath</key>        
  <string>/logs/launchd_myprogram_stdout.log</string>
于 2013-03-14T22:40:54.337 回答