我没有使用 launchd 的经验,但想将 Tor 和 Polipo 设置为每 24 小时左右自动重新启动的服务。我怎样才能做到这一点?
对于 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>
Run Code Online (Sandbox Code Playgroud)
将以下信息替换为与您的系统匹配的信息:
/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位于该用户的主目录中。您需要指定此文件的绝对路径。例如,如果您的用户名为tor并驻留在其中,/Users/tor则该路径将是/Users/tor/.torrc
userNameToRunTorUnder-UsuallyTorOrYourOwnUsershortname
这是运行的用户名tor。如果您确实有一个单独的用户(可能名为tor),请使用该用户,否则您几乎可以使用任何其他用户名。如果这只是为了您自己,请将其设为您自己的用户短名称。(也就是您的主目录的名称。)
确保launchd 项的权限按照launchd 的要求是安全的。
sudo chown root:wheel /Library/LaunchDaemons/org.torproject.tor.plist
sudo chmod 755 /Library/LaunchDaemons/org.torproject.tor.plist
Run Code Online (Sandbox Code Playgroud)
然后启动它
sudo launchctl load -w /Library/LaunchDaemons/org.torproject.tor.plist
您可以使用非常相似的项目来启动 polipo。将此启动项另存为/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>
Run Code Online (Sandbox Code Playgroud)
再次将以下信息替换为与您的系统匹配的信息:
/path/to/your/binary/of/polipo
如果您想使用 Vidalia 中的信息,请使用 /Applications/Vidalia.app/Contents/MacOS/polipo else 找出在哪里你的 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
Run Code Online (Sandbox Code Playgroud)
然后启动它
sudo launchctl load -w /Library/LaunchDaemons/fr.jussieu.pps.polipo.plist
警告:此安装程序不按要求重新启动守护程序每24小时。我认为没有必要,因为我从来没有遇到任何稳定性问题tor。(我已经在 Mac OS X 上运行节点好几年了。)
tor根本不处理系统睡眠。因此,如果您让 Mac 进入睡眠状态,则需要重新启动tor以使其再次可靠地构建电路。
此说明适用于无论如何都已启动并正在运行的 Mac。可以以您的用户身份运行此操作,并且仅当您以图形方式登录而不需要root特权时。
应该是这样。
PS:请记住,这tor是为了允许访问发生阻塞和审查以及在线匿名和隐私以及为什么运行 BitTorrenttor不是一个好主意。
| 归档时间: |
|
| 查看次数: |
2823 次 |
| 最近记录: |