我试图添加一个在启动时执行的守护进程。我基本上遵循了这个教程。
我制作了一个可以直接执行的 .sh 脚本。制作了一个launchd文件以在启动时运行它,现在想将它添加到launchctl列表中。
执行后sudo launchctl load -w /Library/LaunchDaemons/com.startup.plist
没有任何反应。
守护进程不在launchctl 列表中,但没有抛出错误,也没有在启动时运行。
我正在查看列表sudo launchctl list | grep com.startup
这是我的启动文件:
<?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>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/bin:/usr/bin:/usr/local/bin</string>
</dict>
<key>Label</key>
<string>com.startup</string>
<key>Program</key>
<string>/Users/user/scripts/startup/startup.sh</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
<key>LaunchOnlyOnce</key>
<true/>
<key>StandardInPath</key>
<string>/tmp/test.stdin</string>
<key>StandardOutPath</key>
<string>/tmp/test.stdout</string>
<key>StandardErrorPath</key>
<string>/tmp/test.stderr</string>
</dict>
</plist>
这是我的脚本:
#!bin/bash
# Check if deamon is running
if [ "$(ps -ef | grep -v grep | grep clamd | wc -l)" -le 0 ]
then
#Start deamon
/opt/homebrew/Cellar/clamav/0.104.2/sbin/clamd
echo "clamd started"
else
echo "clamd already running"
fi
有什么建议为什么不将其添加到列表中?
告诉我,如果我可以提供更多信息
LaunchOnlyOnce
编辑:我可以通过删除launchd文件中的标志将它添加到列表中。不幸的是,它仍然没有在启动时运行脚本。我的 launchd 文件中使用的 'standardIn/Out/Err 文件存在,但为空。我错过了什么吗?
有没有办法在echo
任何地方查看我的脚本的输出?