I have a VM (VMware Fusion) with enabled VNC access. I want to be able to access it from the network. Unfortunately, VMware requires VM to be running to be able to accept VNC connections and vmware-vmx is the process that listens on VNC port.

My idea was to have launchd job that will run desired VM when something comes to the port. I've ended up with the following launchd job:

<?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">
        <string> </string>


/Applications/VMware\ Fusion.app/Contents/Library/vmrun -T fusion start "$1" nogui

The problem is that launchd listens on the port and I have to stop this before I can run VM. The only way to stop it to listen on the port I've found so far is to unload the job. Unfortunately it also stops the job itself and prevents VM from launching.

Is it possible to somehow tell launchd to stop listening on a port within the daemon?


Your problem here is that if launchd is going to listen on the VNC port, well, then it's going to get the traffic on the VNC port. The approved ways for a daemon program to deal with this are either to expect the network traffic on StdIn and StdOut or to collect a list of file descriptors from launchd and use one of those for the network communication. Otherwise the client is going to create a connection and then see the connection closed by launchd while it starts up the daemon.

I suggest you have launchd listen on another port and spawn a simple program that just pipes input to /dev/null while also launching the VM. So then to start the VM you telnet to this special port.

Or, you know, the easy thing to do is just always have the VM running. :-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .