You are right. Using a hook to disable autostart seems to work. At least in some cases, I figure.
daemon: forking the installer, however, still tries to run the specified command.
Let’s say your snapcraft.yaml contains the following service declaration:
command: bash $SNAP/test.sh
The test.sh always exits with exit code 1 (only for demonstration purposes):
sleep 60 &
And the hook in snap/hooks/configure tries to disable the service:
snapctl stop --disable mysnap.myservice
Then, the installation of the snap will fail, because snapd still tries to start the daemon during installation:
error: cannot perform the following tasks:
- Start snap “mysnap” (unset) services ([start snap.mysnap.myservice.service] failed with exit status 1: Job for snap.mysnap.myservice.service failed because the control process exited with error code.
See “systemctl status snap.mysnap.myservice.service” and “journalctl -xe” for details.
However, if the specified command exits with exit code 0, and the forked process exits with exit code 1, the installation does succeed.
Another version of test.sh:
exit 1 &
daemon: simple and a command that exits with exit code 1, the installation is also successful.
Is this behavior expected?