Socket activated oneshot daemons

I’m playing around with socket activation, creating something like:

    plugs: [ network-bind ]
    daemon: oneshot
    restart-condition: never
        listen-stream: $SNAP_DATA/socket
        socket-mode: 0644

and a shell script ( like:

#! /bin/sh

set -e

echo "socket triggered"

creates a socket just fine and i can do something like:

echo foo|sudo nc -q 1 -U /var/snap/<snapname>/current/socket

this actually triggers the script and properly makes it print “socket triggered” in syslog …

but … it does not seem to respect the oneshot or restart-condition directives above and simply goes into a restart loop.

is that me misunderstanding how our socket implementation works or is there a bug with snapd not respecting oneshot when sockets are used (then we should perhaps add a syntax check in snapcraft)

1 Like

ok, i found the right hint for my issue in

" - wrappers/services: RemainAfterExit=yes for oneshot daemons w/ stop cmds"

and indeed it works if i explicitly define some pointless stop-command: in my snapcraft.yaml like:

stop-command: sh -c "touch /dev/null"

why do we restrict RemainAfterExit=yes for oneshot daemons this way, is there any technical reason for not simply using it by default if oneshot is set ?

1 Like