Opened 12 years ago

Last modified 12 years ago

#558 closed enhancement (Implemented)

Use Launchd for starting Tor on OS X

Reported by: igel Owned by: phobos
Priority: Low Milestone: post 0.2.0.x
Component: Applications/Tor bundles/installation Version: 0.1.1.26
Severity: Keywords:
Cc: nickm Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

Launchd allows to fire up Tor as soon as the port that Tor is being assigned to is being contacted.
As an initial setup, add this code as a file named org.tor.plist into the directory called /Library/LaunchAgents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-AppleDTD PLIST 1.0EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>

<key>Label</key>
<string>org.tor</string>
<key>ProgramArguments</key>
<array>

<string>tor</string>

</array>


<key>OnDemand</key>
<true/>

<key>Sockets</key>
<dict>

<key>Listeners</key>
<dict>

<key>SockServiceName</key>
<string>9050</string>

</dict>

</dict>
<key>TimeOut</key>
<integer>600</integer>

</dict>
</plist>

</dict>
</plist>

Of course, the TimeOut feature is discussible and can be omitted. Its usefulness depends mainly on the question how hard it is to fire up Tor.

The easier it is, the more usefl this option will be.

This will work already! But you will have to hit the reload button upon first access to Tor, as the first access is swallowed by Launchd.

Launchd can give you the initial request with a couple of simple API calls. The source code package of launchd brings a decent example. Download it here:

http://www.opensource.apple.com/darwinsource/tarballs/other/launchd-152.tar.gz

It will contain a file called sample.c. It's easy to understand and should pretty much be exactly what needs to be pasted into the Tor binary.

Altogether, this will take no longer than 10 minutes but will make life a little happier!

Igel

[Automatically added by flyspray2trac: Operating System: OSX 10.4 Tiger]

Child Tickets

Change History (8)

comment:1 Changed 12 years ago by igel

Forgot to mention: This will NOT work with panther! For panther, a more unix-like startup process is required.

comment:2 Changed 12 years ago by phobos

At one point a year ago or so, I managed to convert everything to launchd. I ran into compatibility problems between
tiger and leopard (beta at the time) launchd differences. Are you testing this under tiger or leopard?

comment:3 Changed 12 years ago by igel

I'm testing under Leopard. It runs fine. Only that I have to hit reload upon first access.

comment:4 Changed 12 years ago by phobos

So, launching tor on demand probably isn't what we want. We probably want tor to start up as a daemon and sit and wait
for traffic. This way tor can keep the directory up to date and ready for use when the user passes traffic. I'll dig
up my old launch agent xml for tor and figure out which keys to merge into one xml file. thanks.

comment:5 Changed 12 years ago by jasemandude

Here's my tor launch daemon xml - note that it is located in /Library/LaunchDaemons rather than /Library/LaunchAgents. In order to have a circuit up and ready, it runs at load rather than on demand. I found that defining Listeners in the xml made launchd grab the port before tor had the chance and this would cause tor to exit, so Listeners is left undefined.

---cut here---

bash-3.2$ cat /Library/LaunchDaemons/com.jason.launchd.tor.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-Apple ComputerDTD PLIST 1.0EN"

"http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">
<dict>

<key>Label</key>
<string>com.jason.launchd.tor</string>
<key>ProgramArguments</key>
<array>

<string>/usr/bin/tor</string>
<string>-f</string>
<string>/Library/Tor/torrc</string>

</array>
<key>RunAtLoad</key>
<true/>
<key>OnDemand</key>
<false/>

<key>UserName</key>
<string>_tor</string>
<key>GroupName</key>
<string>daemon</string>

</dict>
</plist>

comment:6 Changed 12 years ago by jasemandude

Hmmm... it's stripped all the xml, perhaps I need to escape it

bash-3.2$ cat /Library/LaunchDaemons/com.jason.launchd.tor.plist
\<?xml version="1.0" encoding="UTF-8"?\>
\<!DOCTYPE plist PUBLIC "-Apple ComputerDTD PLIST 1.0EN"

"http://www.apple.com/DTDs/PropertyList-1.0.dtd"\>

\<plist version="1.0"\>
\<dict\>

\<key\>Label\</key\>
\<string\>com.jason.launchd.tor\</string\>
\<key\>ProgramArguments\</key\>
\<array\>

\<string\>/usr/bin/tor\</string\>
\<string\>-f\</string\>
\<string\>/Library/Tor/torrc\</string\>

\</array\>
\<key\>RunAtLoad\</key\>
\<true/\>
\<key\>OnDemand\</key\>
\<false/\>

\<key\>UserName\</key\>
\<string\>_tor\</string\>
\<key\>GroupName\</key\>
\<string\>daemon\</string\>

\</dict\>
\</plist\>

comment:7 Changed 12 years ago by jasemandude

Third time lucky!...

bash-3.2$ cat /Library/LaunchDaemons/com.jason.launchd.tor.plist
&lt;?xml version=\&quot;1.0\&quot; encoding=\&quot;UTF-8\&quot;?&gt;
&lt;!DOCTYPE plist PUBLIC \&quot;-Apple ComputerDTD PLIST 1.0EN\&quot;

\&quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd\&quot;&gt;

&lt;plist version=\&quot;1.0\&quot;&gt;
&lt;dict&gt;

&lt;key&gt;Label&lt;/key&gt;
&lt;string&gt;com.jason.launchd.tor&lt;/string&gt;
&lt;key&gt;ProgramArguments&lt;/key&gt;
&lt;array&gt;

&lt;string&gt;/usr/bin/tor&lt;/string&gt;
&lt;string&gt;-f&lt;/string&gt;
&lt;string&gt;/Library/Tor/torrc&lt;/string&gt;

&lt;/array&gt;
&lt;key&gt;RunAtLoad&lt;/key&gt;
&lt;true/&gt;
&lt;key&gt;OnDemand&lt;/key&gt;
&lt;false/&gt;

&lt;key&gt;UserName&lt;/key&gt;
&lt;string&gt;_tor&lt;/string&gt;
&lt;key&gt;GroupName&lt;/key&gt;
&lt;string&gt;daemon&lt;/string&gt;

&lt;/dict&gt;

&lt;/plist&gt;

comment:8 Changed 12 years ago by phobos

flyspray2trac: bug closed.
Commit to svn as r14147. Right now, it's optional.

Note: See TracTickets for help on using tickets.