2011-06-13 44 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必要的信息。