非常简单 Launchd plist 不运行我的脚本
我试图找出为什么我的 launchd
脚本不起作用。这非常简单,但我是 mac 环境的新手,正在努力适应。这是我的清单。我知道 ProgramArguments
是必需的,所以我只是将脚本路径放在那里。
<?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.tomcat.plist</string>
<key>ProgramArguments</key>
<array>
<string>/opt/apache-tomcat-5.5.27/bin/startup.sh</string>
</array>
<key>OnDemand</key>
<false/>
</dict>
</plist>
当我尝试运行 launchctl load
时,它似乎正确加载(因为它不会给我任何错误消息),但脚本似乎没有执行,即使在重新启动。
我已经使用了在网上找到的所有示例,但我无法弄清楚为什么这在启动时没有运行我的脚本。
I'm trying to figure out why my launchd
script is not working. It is extremely simple, but I am new to the mac environment and trying to get accustomed. Here's my plist. I know ProgramArguments
is required, so I just put the script path in there.
<?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.tomcat.plist</string>
<key>ProgramArguments</key>
<array>
<string>/opt/apache-tomcat-5.5.27/bin/startup.sh</string>
</array>
<key>OnDemand</key>
<false/>
</dict>
</plist>
When I try to run launchctl load <name>
it seems to load properly (in that it doesn't give me any error messages), but the script doesn't seem to be executing, even on reboot.
I've used all the examples I've found online and I can't figure out why this isn't running my script on start up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以防万一其他人遇到这个问题,并且他们的 plist 中已经有
RunAtLoad
,我想提供一些额外的解决方案。仔细检查权限以确保您的脚本可执行(查找“x”):
如有必要,修改权限:
还首先直接运行脚本并确保其有效:
如果脚本可执行,并且直接运行良好,请尝试尾随用于调试 launchd 的系统日志:
-f
标志(基本上)持续显示日志的结尾(最新条目)。您可以删除此标志以仅打印日志末尾的快照。如果您使用此标志,您将需要打开一个新终端来运行其他命令。按 CTRL + C 结束尾部会话。有关详细信息:当您完成调试时:
还有其他日志级别。有关详细信息:
如果对脚本或 plist 进行任何更改,请确保重新加载 plist。例如:
如果您只更改了脚本而不是 plist,则只需重新启动 plist:
如果将以下键值添加到 plist:
那么您只需运行:
它将自动重新启动。
如果这些都没有帮助,并且您在 OS X 上设置 Tomcat 时遇到问题,本教程可能会有所帮助。
Just in case anyone else runs across this issue, and already has
<key>RunAtLoad</key><true/>
in their plist, I want to provide some additional solutions.Double check permissions to make sure that your script is executable (look for an 'x'):
Modify permissions if necessary:
Also run the script directly first and make sure it works:
If the script is executable, and runs fine directly, try tailing the system log to debug launchd:
The
-f
flag (basically) continually shows the end (latest entries) of the log. You can remove this flag to just print a snapshot of the end of the log. If you use this flag, you'll need to open a new terminal to run other commands. Press CTRL + C to end the tail session. For more information:When you're finished debugging:
There are other log levels. For more information:
If you make any changes to the script or plist, make sure you reload the plist. For example:
If you ONLY made changes to the script and NOT the plist, you can just restart the plist:
If you add the following key-value to your plist:
Then you can just run:
And it will restart automatically.
If none of this helps, and you're specifically having problems with setting up Tomcat on OS X, this tutorial might be of help.
要使脚本在调用 launchctl load 时自动运行,您需要添加 :-
或者您可以使用 :-
To make your script run automatically when you call launchctl load, you need to add :-
Alternatively you could use :-
虽然我想大多数人不会遇到这个问题,但我认为它值得放在这里,因为我花了近两个小时试图弄清楚为什么
launchd load
尽管返回0
却无法工作代码 > 退出代码。问题很简单。我的
plist
文件的文件扩展名错误(我有“plst
”),并且launchctl
默默地拒绝加载该文件。将扩展名更改为plist
解决了该问题。Although I imagine most people will not have this problem, I figure it is worth putting here since I spent nearly two hours trying to figure out why
launchd load
was not working despite returning a0
exit code.The problem was simple. My
plist
file had the wrong file extension (I had "plst
"), andlaunchctl
was silently refusing to load the file. Changing the extension toplist
resolved the issue.