Oneshot daemon freezes install on start snap "foo" (unset) services


#1

I’ve defined a daemon command specified for a snap. This command is designed to run only at certain instances and exit. I defined the command in the snapcraft.yaml as:

apps:
  app1:
    command: bin/do_something.sh
  usb-mount:
     command: bin/mount_usb.sh
     daemon: oneshot
     plugs:
       - removable-media

Here there is a command that is defined not as a service, plus our daemon service. When I go to install the snap. It hangs on install

Start snap "foo" (unset) services

If I remove the oneshot daemon from the snapcraft.yaml it installs fine.
is there a proper way to define a oneshot daemon?


#2

Thanks for reporting this. I was able to reproduce the problem although under some very specific conditions. Namely I had to make the ‘oneshot’ service loop or otherwise not terminate within a reasonable time.

The way snapd works is that we start all the services when a snap is getting installed. Meaning that the oneshot service gets started too by running systemctl snap.<snap-name>.<app-name>.service. For oneshot services, systemctl waits until the exec command finishes, thus blocking snapd from advancing the installation further.

Can you tell us more about the bin/mount_usb.sh app? What does it do? How do you want it to be started? I understand it is possible for it to block if some conditions are not met.


#3

Hi I’ll check through it. The mount_usb.sh tries 3 times to mount the usb. This oneshot daemon in normal usage is designed for running on a udev daemon when a usb is inserted for mounting the usb and then doing some stuff (like copying files). I haven’t set these up for the snap environment (I’m porting from a classic environment.) its likely that there is a loop somewhere that is hanging.

My questions around the way to run script on usb insertion is here


#4

Ended up being path errors with the daemon script. If the script runs without errors, then install will proceed nicely.