2012-09-25 50 views
2

編輯:這看起來好像我在控制檯 com.apple.launchd得到一個錯誤:(com.xxxx.adbind [57])與代碼退出的:1的launchd plist中不工作

那有什麼什麼意思?

另外;如果我加載使用launchctl命令登錄的launchd plist文件,它工作正常!

我開車自己瘋了試圖找出爲什麼我的launchd不工作。我在Mountain Lion 10.8.2中使用它當我使用launchctl手動啓動它時,它說它已加載,但腳本未運行。手動運行時的腳本也可以很好地工作。也許它只是需要一個更好的眼睛來看看我在做什麼。

首先,我將解釋我正在努力完成的是什麼。我有大約400臺電腦在現場拍攝。我需要將這些計算機綁定到AD,這無法通過我們的網絡完成。我想通過在啓動時運行launchd腳本來調用腳本,然後讓腳本在運行之前檢查它是否在網絡中。在AD用戶登錄之前,可以在我們的網絡中首次啓動時綁定這些計算機。

這裏是我的launchd,我把它放在/ Library/launchDaemons

<?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>Label</key> 
    <string>com.xxxx.adbind</string> 
    <key>ProgramArguments</key> 
    <array> 
     <string>/usr/local/bin/adbind.bash</string> 
    </array> 
    <key>RunAtLoad</key> 
    <true/> 
    <key>WorkingDirectory</key> 
    <string>/usr/local/bin</string> 
</dict> 
</plist> 

我已經使用這個有和沒有WorkingDirectory關鍵試過。

這裏是我的劇本,我把我的腳本在/ usr/local/bin目錄

#!/bin/bash 

computerid=`/usr/sbin/scutil --get LocalHostName` 

# Standard parameters 
domain="xxx.xxxx.edu"   # fully qualified DNS name of Active Directory Domain 
udn="xxxxxx"   # username of a privileged network user 
password="xxxxx"     # password of a privileged network user 
ou="OU=xxx,DC=xxx,DC=xxxx,DC=edu"  # Distinguished name of container for the computer 

# Advanced options 
alldomains="enable"   # 'enable' or 'disable' automatic multi-domain authentication 
localhome="enable"   # 'enable' or 'disable' force home directory to local drive 
protocol="smb"    # 'afp' or 'smb' change how home is mounted from server 
mobile="enable"   # 'enable' or 'disable' mobile account support for offline logon 
mobileconfirm="disable"  # 'enable' or 'disable' warn the user that a mobile acct will be created 
useuncpath="enable"   # 'enable' or 'disable' use AD SMBHome attribute to determine the home dir 
user_shell="/bin/bash"  # e.g., /bin/bash or "none" 
preferred="-preferred xxx.xxxxx.edu" # Use the specified server for all Directory lookups and authentication 
          # (e.g. "-nopreferred" or "-preferred ad.server.edu") 
admingroups="xxx\admins,xxx\teachers,xxx\ADManagement - Computers,xxx\employees" # These comma-separated AD groups may administer the machine (e.g. "" or "APPLE\mac admins") 

# Login hook setting -- specify the path to a login hook that you want to run instead of this script 

### End of configuration 

## Wait until all network services are up. 
ipconfig waitall 

# Check to see if we're in the district 
if ping -c 1 xxx.xxx.x.x 
then 

# Activate the AD plugin 
defaults write /Library/Preferences/DirectoryService/DirectoryService "Active Directory" "Active" 
plutil -convert xml1 /Library/Preferences/DirectoryService/DirectoryService.plist 
sleep 5 

# Remove computer from OU 
dsconfigad -f -r -u xxxxxxx -p xxxxxx 
sleep 5 

# Bind to AD 
dsconfigad -f -a $computerid -domain $domain -u $udn -p "$password" -ou "$ou" 

# Configure advanced AD plugin options 
if [ "$admingroups" = "" ]; then 
    dsconfigad -nogroups 
else 
    dsconfigad -groups "$admingroups" 
fi 

dsconfigad -alldomains $alldomains -localhome $localhome -protocol $protocol \ 
    -mobile $mobile -mobileconfirm $mobileconfirm -useuncpath $useuncpath \ 
    -shell $user_shell $preferred 

# Restart DirectoryService (necessary to reload AD plugin activation settings) 
killall DirectoryService 

# Add the AD node to the search path 
if [ "$alldomains" = "enable" ]; then 
    csp="/Active Directory/All Domains" 
else 
    csp="/Active Directory/$domain" 
fi 


# This works in a pinch if the above code does not 
defaults write /Library/Preferences/DirectoryService/SearchNodeConfig "Search Node Custom Path Array" -array "/Active Directory/All Domains" 
defaults write /Library/Preferences/DirectoryService/SearchNodeConfig "Search Policy" -int 4 
defaults write /Library/Preferences/DirectoryService/ContactsNodeConfig "Search Node Custom Path Array" -array "/Active Directory/All Domains" 
defaults write /Library/Preferences/DirectoryService/ContactsNodeConfig "Search Policy" -int 4 

plutil -convert xml1 /Library/Preferences/DirectoryService/SearchNodeConfig.plist 

## Remove the script and launchd job. Be sure to delete the script. 
launchctl unload -w /Library/LaunchDaemons/com.xxxx.adbind.plist 
rm /Library/LaunchDaemons/com.xxxx.adbind.plist 
rm /usr/local/bin/adbind.bash 

exit 0 
else 
echo "District not Available. Quitting" 
exit 1 
fi 

感謝您的幫助!

+0

嗯,我終於通過我的問題,並找到了解決方案!我會在這裏發佈答案,希望有一天能幫助別人!看起來好像launchd文件的運行時間不足以運行我的整個腳本。所以我將KeepAlive鍵添加到了plist。現在看起來像這樣。 – Chuck

回答

1

嗯,我終於通過我的問題,並找到了解決方案!我會在這裏發佈答案,希望有一天能幫助別人!看起來好像launchd文件的運行時間不足以運行我的整個腳本。所以我將KeepAlive鍵添加到了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>Label</key> 
    <string>com.xxxx.adbind</string> 
    <key>KeepAlive</key> 
    <dict> 
     <key>SuccessfulExit</key> 
     <false/> 
    </dict> 
    <key>ProgramArguments</key> 
    <array> 
     <string>/usr/local/bin/adbind.bash</string> 
    </array> 
    <key>RunAtLoad</key> 
    <true/> 
</dict> 
</plist> 

我也遇到了權限問題,發現我創建並放入腳本的「bin」文件夾不屬於root。所以我在我的文件和文件夾上運行chown和chmod。喜歡這個。

sudo chown root:wheel bin 
sudo chown root:wheel adbind.bash 
sudo chmod 755 adbind.bash 
sudo chown root:wheel com.xxxx.adbind.plist 
sudo chmod 755 com.xxxx.adbind.plist 
1

退出代碼1表示腳本退出並出現錯誤情況。如果它以0結束,則意味着沒有錯誤。