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?
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
<?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:
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.
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
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
<?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:
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
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.
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
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
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.
Lingon is discontinued but still works and is the best tool to manage launchd if you have no experience.