2011-06-13 95 views
9

我有一些自制的Launchd脚本。但是我有当我重新启动我的电脑手动运行它们:如何调试启动时不运行的Launchd脚本?

launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.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> 
    <true/> 
    <key>Label</key> 
    <string>com.mysql.mysqld</string> 
    <key>Program</key> 
    <string>/Users/dash/.local/Cellar/mysql/5.1.49/bin/mysqld_safe</string> 
    <key>RunAtLoad</key> 
    <true/> 
    <key>UserName</key> 
    <string>dash</string> 
    <key>WorkingDirectory</key> 
    <string>/Users/dash/.local/var</string> 
</dict> 
</plist> 

我想这应该发生在启动时。我错过了什么?

+0

我不认为这会有任何效果(因此,我没有把它作为答案),但尝试运行它没有测试的“-w”标志(即“launchctl加载〜/ Library/LaunchAgents /com.mysql.mysqld.plist“),然后重新启动。或者,也许试试plist的完整文件路径(例如/Users/{you}/Library/LaunchAgents/com.mysql.mysqld.plist)。只是在这里猜测。 – 2011-07-31 03:10:05

+1

不是一个真正的答案,但我确信[LaunchControl](http://www.soma-zone.com/LaunchControl)会告诉你为什么。 – LCC 2013-09-05 14:30:03

+0

查看我的[回复](http://stackoverflow.com/a/15820488/711807)到类似的问题。 – 2014-05-27 00:22:49

回答

2

一种可能性:看目录:

/private/var/db/launchd.db/ 

和精细的文件,您的用户 “com.apple.launchd.peruser ###”。打开并查看是否有类似的条目:

<key>com.mysql.mysqld.plist</key> 
<dict> 
    <key>Disabled</key> 
    <true/> 
</dict> 

如果是这样,尝试将其设置为<false/>。另一个文件寻找同样的事情是:

/private/var/db/launchd.db/com.apple.launchd/overrides.plist 
+0

这看起来很有希望,但唉,它是'' – 2011-07-31 04:08:42

+0

也许尝试一起切割出来?我不明白这会有什么不同,但我正在抓秸秆。 – 2011-07-31 12:47:22

0

尝试重命名它。更改文件名:

~/Library/LaunchAgents/com.mysql.mysqld2.plist 

,并在plist中的标签部分:

<key>Label</key> 
<string>com.mysql.mysqld2</string> 

如果您保存一个备份副本,请务必将其移动你的〜/库/ LaunchAgents /目录之外的。

最后,不要使用launchctl加载它,只需注销并重新登录即可。这将让launchd自己从“LaunchAgents”目录中选取它并从混合中取出另一个变量(即launchctl)。

12

最好的办法,我发现调试,在你的plist:

<key>StandardErrorPath</key> 
<string>/tmp/mycommand.err</string> 
<key>StandardOutPath</key> 
<string>/tmp/mycommand.out</string> 

打开控制台应用程序,在“全部消息”你应该看到条目时,您的应用程序失败或成功。就像这样:

4/28/15 10:43:19.938 AM com.apple.xpc.launchd[1]: (mycommand[18704]) Service exited with abnormal code: 1 

我的问题是与ProgramArguments挂帅的每个项目在数组中<string>项目。

编辑: 在我的情况下,生成一个简单的外壳脚本包装工作得更好。 此脚本设置基本文件夹结构以将shell脚本创建为OS X“应用程序” - https://gist.github.com/mathiasbynens/674099。这可能对您的mysql -u arg1命令更好。

0

的启动指令要求的工作标签,因为它的参数,所以你会使用以下启动它...

launchctl start com.myfile.hostname.plist 

要停止,只需执行下列操作...

launchctl stop com.myfile.hostname.plist 

完成所有测试后,您将注销然后加载它,或者如果您的plist文件位于用户库文件夹中,请键入以下内容...

launchctl load ~/Library/LaunchAgents/com.myfile.hostname.plist 
-1

回答这个对于未来的Google

你正在寻找的命令是

sudo tail -F /var/log/system.log | grep --line-buffered \ 
"com.apple.launchd\[" | grep "com.example.app" 

如果没有调试帮助,然后简单地添加StandardOutPathStandardErrorPath钥匙给您* .plit文件并检查日志:

<key>StandardOutPath</key> 
<string>/tmp/test.stdout</string> 
<key>StandardErrorPath</key> 
<string>/tmp/test.stderr</string> 

检查了这一点http://www.launchd.info/

提供所有有关配置/故障排除有关的launchd必要的信息。