我正在尝试在我的 Mac(OSX 10.8.2 Mountain Lion)上每小时运行一个节点脚本。根据排名靠前的搜索结果,最好的方法是添加launchd启动代理。
出于某种原因,它似乎不起作用。
我编写了以下启动代理文件并将其保存为~/Library/LaunchAgents/agenttest.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>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
<string>protocol</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/node</string>
<string>/Users/snorpey/PATH/TO/file.js</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>3600</integer>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
我通过launchctl load ~/Library/LaunchAgents/agenttest.plist在终端中运行来启动启动代理。
我还使脚本文件可执行,sudo chmod -x /Users/snorpey/PATH/TO/file.js并使用sudo chmod 777 /Users/snorpey/PATH/TO/file.js.
当我/usr/local/bin/node /Users/snorpey/PATH/TO/file.js在终端中运行时,脚本运行良好。
但是,它在运行时似乎不起作用launchd。我收到以下消息/var/log/system.log:
Jan 15 22:32:46 snorpey com.apple.launchd.peruser.501[595] (agenttest[21625]): Exited with code: 1
Jan …Run Code Online (Sandbox Code Playgroud)