Docker-Deamon is too fast for /dev/ttyAMC0 on reboot

Hey,

I am running the latest stable openHAB docker. I use docker-compose to set it up and it works really great as long as I start the container manually with docker-compose up -d.

In my compose file I have the option restart: unless-stopped so the openHAB container should automatically get started upon reboot.

But, the issue comes with my zwave stick /dev/ttyAMC0, which I have included via devices in my compose file: Upon reboot the docker-deamon is a couple of seconds faster than the stick resulting in docker not starting the container.

Based on the timestamps in the docker deamon log and dmesg you can clearly see that the device becomes available roughly 7 s later.

journalctl -f -n 100 -u docker.service
Sep 08 19:00:32 nuc dockerd[863]: time="2020-09-08T19:00:32.493077680+02:00" level=error msg="2066fdff0ce6b9590813eda2906c83d409cfe1af9067c629a21103ed7ff0b72a cleanup: failed to delete container from containerd: no such container"
Sep 08 19:00:32 nuc dockerd[863]: time="2020-09-08T19:00:32.493569896+02:00" level=error msg="Failed to start container 2066fdff0ce6b9590813eda2906c83d409cfe1af9067c629a21103ed7ff0b72a: error gathering device information while adding custom device \"/dev/ttyACM0\": no such file or directory"
dmesg -T
[Tue Sep  8 19:00:39 2020] cdc_acm 2-4.4:1.0: ttyACM0: USB ACM device

  • Again, I can manually start the container with docker-compose up -d so there is no issue with any permissions (dialout group etc.).
  • If possible I do not want to postpone the whole docker-deamon start (which could easily be done by copying and altering the unit file or even creating a drop-in file) as couple of other containers are started as well, but more important I would like to minimize manipulating a standard docker host. (for me the whole Idea of docker in a private environment is to quickly get stuff up and running, easily backup appdata, move containers around and care not to much about the replaceable host).

I am looking for a solution where I might even (accidentally) unplug the zwave stick and openHAB would start anyways. Preferably, by not creating custom docker images or wrapper scripts where I would loose the convenience of orchestrating all my services with docker compose files.

I know, I am asking for something where so many workarounds exist, but maybe somebody has an idea for a clean solution.

For the sake of completeness my docker compose file:

version: '3'

services:
  openhab:
    image: "openhab/openhab:latest"
    container_name: openhab
    restart: always

    network_mode: host
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "/etc/timezone:/etc/timezone:ro"
      - "${DOCKER_DATA}/openhab/addons:/openhab/addons"
      - "${DOCKER_DATA}/openhab/conf:/openhab/conf"
      - "${DOCKER_DATA}/openhab/userdata:/openhab/userdata"
      - "${DOCKER_DATA}/openhab/cont-init.d:/etc/cont-init.d"
    environment:
      OPENHAB_HTTP_PORT: "8090"
      OPENHAB_HTTPS_PORT: "8443"
      EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/Berlin"
      USER_ID: 1000
      GROUP_ID: 1000
    devices:
      - "/dev/ttyACM0:/dev/ttyACM0:rwm"

    cap_add:
      - NET_ADMIN
      - NET_RAW
    

It looks like the error is coming from Docker, not openHAB. openHAB will throw an error into the logs saying that the controller device doesn’t exist but then start without it. That error above is coming from the Docker daemon before the container is loaded.

If you want a solution that doesn’t require delaying the Docker Daemon from starting until the device is available you will most likely find the answer by asking on a Docker forum. The problem really has nothing to do with openHAB and there are few to any users on this forum who can help.

There is nothing you can do to the container itself to solve this problem. It’s failing before the container is even loaded.

I never thought it was an openHAB (or openHAB developer) failure. I just thought I might find more people having the same issue with slow tty devices here than on the docker forum. But you are right, I should give the docker forum a try.

In the meantime I just figured out that those 7 seconds stated above could vary up to 50 s (caused by who knows). But I got rid of a usb hub which was in between the host and the stick (thanks dmesg for the reminder) and now I am always under 10 s. I just added a drop-in systemd file for the docker deamon to sleep 10 s before starting the container and it seems to be fixed.

Nonetheless, I am still looking for a solution where I might even accidentally unplug the stick or do not need to alter the host and the container would start anyways. I will check the docker forum.

Thanks rikoshak!

Try mounting by serial id instead:

For example:

      - "/dev/serial/by-id/usb-Zooz_800_Z-Wave_Stick_533D004242-if00:/dev/ttyACM0"

You may also use device_cgroup_rules (starting with docker compose file version 2.3)

  device_cgroup_rules:
            - c 188:* rmw

You can get the group id with the ls -l command:

ls -l /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 0 Feb  5 22:05 /dev/ttyUSB0