Docker restart gpio reclaiming

I’m running openhab 2.4 in a docker container on Raspberry Pi 4. When the full RPi server is restarted, then openHab can access the gpio pins without issues. But when only the openHab docker container is restarted, then the gpio interface is unavailable.
The log then shows this line:

2021-04-04 10:39:31.296 [ERROR] [ab.binding.gpio.internal.GPIOBinding] - Error occurred while creating backend object for item PushButton, exception: Device or resource busy

The problem is described here. But it is described for a non-Docker environment.
https://groups.google.com/g/openhab/c/eUgy1xDgjp4?pli=1
The workaround presented is to run the command below between the stop and start of openHab:

echo gpio_portnr > /sys/class/gpio/unexport

Is this the right way to address this problem? And if so, what is a correct way to configure the call to this command as part of a docker container start command? Should I tweak the container start command, which is currently standard:

gosu openhab tini -s ./start.sh

Thanks in advance for all help.

I can’t answer most of the questions, but I can say that if you do need to add a command to the startup in the container, add it to entrypoint.sh. That is the very first thing that is run when the container starts and it does all the house keeping required so OH can come up correctly (e.g. looking to see if an upgrade is going on).

Thanks for your reply. I took some time reading about docker entrypoint but I had trouble matching this mechanism to my challenge. Then I found a another post of yours, Running openHAB 2 in Docker, pointing to Docker Hub. This page has a topic “Executing shell scripts before openHAB is started”. Exactly what I needed.
Thanks and regards

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.