Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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>

/usr/local/bin/vmw:

#!/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?

share|improve this question

migrated from serverfault.com Nov 14 '12 at 20:23

This question came from our site for professional system and network administrators.

1 Answer 1

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. :-)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.