Mac-Osx

OSX launchctl list 找不到我的 plist

  • April 22, 2014

我創建了/System/Library/LaunchDaemons/com.rundeckd.plist包含以下內容的文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>Disabled</key>
   <true/>
   <key>Label</key>
   <string>com.rundeckd</string>
   <key>ProgramArguments</key>
   <array>
       <string>/test/rundeck/server/sbin/rundeckd</string>
       <string>start</string>
   </array>
   <key>KeepAlive</key>
   <true/>

   <key>StandardOutPath</key>
   <string>/test/rundeck/var/log/launchd_out.log</string>
   <key>StandardErrorPath</key>
   <string>/test/rundeck/var/log/launchd_sdd.log</string>
   <key>Debug</key>
   <true/>
</dict>
</plist>

但是, sudo launchctl list 沒有顯示這個 rundeckd。

為什麼?

此外,rundeckd 不會在引導時執行它,也不會創建日誌文件。(注意,我已修改 rundeckd 以在腳本中硬編碼所需的 $RDECK_BASE 環境變數)

更新

Gordon Davisson,我已經按照您所說的修改了 plist,並且沒有修改 rundeckd 腳本,我得到以下資訊:

nohup: can't detach from console: Inappropriate ioctl for device

然後,我嘗試將選項“launchd”添加到rundeckd(目前有啟動、停止和狀態),如下:

launchd() {
   echo "%s" "launchd $prog: "
   touch $LOK_FILE
   $rundeckd 2>&1 >>$RDECK_BASE/var/log/service.log &
   PID=$!
   echo $PID > $PID_FILE
   fg $PID  # block until it is stopped
}

但我得到了錯誤fg: no job control,因為我似乎無法執行“fg”,因為它不是互動式外殼。 https://stackoverflow.com/questions/11821378/what-does-bashno-job-control-in-this-shell-mean

https://gist.github.com/dportabella/7714449

$RDECK_BASE/server/sbin/rundeck_launchd是一個無需將程序發送到後台即可啟動 rundeck 的腳本(OSX Launchd 需要)。

/System/Library/LaunchAgents/david.rundeck.plist是一個配置文件,用於將 rundeck 設置為 Mac OSX 啟動服務。您需要根據需要修改此文件。在這個例子中,RDECK_BASE 是 /Users/david/bin/rundeck。

安裝這兩個文件後,重新啟動電腦,rundeck 將在啟動時啟動。

然後您可以停止、啟動並查看 rundeck 服務的狀態:

$ launchctl start david.rundeck
$ launchctl stop david.rundeck
$ launchctl list david.rundeck

(此腳本基於 $RDECK_BASE/server/sbin/rundeckd 腳本)

文件$RDECK_BASE/server/sbin/rundeck_launchd

#!/bin/bash 
#
# rundeck_launchd    Startup script for the RunDeck Launcher install
#   paramaters:
#     - env vars: [RDECK_BASE, RDECK_PORT, RDECK_LAUNCHER]
#     - standard RDECK_PORT values: [http: 4440, https: 4443]

export RDECK_BASE=${0%/*/*/*}

# RDECK_BASE must be set and exist
[ -z "$RDECK_BASE" -o ! -d "$RDECK_BASE" ] && {
   echo "RDECK_BASE not set or does not exist" ;
   exit 1 ;
}

# Source installation profile
. $RDECK_BASE/etc/profile

# Get the Launcher Jar path
[ -z "$RDECK_LAUNCHER" ] && {
   # Defaults to location of first startup
   RDECK_LAUNCHER=$(ls $RDECK_BASE/rundeck-launcher-*.jar)
}
[ -r "$RDECK_LAUNCHER" ] || {
   echo "RDECK_LAUNCHER not found: $RDECK_LAUNCHER" 
   exit 1;
}

# lookup the server port from the tools config file
RDECK_PORT=`awk '/framework.server.port/ {print $3}' $RDECK_BASE/etc/framework.properties`

# set the ssl opts if https is configured
SSL_OPTS=
proto=$(awk '/framework.server.url = / {split($3, a, ":"); print a[1]}' $RDECK_BASE/etc/framework.properties)
[ "${proto:-http}" == "https" ] && {
  SSL_OPTS="-Drundeck.ssl.config=$RDECK_BASE/server/config/ssl.properties"
}

rundeckd="${JAVA_HOME}/bin/java ${RDECK_JVM} -Dserver.http.port=${RDECK_PORT:=4440} $SSL_OPTS -jar ${RDECK_LAUNCHER}"

[ -w $RDECK_BASE/var ] || {
   echo "RDECK_BASE dir not writable: $RDECK_BASE" 
   exit 1 ;
}

mkdir -p $RDECK_BASE/var/run
mkdir -p $RDECK_BASE/var/log
mkdir -p $RDECK_BASE/var/lock/subsys

$rundeckd 2>&1 >>$RDECK_BASE/var/log/service.log

文件/System/Library/LaunchAgents/david.rundeck.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>Label</key>
   <string>david.rundeck</string>
   <key>ProgramArguments</key>
   <array>
       <string>/Users/david/bin/rundeck/server/sbin/rundeck_launchd</string>
   </array>
   <key>KeepAlive</key>
   <true/>
   <key>RunAtLoad</key>
   <true/>
   <key>UserName</key>
   <string>david</string>
   <key>Debug</key>
   <true/>
</dict>
</plist>

您的已啟動 plist 將該項目標記為已禁用:

   <key>Disabled</key>
   <true/>

為了讓它執行,您需要將其更改為<false/>或覆蓋它sudo launchctl load -w /System/Library/LaunchDaemons/com.rundeckd.plist-w使其永久覆蓋)。

另外,您是否修改了腳本以避免自身守護程序?如果沒有,您需要更改<key>KeepAlive</key><false/>,然後添加<key>AbandonProcessGroup</key><true/>

順便說一句,您還可以在 .plist 中定義環境變數,而不必修改腳本以包含它們:

   <key>EnvironmentVariables</key>
   <dict>
       <key>RDECK_BASE</key>
       <string>/Users/david/bin/rundeck</string>
   </dict>

最後,我建議更改標籤和文件名——它們應該基於反向 DNS 命名約定,因此除非您擁有 rundeckd.com 域,否則不應將其用作標籤或標籤字首。對於這樣的自製條目,我建議使用“local”前綴,即“local.rundeckd”。

更新:作業控制僅在互動式 shell 中可用;使用wait $PID而不是fg $PID.

引用自:https://serverfault.com/questions/511155