Mac启动守护程序服务正在重复启动我的bash脚本



我一直在设置一个启动守护进程,以便根据需要启动bash脚本。然而,一旦我加载了启动代理并通过套接字进行通信,它就会每10秒运行一次bash脚本。我甚至在plist中将KeepAlive标志设置为false,并在bash脚本中添加了延迟,但它仍然在运行。

当我连接到插座时,如何将其设置为只运行一次。

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">
<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

;"按需";密钥在MacOSX10.4.Tiger中用于控制作业是否保持活动。钥匙不应该再使用了。

将keepalive键设置为false时,默认情况是仅按需启动作业。

最新更新