非常简单 Launchd plist 不运行我的脚本

发布于 2024-08-03 21:21:22 字数 849 浏览 9 评论 0原文

我试图找出为什么我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

自此以后,行同陌路 2024-08-10 21:21:22

以防万一其他人遇到这个问题,并且他们的 plist 中已经有 RunAtLoad ,我想提供一些额外的解决方案。

仔细检查权限以确保您的脚本可执行(查找“x”):

ls -l /opt/apache-tomcat-5.5.27/bin/startup.sh

如有必要,修改权限:

chmod +x /opt/apache-tomcat-5.5.27/bin/startup.sh

还首先直接运行脚本并确保其有效:

/opt/apache-tomcat-5.5.27/bin/startup.sh

如果脚本可执行,并且直接运行良好,请尝试尾随用于调试 launchd 的系统日志:

sudo launchctl log level debug 
tail -f /var/log/system.log

-f 标志(基本上)持续显示日志的结尾(最新条目)。您可以删除此标志以仅打印日志末尾的快照。如果您使用此标志,您将需要打开一个新终端来运行其他命令。按 CTRL + C 结束尾部会话。有关详细信息:

man tail

当您完成调试时:

sudo launchctl log level error

还有其他日志级别。有关详细信息:

man launchctl

如果对脚本或 plist 进行任何更改,请确保重新加载 plist。例如:

launchctl unload ~/Library/LaunchAgents/com.tomcat.plist
launchctl load ~/Library/LaunchAgents/com.tomcat.plist

如果您只更改了脚本而不是 plist,则只需重新启动 plist:

launchctl stop com.tomcat.plist
launchctl start com.tomcat.plist

如果将以下键值添加到 plist:

<key>KeepAlive</key>
<true/>

那么您只需运行:

launchctl stop com.tomcat.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'):

ls -l /opt/apache-tomcat-5.5.27/bin/startup.sh

Modify permissions if necessary:

chmod +x /opt/apache-tomcat-5.5.27/bin/startup.sh

Also run the script directly first and make sure it works:

/opt/apache-tomcat-5.5.27/bin/startup.sh

If the script is executable, and runs fine directly, try tailing the system log to debug launchd:

sudo launchctl log level debug 
tail -f /var/log/system.log

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:

man tail

When you're finished debugging:

sudo launchctl log level error

There are other log levels. For more information:

man launchctl

If you make any changes to the script or plist, make sure you reload the plist. For example:

launchctl unload ~/Library/LaunchAgents/com.tomcat.plist
launchctl load ~/Library/LaunchAgents/com.tomcat.plist

If you ONLY made changes to the script and NOT the plist, you can just restart the plist:

launchctl stop com.tomcat.plist
launchctl start com.tomcat.plist

If you add the following key-value to your plist:

<key>KeepAlive</key>
<true/>

Then you can just run:

launchctl stop com.tomcat.plist

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.

近箐 2024-08-10 21:21:22

要使脚本在调用 launchctl load 时自动运行,您需要添加 :-

<key>RunAtLoad</key>
<true/>

或者您可以使用 :-

launchctl start com.tomcat.plist

To make your script run automatically when you call launchctl load, you need to add :-

<key>RunAtLoad</key>
<true/>

Alternatively you could use :-

launchctl start com.tomcat.plist
攒一口袋星星 2024-08-10 21:21:22

虽然我想大多数人不会遇到这个问题,但我认为它值得放在这里,因为我花了近两个小时试图弄清楚为什么 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 a 0 exit code.

The problem was simple. My plist file had the wrong file extension (I had "plst"), and launchctl was silently refusing to load the file. Changing the extension to plist resolved the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文