flungo-docker / avahi

Docker image for the Avahi mDNS/DNS-SD daemon.
MIT License
66 stars 32 forks source link

Handle empty pid files #12

Closed Timple closed 1 year ago

Timple commented 1 year ago

We had an issue with an empty PID file:

Found PID file (/var/run/avahi-daemon/pid) in container with PID 
PID is running, are you trying to start another instance?
Exiting without starting avahi
Timple commented 1 year ago

Subtle ping. I was bit by this again :slightly_frowning_face:

flungo commented 1 year ago

Sorry for the delay in looking into this. Would you happen to know how you managed to get an empty PID file? I didn't account for that when I wrote this bit of logic to do the pidfile cleanup.

I have been able to reproduce the the issue with the following.

docker build -t flungo/avahi:local src
CONTAINER="$(docker run -d flungo/avahi:local)"
docker exec -it "${CONTAINER}" sh -c 'echo > /var/run/avahi-daemon/pid'
docker kill "${CONTAINER}"
docker start "${CONTAINER}"
docker logs "${CONTAINER}"

It looks like you have accidentally deleted the actual fix you made in a45f73e25bb7c7201377b2d2d0ac65a8d8a0d874. The order of these last two branches don't need to be swapped - I wrote it in the current form so that each if/elif conditions look for a justification to delete the file and then the else case exits if it actually seems like avahi is already running.

Could you make the fix/condition you made in a45f73e25bb7c7201377b2d2d0ac65a8d8a0d874 the first condition? That should fix it and it makes sense to check if it's empty first as even "$$" == "${AVAHI_PID}", while it doesn't fail, does assume that ${AVAHI_PID} contains something sensible.

Timple commented 1 year ago

Would you happen to know how you managed to get an empty PID file?

Nope. But we use a service to manage our containers (balena). So I'm impressed that you managed to reproduce this so quickly. edit: in hindsight I now spot the trick that you actually create an empty pid file on purpose. I'm not sure how they arise in our setting. We share the /var/run/avahi-daemon/ directory with several dockers in a docker-compose file. But I wouldn't know why any of these dockers would create an empty pid file. 🙁

Could you make...

I'll get on it tomorrow!

flungo commented 1 year ago

Looks good. Thanks for reporting and contributing!