非常简单的启动plist无法运行我的脚本 [英] VERY simple Launchd plist not running my script

查看:218
本文介绍了非常简单的启动plist无法运行我的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚为什么我启动的脚本不起作用.这非常简单,但是我对Mac环境是陌生的,并且试图习惯.这是我的清单.我知道ProgramArguments是必需的,所以我只将脚本路径放在其中.

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>

当我尝试运行launchctl load <name>时,它似乎可以正确加载(因为它不会给我任何错误消息),但是该脚本似乎没有执行,即使在重新启动时也是如此.

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.

推荐答案

以防万一其他人遇到此问题,并且在其plist中已经包含<key>RunAtLoad</key><true/>,我想提供一些其他解决方案.

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.

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

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

必要时修改权限:

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

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

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

完成调试后:

sudo launchctl log level error

还有其他日志级别.有关更多信息:

There are other log levels. For more information:

man launchctl

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

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

如果仅更改脚本而不更改plist,则只需重新启动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

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

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

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

然后您可以运行:

launchctl stop com.tomcat.plist

它将自动重新启动.

如果以上方法均无济于事,并且您在OS X上设置Tomcat时特别遇到问题,请

If none of this helps, and you're specifically having problems with setting up Tomcat on OS X, this tutorial might be of help.

这篇关于非常简单的启动plist无法运行我的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆