sktaylortrash / TCPLightingWebInterface-MQTT-Docker

Dockerized Web App interface with MQTT: to control the "Connected by TCP" bulbs
MIT License
0 stars 0 forks source link

Docker Container Exits #3

Closed bmcgowan32 closed 1 year ago

bmcgowan32 commented 1 year ago

Im hoping for a bit of guidance. I cloned your repo, adjusted the docker-compose to reflect my bridge IP and MQTT info, but the container wont stay running. Ive tried it on a Ubuntu machine running docker engine, and on both OSX and Windows running Docker Desktop. All of my environments run other containers successfully, but none can start this one.

Every time it stops the container just after calling the subscriber. I can talk to the httpd during the startup, so I am pretty sure my port mappings and such are good. It kinda looks as if the boot.sh scripts aren't executing properly, as I dont see the updates to the config.inc.php either?

sktaylortrash commented 1 year ago

First off thanks for trying this out. I never know if I'm the only one using it or not.

A couple of things off the top of my head where I've observed this behaviour.

The credentials file tcp.token is critical to the app's function.

Occasionally when testing some of my bridges needed to be in pairing mode before starting the container. I have 5 bridges all on the same firmware version and 2 require this from time to time. I could not find a reproducible pattern

bmcgowan32 commented 1 year ago

Thanks! And "Thank You!" for this tool. Ive been running the MQTT version for a year or so and it made my life so much easier! Ill give these ideas a try!

bmcgowan32 commented 1 year ago

Thanks so much for responding so quick!

So here's a bit more info. When I inspect the container after the run, I can see that the layers from the Dockerfile are being executed. Things like the apache config changes, the insertion of the /var/www/html dir, etc all seem to go fine. But then when it calls boot.sh, its like the ENV variables set in docker-compose arent making it. The sed changes dont appear to get applied. Then it does successfully startup apache and run the curls to get the MQTT stuff. But I am guessing that since its not getting the variables, it isnt going to the right IP/URL, and as such the mqtt_sub.py file is empty. And when it tried to run that, the container just dumps. Im going to go back and see if there is any debugging for the env variable that I can set. I think thats my issue...

sktaylortrash commented 1 year ago

That is strange I haven't run across the sed stuff not working before. But until now I didn't know if I was the only user of this version.

If you want to post your compose I can sanity-check that something isn't amiss there for you.

bmcgowan32 commented 1 year ago

Thank you! I might take you up on the offer. I figured out the biggest issue... I was using "docker run" vs "docker compose" to spin up the container. Rookie move.

However, I still have a missing substitution from the ENV, and I am still crashing out when calling mqtt_sub.py. I think I found the missing substitution while trying to debug the ENV passing overall. It looks like the variable names for the pub/sub topics dont quite line up. In the docker-compose file they have an upper case character, but in the boot.sh (sed commands), they are lower case:

In docker-compose:

in boot.sh:

sed -i "s|MQTTSubscriber|$MQTT_Subscriber|" /var/www/html/config.inc.php sed -i "s|MQTTPublisher|$MQTT_Publisher|" /var/www/html/config.inc.php

So the sed substitution leaves thse values empty in the config.inc.php. But I tried changing the code to align names, and still not getting those values plugged into the config. My search to fix this continues

Not sure if that is what is ultimately what crashing the mqtt_sub.py, but I am further along!!

bmcgowan32 commented 1 year ago

Upon more playing, adjusting the docker-compose file variable names to match boot.sh fixed the substitution problem. I just had to dump the container and start from a fresh config. So now I just need to figure out why mqtt_sub.py is failing. I've tried it both with a DNS name and IP.. Verified that the container is able to resolve the DNS name and that it has connectivity to the MQTT port on my HA box.

Still digging...

2023-09-08 10:52:56 /var/www/html/mqtt_sub.py: line 1: syntax error near unexpected token `'homeassistant.local','

2023-09-08 10:52:56 /var/www/html/mqtt_sub.py: line 1: `client.connect('homeassistant.local', 1883,60)'

and...

TCPLightingWebInterface-MQTT | /var/www/html/mqtt_sub.py: line 1: syntax error near unexpected token `'192.168.1.118','

TCPLightingWebInterface-MQTT | /var/www/html/mqtt_sub.py: line 1: `client.connect('192.168.1.118', 1883,60)'

Could be that its the token thing now. Ill turn my attention back to your initial suggestions!

sktaylortrash commented 1 year ago

Ah, good catch on the case. Had both lowercase on my local but never pushed that to Git Hub. Will push now.

I've never used Home Assistant's internal MQTT server I always spin up my own in another container. So I can reboot HA without taking down everything else.

It also lets me make this container dependent on my MQTT container being running and healthy before attempting to start.

depends_on: \
  mosquitto: \
    condition: service_healthy
bmcgowan32 commented 1 year ago

Thanks for the update to the repo... One more tiny change though, should be "MQTT_publisher" not "MQTT_sublisher"

sed -i "s|MQTTPublisher|$MQTT_sublisher|" /var/www/html/config.inc.php

sktaylortrash commented 1 year ago

Lol fixed

bmcgowan32 commented 1 year ago

Oh! This is a really good idea for deploying the mqtt broker! I'm going to try that out next!

sktaylortrash commented 1 year ago

I just pushed an alternate docker-compose that has the Broker and dependencies configured

sktaylortrash commented 1 year ago

I've also just pushed a corrected version to docker hub as I forgot to do that as well

bmcgowan32 commented 1 year ago

Thank you for all the help! I have the container running successfully! Tips for future users:

Setup a BLANK token file before you compose the container. I tried copying in my tcp.token file from another running instance and it didn't work. Just start with a empty file and grab a new token at boot. I tried starting without a token file and letting the setup script create one...that also didn't work. Best practice would be to follow the instructions above:

Thanks @sktaylortrash for all your help!!

sktaylortrash commented 1 year ago

Great to hear. You honestly shouldn't need to clone the repo. Just use the docker-compose file of your choice.
The code in the repo would only be necessary if you wanted to build your own version of the image. Otherwise, the one hosted on docker hub and referenced in the compose file should be the same

sktaylortrash commented 1 year ago

@bmcgowan32 thanks again for helping iron out the issues. I've updated the readme with some of your points and also linked to additional info for anyone wanting to the broker dependency stuff. Should definitely help anyone else who comes along next