How can I make Tor and Polipo run (and automatically restart) using launchd on Mac OS X?

4

2

I have no experience with launchd but would like to setup Tor and Polipo as a service that automatically restarts every 24 hours or so. How can I do this?

jennym

Posted 2010-09-25T16:48:59.783

Reputation: 51

Answers

6

For tor you can use this launchd plist to have it start at system launch. (No need for a user to be logged in which is ideal for servers and people running a bridge or node that shall be up 24/7.)

Save this file /Library/LaunchDaemons/org.torproject.tor.plist (You'll need root privileges for that so use 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>

Replace the following information with the one matching your system:

/path/to/your/binary/of/tor This is usually /usr/local/bin/tor if you have installed tor from source or /Applications/Vidalia.app/Contents/MacOS/tor if you want to use the tor binary from Vidalia. Or look for it with which tor on your system.

/path/to/your/torrc If you're running tor as a separate user this should be in .torrc in that user's home directory. You need to specify the absolute path to this file. For example if your user is named tor and resides in /Users/tor then that path would be /Users/tor/.torrc

userNameToRunTorUnder-UsuallyTorOrYourOwnUsershortname This is the username to run tor under. If you do have a separate user (which is likely to be named tor) then use that one, else you can use pretty much any other username. If this is just for yourself make it your own usershortname. (Aka what your home directory is named.)

Make sure the privileges of the launchd item are safe as required by launchd.

sudo chown root:wheel /Library/LaunchDaemons/org.torproject.tor.plist
sudo chmod 755 /Library/LaunchDaemons/org.torproject.tor.plist

Then launch it with sudo launchctl load -w /Library/LaunchDaemons/org.torproject.tor.plist

You can use a very similar item to launch polipo. Save this Launchd item as /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>

Again replace the following information with the one matching your system: /path/to/your/binary/of/polipo If you want to use the one from Vidalia use /Applications/Vidalia.app/Contents/MacOS/polipo else find out where your polipo binary is with which polipo. (For example MacPorts does instal this in /opt/local/bin/polipo)

/path/to/your/polipo.conf Again, if you want to use the file provided by Vidalia /Applications/Vidalia.app/Contents/Resources/polipo.conf or use the absolute path to your custom configuration.

userNameToRunPolipoUnder-UsuallyPolipoOrYourOwnUsershortname This can be the same username that you run tor with, but it can also be a separate user. I like to have my daemons separated.

Again, make sure the privileges of the launchd item are safe as required by launchd.

sudo chown root:wheel /Library/LaunchDaemons/fr.jussieu.pps.polipo.plist
sudo chmod 755 /Library/LaunchDaemons/fr.jussieu.pps.polipo.plist

Then launch it with sudo launchctl load -w /Library/LaunchDaemons/fr.jussieu.pps.polipo.plist

Caveat: This setup does not restart the daemons every 24h as requested. I don't think it is necessary as I have never had any problems with stability with tor. (I've been running nodes for several years on Mac OS X.)

tor does not handle system sleep at all. So if you put your Mac to sleep, you need to restart tor to have it reliably build circuits again.

This description is meant for Macs that are up and running anyway. It is possible to make this run as your user and only when you login graphically without requiring root privileges.

That should be it.

PS: Please keep in mind that tor is meant to allow access where blocking and cencorship occurs as well as anonymity and privacy online and why running BitTorrent over tor isn't a good idea.

MacLemon

Posted 2010-09-25T16:48:59.783

Reputation: 492

0

Lingon is discontinued but still works and is the best tool to manage launchd if you have no experience.

user31752

Posted 2010-09-25T16:48:59.783

Reputation:

The abandoned Lingon 2.1.1 still works fine under 10.6 SnowLeopard. There also is an updated version 2.2.1 for SnowLeopard available for 3.99€ in the Mac AppStore. http://itunes.apple.com/at/app/lingon/id411211026?mt=12

– MacLemon – 2011-05-05T10:36:37.923