Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

c5kolb

macrumors newbie
Original poster
Dec 4, 2012
2
0
I am using Tunnelblick to connect and disconnect to an OpenVPN2 server. This works. I wrote a program that I want launchd to start and run while the VPN is connected and kill when the VPN is disconnected.

Tunnelblick creates the device /dev/tun1 when the VPN is connected and deletes the device /dev/tun1 when the VPN is disconnected.

Launchd appears to be able to start and run a program when a path is created. Launchd starts my program when /dev/tun1 is created and makes sure it is running while /dev/tun1 exists. This works as intended.

I want launchd to kill my program when /dev/tun1 is deleted, but it doesn't do this and my program continues to run well after the VPN has been disconnected. The man page for launchd.plist doesn't say that it kills the program when the file disappears. It doesn't say what it does. Maybe it just no longer restarts my program if my program exits. I don't know.

My /Library/LaunchDaemons/com.acme.Aloha.plist file is below:

<?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>Label</key>
<string>com.acme.Aloha</string>

<key>Program</key>
<string>/Library/Aloha/sbin/Aloha.rb</string>

<key>ProgramArguments</key>
<array>
<string>Aloha.rb</string>
<string>--config</string>
<string>/Library/Application Support/Aloha/etc/client.conf</string>
</array>

<key>KeepAlive</key>
<dict>
<key>PathState</key>
<dict>
<key>/dev/tun1</key>
<true/>
</dict>​
</dict>

<key>Debug</key>
<true/>​
</dict>
</plist>

When I disconnect the VPN the /dev/tun1 device is deleted. Aloha continues to run. Nothing is logged to system.log by launchd until I manually kill Aloha from the command line.

Aloha was written to conform to the requirements and recommendations listed on the top of the launchd.plist man page (the MUST NOTs, SHOULD NOTs and SHOULDs).

What am I missing?

Thanks!

Take care,
Chris
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.