這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。
How to run godoc under launchd on OS X
godoc is an amazing reference utility. I use launchd to keep it running for me.
<?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>org.golang.godoc</string> <key>ProgramArguments</key> <array> <!-- ensure this is the absolute path to your godoc install --> <string>/Users/dave/go/bin/godoc</string> <string>-http=127.0.0.1:6060</string> </array> <key>Sockets</key> <dict> <key>Listeners</key> <dict> <key>SockServiceName</key> <string>6060</string> </dict> </dict> <key>RunAtLoad</key> <false/> </dict></plist>
Place this file in ~/Library/LaunchAgents/org.golang.godoc.plist
and edit the absolute path to your godoc binary. Then issue the command
$ launchctl load ~/Library/LaunchAgents/org.golang.godoc.plist
You can then browse to http://127.0.0.1:6060 to view the current documentation for your Go installation.
To stop godoc just issue a killall godoc and launchd will restart it when necessary. You can use the same command after updating to the latest release to ensure you’re viewing the most up to date documentation.
——–我是分割線———–
launchctl不是特別友好,用load載入plist檔案時,只會報告出錯了,但不會告訴你出了什麼錯誤,今天折騰了半天,才發現是格式問題,漏了一個?號。
原作中貌似沒提用start啟動,以本文為例,啟動godoc需要使用start命令:
launchctl start org.golang.godoc
不知道為什麼啟動godoc還要配置SocketService,看別人配置redis也沒指定,結果照著redis配置,一直沒啟動,好在有人寫了現成的。找個機會看下plist的詳細格式要去。