fhem / fhem-docker

A basic Docker image for FHEM house automation system, based on Debian Linux.
https://fhem.de/
MIT License
84 stars 27 forks source link

avahi-daemon not startable #148

Open tobiasfaust opened 10 months ago

tobiasfaust commented 10 months ago

Hi, i need avahi-browse inside of Fhem Docker. So i need to install those packets: apt-get install -y avahi-utils avahi-daemon libnss-mdns systemd

My Dockerfile:

FROM fhem/fhem:bullseye

RUN apt-get update -y &&  \
    apt-get upgrade -y && \
    apt-get install -y avahi-utils avahi-daemon libnss-mdns systemd && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

My docker compose file:

  fhem:
    build:
      context: fhem
    image: fhem:1.0
    container_name: fhem
    hostname: fhem
    volumes:
      - fhem:/opt/fhem
      - /var/run/dbus:/var/run/dbus
    ports:
      - 8083:8083
      - 7072:7072
    restart: unless-stopped

After starting the docker the daemon didn´t start:

root@fhem:/tmp# avahi-browse -a
Failed to create client object: Daemon not running

So I have to do the following steps for a proper working inside of docker:

rm /run/dbus/pid
dbus-daemon --system
/etc/init.d/avahi-daemon start
avahi-browse -a
[.....]

Its a problem inside of the fhem docker why dbus is not startable? If not, how can i add a custom startscript to execute the needed steps after each container start?

sidey79 commented 10 months ago

Does this Problem also persist with an up to date Image: ghcr.io/fhem/fhem-minimal-docker:3-bullseye

tobiasfaust commented 10 months ago

I´m afraid of that, its the same. I made fresh compilation:

FROM ghcr.io/fhem/fhem-minimal-docker:3-bullseye

ENV AWS_CONFIG_FILE /run/secrets/aws_fhem_config
ENV AWS_SHARED_CREDENTIALS_FILE /run/secrets/aws_fhem_credentials

WORKDIR /tmp

RUN apt-get update -y &&  \
    apt-get upgrade -y && \
    apt-get install -y nano cron awscli \
        libmatch-simple-perl \
        avahi-utils avahi-daemon libnss-mdns systemd && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
root@fhem:/tmp# /etc/init.d/avahi-daemon status
Avahi mDNS/DNS-SD Daemon is not running
root@fhem:/tmp# ls -ail /run/dbus/pid
ls: cannot access '/run/dbus/pid': No such file or directory
root@fhem:/tmp#
root@fhem:/tmp#
root@fhem:/tmp# dbus-daemon --system
root@fhem:/tmp# /etc/init.d/avahi-daemon start
Starting Avahi mDNS/DNS-SD Daemon: avahi-daemon.
root@fhem:/tmp#
root@fhem:/tmp# /etc/init.d/avahi-daemon status
Avahi mDNS/DNS-SD Daemon is running
sidey79 commented 10 months ago

Can you explain the reason, why you need avahi inside FHEM container and why you are not using it seperate?

Overall i think the service ist not told to be started automatic ( systemctl ).

tobiasfaust commented 10 months ago

Hi, i need avahi insinde the container because i want use Text2speech module and airplay2 devices as enpoints. I´m using this instructions: https://forum.fhem.de/index.php?topic=119278.0 So the described play.sh script needs an avahi-browse funtionality to determine the right port of the given IP-device.

set myTTS tts [192.168.10.102] Hier kommt ein Test!

I dont want to change the play.sh script because it should be automaticly installed by fhem dockerfile from github

Maybe its possible to add custom start script?

sidey79 commented 10 months ago

I am not familar with avahi, but i think best is to run this deamon in a seperate container and use network communication, because running it inside the fhem container will not detect if the deamon isn't running.

But to run a custom start command for this deamon inside the FHEM omage you can use following options:

Option 1

If something needs to be done only once during the first start of a fresh container you just created, like after upgrading to a new version of the FHEM Docker Image, the *-init.sh scripts are the right place:

/pre-init.sh, /docker/pre-init.sh

I think it is enough to run a update-rc.d avahi-daemon defaults once, but i haven't tested it.

Option 2

If something needs to be done every time you (re)start your container, the *-start.sh scripts are the right place:

/pre-start.sh, /docker/pre-start.sh

This script will be run every time the container starts, even before the FHEM Docker image's own startup preparations. FHEM will not yet be running at this point in time.

As an alternative to the first approach, you can run your init script manually from here: /etc/init.d/avahi-daemon status


One last note to your "apt upgrade" command. This will upgrade installed packages, but not overwrite the packages already installed in the fhem-minimal-docker:3-bullseye image. So you are adding an extra layer which needs extra space. The FHEM image itself is updated very often to not need this step on your side.