Socket activated oneshot daemons

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

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

and a shell script (mysock.sh) 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 https://launchpad.net/ubuntu/+source/snapd/2.23

" - 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