Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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 -w load /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 -w load /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.

share|improve this answer

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

share|improve this answer
    
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. itunes.apple.com/at/app/lingon/id411211026?mt=12 –  MacLemon May 5 '11 at 10:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.