我正在开发一个应用程序,在本例中是针对 macOS 的。我的应用程序有两个部分:
从 GUI 我可以启动和停止服务。我的问题是我需要在 Mac 启动时启动服务器。使用 LaunchAgents,我必须在用户登录时启动它,但我需要在此之前启动它。
我发现我需要将 .plis 保存在 /Library/LaunchDaemons 中。我做到了,但是当我重新启动计算机时,服务器没有启动。
我检查了我的服务给了我状态 1,所以它没有正确启动。也许失败是在 plist 内部...但我不明白为什么它在 LaunchAgent 中工作而不是在 LaunchDaemons 中工作
我的清单是:
<?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">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.turnoffpc.turnoffpcplist</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/Turn Off PC.app/Contents/Resources/Turn Off PC/Server/dist/turn_off_pc_server.app/Contents/MacOS/turn_off_pc_server</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
要加载服务,我使用以下命令:
#!/bin/bash
# Copiar el archivo plist a /Library/LaunchDaemons/
sudo cp com.turnoffpc.turnoffpcplist.plist /Library/LaunchDaemons/
# Establecer los permisos adecuados
sudo chown root:wheel /Library/LaunchDaemons/com.turnoffpc.turnoffpcplist.plist
sudo chmod 644 /Library/LaunchDaemons/com.turnoffpc.turnoffpcplist.plist
# Descargar y luego cargar el servicio utilizando launchctl
sudo launchctl unload /Library/LaunchDaemons/com.turnoffpc.turnoffpcplist.plist
sudo launchctl load /Library/LaunchDaemons/com.turnoffpc.turnoffpcplist.plist
我检查了该服务是否位于正确的位置
我的应用程序的路径是: /Applications/Turn Off PC.app/Resources/Turn Off PC/Server/dist/turn_off_pc_server.app/Contents/MacOS/turn_off_pc_server 里面
有人看到错误或我做错的事情吗?预先感谢
我尝试了以上所有
最后我用了contaba,这样就解决了