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"> <dict> <key>Label</key> <string>com.kulakov.vm.development</string> <key>ProgramArguments</key> <array> <string>/usr/local/bin/vmw</string> <string> </string> </array> <key>StandardOutPath</key> <string>/Users/kentzo/Desktop/com.kulakov.vm.development.log</string> <key>StandardErrorPath</key> <string>/Users/kentzo/Desktop/com.kulakov.vm.development.log</string> <key>Sockets</key> <dict> <key>NetworkListener</key> <dict> <key>SockServiceName</key> <string>5906</string> <key>SockType</key> <string>stream</string> </dict> </dict> <key>Debug</key> <true/> </dict> </plist>
#!/bin/bash /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?