[英]osx startupitems shell script does not launch application
我正在嘗試使用OSX 10.10.4上的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>
自OS X v10.4起,不推薦使用啟動項,而希望使用啟動守護程序 ,並且它們似乎最終在v10.10中被完全禁用。 更好的選擇是...創建一個啟動守護進程。 這將是/ Library / LaunchDaemons /中的屬性列表(.plist)文件,其中包含有關啟動什么以及何時啟動的說明。
這將比平常復雜一些,因為已啟動的系統喜歡跟蹤已啟動的作業,這要求它們不要掉入后台,並且我認為沒有任何阻止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中,將所有權設置為root:wheel,權限設置為644,然后使用sudo launchctl load /Library/LaunchDaemons/local.wakanda-server.plist
手動重新啟動或加載它sudo launchctl load /Library/LaunchDaemons/local.wakanda-server.plist
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.