2015-10-05 80 views
1

我試圖在OSX 10.10.4上使用shell腳本啓動與其關聯項目的無臉服務器應用程序。osx startupitems shell腳本不會啓動應用程序

shell腳本已被設置爲可執行文件。

在啓動時無法啓動Wakanda \ Server.app/Contents/MacOS/Wakanda \ Server。

請幫我做這個工作。

shell腳本在:

Macintosh HD:Library:StartupItems:DispatchStartup:DispatchStartup.sh 

這個shell腳本的內容是:

#!/bin/sh 
. /etc/rc.common 

# The start subroutine 
StartService() { 
    # Insert your start command below. For example: 
    /Applications/Wakanda\ Server.app/Contents/MacOS/Wakanda\ Server --solution=/Applications/Dispatch/Dispatch\ Solution/Dispatch.waSolution 
    # End example. 
} 

# The stop subroutine 
StopService() { 
    # Insert your stop command(s) below. For example: 
    killall -TERM /Applications/Wakanda\ Server.app/Contents/MacOS/Wakanda\ Server 
    sleep 15 
    killall -9 /Applications/Wakanda\ Server.app/Contents/MacOS/Wakanda\ Server 
    # End example. 
} 

# The restart subroutine 
RestartService() { 
    # Insert your start command below. For example: 
    killall -HUP /Applications/Wakanda\ Server.app/Contents/MacOS/Wakanda\ Server 
    # End example. 
} 

RunService "$1" 

// ---------------- -------------------------------------------------- -

//在shell腳本旁邊是StartParameters.plist // ------------------------------- -------------------------------------

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> 
<plist version="0.9"> 
    <dict> 
     <key>Description</key> 
     <string>Wakanda Server</string> 
     <key>OrderPreference</key> 

     <string>Late</string> 
     <key>Provides</key> 
     <array> 
       <string>Web service to database and objects</string> 
     </array> 
     <key>Uses</key> 
     <array> 
       <string>Network</string> 
     </array> 
    </dict> 
</plist> 

回答

1

自OS X v10.4以來,啓動項已被棄用,支持launch daemons,它們似乎最終在v10.10中完全禁用。更好的選擇是...創建一個啓動守護進程。它將成爲/ Library/LaunchDaemons中的一個屬性列表(.plist)文件/包含關於啓動以及啓動時間的指令。

這會比平時稍微複雜一點,因爲launchd系統喜歡跟蹤它啓動的作業,這需要他們不是掉落到背景中,並且我沒有看到任何阻止Wakanda服務器從背景本身。你可以通過向.plist添加指令來避免它活着,並「放棄」它的進程組(即不殺死它產生的剩餘後臺進程)來解決這個問題。有可能也是一個問題,因爲沒有好的方法來告訴它等到網絡啓動。但是,如果它試圖偵聽特定的IP地址或接口,這就成了問題。如果它只是聽取0.0.0.0(即計算機上的所有IP),那麼這不是問題,因爲它只會在接口出現時接收。

我想的.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>Disabled</key> 
     <false/> 
     <key>Label</key> 
     <string>local.wakanda-server</string> 
     <key>ProgramArguments</key> 
     <array> 
       <string>/Applications/Wakanda Server.app/Contents/MacOS/Wakanda Server</string> 
       <string>--solution=/Applications/Dispatch/Dispatch Solution/Dispatch.waSolution</string> 
     </array> 
     <key>RunAtLoad</key> 
     <true/> 
     <key>KeepAlive</key> 
     <false/> 
     <key>AbandonProcessGroup</key> 
     <false/> 
</dict> 
</plist> 

把它放在/Library/LaunchDaemons/local.wakanda-server.plist,設定所有權根:車輪,權限爲644,和然後重新啓動或使用sudo launchctl load /Library/LaunchDaemons/local.wakanda-server.plist手動加載。

+0

戈登,你的答案完美無缺! 很少有人給過我發過來的答案。 謝謝! :-) –

相關問題