我一直在设置一个启动守护进程,它可以按需启动一个 bash 脚本。但是,一旦我加载启动代理并通过套接字进行通信,它就会每 10 秒运行一次我的 bash 脚本。我什至在 plist 中将 KeepAlive 标志设置为 false 并在 bash 脚本中添加了延迟,但它仍然继续运行。
当我与套接字连接时,如何将其设置为仅运行一次。
列表文件:
<?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.example.test.helper</string>
<key>Program</key>
<string>/Library/Application Support/test/testexec</string>
<key>ProgramArguments</key>
<array>
<string>/Library/Application Support/test/testexec</string>
</array>
<key>OnDemand</key>
<true/>
<key>KeepAlive</key>
<false/>
<key>Sockets</key>
<dict>
<key>MasterSocket</key>
<dict>
<key>SockFamily</key>
<string>Unix</string>
<key>SockPathMode</key>
<integer>438</integer>
<key>SockPathName</key>
<string>/var/run/com.example.test.helper.socket</string>
<key>SockType</key>
<string>Stream</string>
</dict>
</dict>
</dict>
</plist>
bash 脚本文件:
#!/bin/bash
FILE_PATH="/var/log/test.log"
print()
{
echo "$(date +"%m-%d %T") $1" >> $FILE_PATH
}
/bin/rm -r "/private/var/test"
retcode=$?
print "rm returncode: $retcode"
if [ $retcode -ne 0 ];
then
print "The removing failed"
fi
sleep 15