Snap service (daemon: simple) does not start

My snap (hw-wtdog) having an app of type simple daemon, stays disabled (Startup) and inactive (Current) after installation.

snap info snippet

services:
  hw-wtdog.runner: simple, disabled, inactive

root@localhost:# snap services
Service Startup Current Notes
app-mgr.app-mgr enabled active -
hw-wtdog.runner disabled inactive - --> Problemtic snap
`

When I try to enable the snap, I get an error already enabled

root@localhost:~# snap enable hw-wtdog
error: cannot enable "hw-wtdog": snap "hw-wtdog" already enabled
root@localhost:~#

Finally, on starting the snap, status changes to active and service starts

root@localhost:# snap services
Service Startup Current Notes
app-mgr.app-mgr enabled active -
hw-wtdog.runner disabled active -

snapcraft.yaml snippet

apps:                                                                              
    runner:                                                                        
        command: bin/setpet                                                        
        daemon: simple                                                             
        restart-condition: always                                                  
        plugs: [snapd-control]                               
        environment:                                                               
            LD_LIBRARY_PATH: $SNAP/lib;

Not sure why other snaps that I have do not have this issue.

thats your issue … you are not trying to enable a snap but a service :wink:

snap start --enable hw-wtdog.runner

(instead of “snap enable …”)

though i’d recommend watching the journal to find out why it didnt start in the first place …

Right. But why should I need to enable service of a snap manually in first place? I am expecting that like other snap’s, service of this snap to start when snap gets installed.

I reinstalled the snap this time with journalctl running on one more terminal. But it does not give anything

root@localhost:# snap install hw-wtdog_0.27-0.1_amd64.snap --devmode
hw-wtdog 0.27-0.1 installed
root@localhost:

user@localhost:~$ sudo journalctl --output=short --follow --all | sudo snappy-debug -r
kernel.printk_ratelimit = 0

because the packager was cleverer than others and made sure that the service only starts once all interfaces it needs are connected ? :wink:

… or just because it is broken :wink:

i.e. take a look at the set of hooks here:

by default the service comes up disabled … because it needs two interfaces to function … so instead of having it enabled and dieing in a loop (spamming logs) it stays disabled until both interface connections are there …

In my case, not all the interfaces (snapd-control) were connected. So I connected them and started the service manually. Then reinstalled the same snap again hoping this time the service will start. But it did not.

I am starting to believe this :confused:

Apart from snapd-control are there any other interfaces required for setting system watchdog (runtime and shutdown) timeouts? I tried adding hardware-observe but still did not work.

i dont think so, snapd-control should be sufficient to give you access to the API equivalent of “snap set/get” … if the app is yours, just add some debugging code and watch your journal (and i mean not via snappy-debug but literally the syslog output there)…

I do have debug logs. But they are not getting printed.

Problematic snap has this logs while running snap install:
Journal log snippet

Jul 01 13:59:18 localhost systemd[1]: Stopping Service for snap application -hw-wtdog.runner...
Jul 01 13:59:18 localhost systemd[1]: Stopped Service for snap application -hw-wtdog.runner.
Jul 01 13:59:20 localhost systemd[1]: Reloading.
Jul 01 13:59:21 localhost audit[3177]: AVC apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="/snap/snapd/8140/usr/lib/snapd/snap-confine" pid=3177 comm="apparmor_parser"
Jul 01 13:59:21 localhost audit[3177]: AVC apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="/snap/snapd/8140/usr/lib/snapd/snap-confine//mount-namespace-capture-helper" pid=3177 comm="apparmor_parser"
Jul 01 13:59:21 localhost kernel: audit: type=1400 audit(1593611961.402:1611): apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="/snap/snapd/8140/usr/lib/snapd/snap-confine" pid=3177 comm="apparmor_parser"
Jul 01 13:59:21 localhost kernel: audit: type=1400 audit(1593611961.402:1612): apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="/snap/snapd/8140/usr/lib/snapd/snap-confine//mount-namespace-capture-helper" pid=3177 comm="apparmor_parser"
Jul 01 13:59:21 localhost audit[3179]: AVC apparmor="STATUS" operation="profile_replace" profile="unconfined" name="snap.-hw-wtdog.runner" pid=3179 comm="apparmor_parser"
Jul 01 13:59:21 localhost kernel: audit: type=1400 audit(1593611961.598:1613): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="snap.-hw-wtdog.runner" pid=3179 comm="apparmor_parser"
Jul 01 13:59:21 localhost audit[3181]: AVC apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="snap-update-ns.-hw-wtdog" pid=3181 comm="apparmor_parser"
Jul 01 13:59:21 localhost kernel: audit: type=1400 audit(1593611961.602:1614): apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="snap-update-ns.-hw-wtdog" pid=3181 comm="apparmor_parser"
Jul 01 13:59:22 localhost systemd[1]: Reloading.
Jul 01 13:59:26 localhost systemd-udevd[499]: Network interface NamePolicy= disabled on kernel command line, ignoring.
Jul 01 13:59:26 localhost systemd[1]: Reloading.

Another working snap has this:
Journal log snippet

Jul 01 13:51:01 localhost systemd[1]: Reloading.
Jul 01 13:51:01 localhost systemd[1]: Mounting Mount unit for -app-mgr, revision x174...
Jul 01 13:51:01 localhost systemd-udevd[499]: Network interface NamePolicy= disabled on kernel command line, ignoring.
Jul 01 13:51:02 localhost systemd[1]: Mounted Mount unit for -app-mgr, revision x174.
Jul 01 13:51:02 localhost systemd[1]: Stopping Service for snap application app-mgr.app-mgr...
Jul 01 13:51:02 localhost -app-mgr.app-mgr[1752]: 2020/07/01 13:51:02: am_mqtt_offline_cb(44): am_mqtt_offline_cb 0
Jul 01 13:51:02 localhost -mosquitto.mosquitto[906]: 1593611462: Socket error on client am, disconnecting.
Jul 01 13:51:02 localhost systemd[1]: Stopped Service for snap application app-mgr.app-mgr.
Jul 01 13:51:03 localhost snapd[949]: response.go:368: cannot stream response; problem writing: write unix /run/snapd.socket->@: write: broken pipe
Jul 01 13:51:04 localhost systemd[1]: Reloading.
Jul 01 13:51:06 localhost snapd[949]: spec.go:175: renaming mount entry for directory "/snap/app-mgr/x174/-lib" to "/snap/-app-mgr/x174/-lib-2" to avoid a clash
Jul 01 13:51:06 localhost audit[2465]: AVC apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="/snap/snapd/8140/usr/lib/snapd/snap-confine" pid=2465 comm="apparmor_parser"
Jul 01 13:51:06 localhost audit[2465]: AVC apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="/snap/snapd/8140/usr/lib/snapd/snap-confine//mount-namespace-capture-helper" pid=2465 comm="apparmor_parser"
Jul 01 13:51:06 localhost kernel: audit: type=1400 audit(1593611466.206:1596): apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="/snap/snapd/8140/usr/lib/snapd/snap-confine" pid=2465 comm="apparmor_parser"
Jul 01 13:51:06 localhost kernel: audit: type=1400 audit(1593611466.206:1597): apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="/snap/snapd/8140/usr/lib/snapd/snap-confine//mount-namespace-capture-helper" pid=2465 comm="apparmor_parser"
Jul 01 13:51:06 localhost audit[2467]: AVC apparmor="STATUS" operation="profile_replace" profile="unconfined" name="snap-update-ns.-app-mgr" pid=2467 comm="apparmor_parser"
Jul 01 13:51:06 localhost kernel: audit: type=1400 audit(1593611466.286:1598): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="snap-update-ns.app-mgr" pid=2467 comm="apparmor_parser"
Jul 01 13:51:06 localhost audit[2468]: AVC apparmor="STATUS" operation="profile_replace" profile="unconfined" name="snap.app-mgr.app-mgr" pid=2468 comm="apparmor_parser"
Jul 01 13:51:06 localhost kernel: audit: type=1400 audit(1593611466.490:1599): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="snap.app-mgr.app-mgr" pid=2468 comm="apparmor_parser"
Jul 01 13:51:06 localhost audit[2469]: AVC apparmor="STATUS" operation="profile_replace" profile="unconfined" name="snap.app-mgr.launch" pid=2469 comm="apparmor_parser"
Jul 01 13:51:06 localhost kernel: audit: type=1400 audit(1593611466.494:1600): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="snap.app-mgr.launch" pid=2469 comm="apparmor_parser"
Jul 01 13:51:06 localhost systemd[1]: Reloading.
Jul 01 13:51:09 localhost systemd[1]: Started Service for snap application app-mgr.app-mgr.
Jul 01 13:51:10 localhost audit[2493]: AVC apparmor="ALLOWED" operation="capable" info="optional: no audit" error=-1 profile="snap.-app-mgr.app-mgr" pid=2493 comm="snap-exec" capability=12  capname="net_admin"
Jul 01 13:51:10 localhost kernel: audit: type=1400 audit(1593611470.006:1601): apparmor="ALLOWED" operation="capable" info="optional: no audit" error=-1 profile="snap.app-mgr.app-mgr" pid=2493 comm="snap-exec" capability=12  capname="net_admin"
Jul 01 13:51:11 localhost systemd-udevd[499]: Network interface NamePolicy= disabled on kernel command line, ignoring.

well, make it log directly to a txt file in $SNAP_DATA worst case … from the app code …

Tried. Writing to a log file in $SNAP_DATA, but log file seen there only after i do snap start ....

While digging through https://snapcraft.io/docs/service-management came across - snap start --enable <snap>.<service>

Ran the command and rebooted. Voila !!! Service becomes active on next boot.

Although I don’t recall running snap start --disable<snap>.<service> on my device, --enable has solved the issue.

Thanks @ogra for your inputs.

1 Like