
我沒有使用 launchd 的經驗,但想將 Tor 和 Polipo 設定為每 24 小時左右自動重新啟動的服務。我怎樣才能做到這一點?
答案1
對於 Tor,您可以使用此 launchd plist 使其在系統啟動時啟動。 (無需使用者登錄,這對於運行 24/7 全天候運行的網橋或節點的伺服器和人員來說是理想的選擇。)
儲存此文件/Library/LaunchDaemons/org.torproject.tor.plist
(您需要 root 權限,因此請使用sudo
。)
<?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>org.torproject.tor</string>
<key>ProgramArguments</key>
<array>
<string>/path/to/your/binary/of/tor</string>
<string>-f</string>
<string>/path/to/your/torrc</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>OnDemand</key>
<false/>
<key>UserName</key>
<string>userNameToRunTorUnder-UsuallyTorOrYourOwnUsershortname</string>
<key>GroupName</key>
<string>daemon</string>
</dict>
</plist>
將以下資訊替換為與您的系統相符的資訊:
/path/to/your/binary/of/tor
這通常是/usr/local/bin/tor
如果您從原始程式碼安裝了 tor 或/Applications/Vidalia.app/Contents/MacOS/tor
您想使用 Vidalia 的 tor 二進位。或在which tor
您的系統上尋找它。
/path/to/your/torrc
如果您以單獨的使用者身分執行 tor,則該檔案應位於.torrc
該使用者的主目錄中。您需要指定絕對路徑到這個文件。例如,如果您的用戶名稱為托爾並駐留在/Users/tor
該路徑將是/Users/tor/.torrc
userNameToRunTorUnder-UsuallyTorOrYourOwnUsershortname
這是運行時使用的用戶名tor
。如果您確實有一個單獨的用戶(可能會被命名為托爾)然後使用該用戶名,否則您可以使用幾乎任何其他用戶名。如果這只是為了您自己,請將其設為您自己的用戶短名。 (也就是你的主目錄的名稱。)
確保launchd項的權限依照launchd的要求是安全的。
sudo chown root:wheel /Library/LaunchDaemons/org.torproject.tor.plist
sudo chmod 755 /Library/LaunchDaemons/org.torproject.tor.plist
然後啟動它
sudo launchctl load -w /Library/LaunchDaemons/org.torproject.tor.plist
您可以使用非常相似的物品來啟動 polipo。將此 Launchd 項目另存為/Library/LaunchDaemons/fr.jussieu.pps.polipo.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>fr.jussieu.pps.polipo</string>
<key>ProgramArguments</key>
<array>
<string>/path/to/your/binary/of/polipo</string>
<string>-c</string>
<string>/path/to/your/polipo.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>OnDemand</key>
<false/>
<key>UserName</key>
<string>userNameToRunPolipoUnder-UsuallyPolipoOrYourOwnUsershortname</string>
<key>GroupName</key>
<string>daemon</string>
</dict>
</plist>
再次將以下資訊替換為與您的系統相符的資訊:
/path/to/your/binary/of/polipo 的 /path/to/your/binary/of/polipo
如果您想使用 Vidalia 中的一個,請使用 /Applications/Vidalia.app/Contents/MacOS/polipo,否則找出您的 polipo 二進位檔案的位置which polipo
。 (例如 MacPorts 確實將其安裝在/opt/local/bin/polipo
)
/path/to/your/polipo.conf
同樣,如果您想使用 Vidalia 提供的文件/Applications/Vidalia.app/Contents/Resources/polipo.conf
或使用絕對路徑到您的自訂配置。
userNameToRunPolipoUnder-UsuallyPolipoOrYourOwnUsershortname
這可以是您運行時使用的相同用戶名tor
,但也可以是單獨的用戶。我喜歡將我的守護程式分開。
再次確保 launchd 項的權限依照 launchd 的要求是安全的。
sudo chown root:wheel /Library/LaunchDaemons/fr.jussieu.pps.polipo.plist
sudo chmod 755 /Library/LaunchDaemons/fr.jussieu.pps.polipo.plist
然後啟動它
sudo launchctl load -w /Library/LaunchDaemons/fr.jussieu.pps.polipo.plist
注意:此設定確實不是根據要求每 24 小時重新啟動一次守護程式。我認為沒有必要,因為我從來沒有遇到任何穩定性問題tor
。 (我已經在 Mac OS X 上運行節點好幾年了。)
tor
做不是完全處理系統睡眠。因此,如果您讓 Mac 進入睡眠狀態,則需要重新啟動tor
才能使其再次可靠地建構電路。
此描述適用於無論如何都已啟動並運行的 Mac。只有當您以圖形方式登入而無需root
特權時,才可以以您的使用者身分執行此程式。
應該是這樣。
PS:請記住,這tor
意味著允許在發生阻止和審查的情況下進行訪問以及線上匿名和隱私為什麼運行 BitTorrenttor
不是一個好主意。
答案2
林貢已停產,但仍然有效,如果您沒有經驗,它是管理 launchd 的最佳工具。