Domanda

I am trying to figure out a way to trigger a launchd daemon on a OS X Server. I found out that I can set up the launchd daemon to listen to a specific socket connection (tcp port) which will - when contacted - execute a script. I have done all of that successfully, except that when I for example open a connection to the socket (for test purpose with telnet), the script is executed indefinitely even after I dropped the socket connection.

Launchd plist:

<?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.example.app</string>
    <key>Program</key>
    <string>/usr/bin/true</string>
    <key>Sockets</key>
    <dict>
        <key>Listeners</key>
        <dict>
            <key>SockServiceName</key>
            <string>1234</string>
        </dict>
    </dict>
    <key>inetdCompatibility</key>
    <dict>
        <key>Wait</key>
        <true/>
    </dict>
</dict>
</plist>

Does anyone know why the scripts gets called again and again? My aim is to have the script be executed ONLY ONCE when a socket connection is established from a client...

Any help appreciated, Vince

È stato utile?

Soluzione

By specifying Wait = true in the inetdCompatibility dictionary you're telling launchd that your application is responsible for calling accept on the listening socket to consume one of the pending connections. By failing to do that the connection will remain queued on the listening socket, causing launchd to think that there is still new work for your application to do. You can either ensure that your application calls accept when launchd to consume the pending connect, or specify Wait = false to have launchd to call accept on your behalf.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top