MQTT failure with boot and reboot

Others (MiLight, Hue, Toon etc...)

Moderator: leecollings

Post Reply
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

MQTT failure with boot and reboot

Post by McMelloW »

Dear forumers

Code: Select all

uname -a
Linux rpi-2b 5.4.51-v7+ #1333 SMP Mon Aug 10 16:45:19 BST 2020 armv7l GNU/Linux
On this RPi-2B with Buster, I have created a mosquitto MQTT Broker.

Using <<sudo service mosquitto restart>> or stop and start work OK. But a reboot or shutdown and power-on boot, the port 1883 is still in use and I cannot start mosquitto.

I have to use sudo kill -kill <PID> to release the listener job.

What can I do to solve this problem?
Or is there a work around with a delaay in the reboot and/or shutdown?
Greetings McMelloW
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

Re: MQTT failure with boot and reboot

Post by erem »

a (re)boot kills all processes, so i conclude there must be something wrong in your mqtt start up.

what does systemctl status mosquitto tell you after reboot.
have you tried reinstalling mqtt?
Regards,

Rob
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: MQTT failure with boot and reboot

Post by McMelloW »

erem wrote: Monday 12 October 2020 13:45 what does systemctl status mosquitto tell you after reboot.
have you tried reinstalling mqtt?
It is a headless RPi only connected with an ethernet cable. Communication is done with Putty and ssh

status before reboot

Code: Select all

pi@rpi-2b:~ $ sudo service mosquitto status
? mosquitto.service - Mosquitto MQTT v3.1/v3.1.1 Broker
   Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset
   Active: active (running) since Mon 2020-10-12 14:37:30 CEST; 3s ago
     Docs: man:mosquitto.conf(5)
           man:mosquitto(8)
 Main PID: 1233 (mosquitto)
    Tasks: 1 (limit: 2065)
   CGroup: /system.slice/mosquitto.service
           ??1233 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Oct 12 14:37:30 rpi-2b systemd[1]: Starting Mosquitto MQTT v3.1/v3.1.1 Broker...
Oct 12 14:37:30 rpi-2b systemd[1]: Started Mosquitto MQTT v3.1/v3.1.1 Broker.
Staus after a reboot now

Code: Select all

pi@rpi-2b:~ $ sudo service mosquitto status
? mosquitto.service - Mosquitto MQTT v3.1/v3.1.1 Broker
   Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2020-10-12 14:38:22 CEST; 52s ago
     Docs: man:mosquitto.conf(5)
           man:mosquitto(8)
  Process: 403 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, status=1/FAILURE)
 Main PID: 403 (code=exited, status=1/FAILURE)

Oct 12 14:38:22 rpi-2b systemd[1]: mosquitto.service: Service RestartSec=100ms expired, scheduling restart.
Oct 12 14:38:22 rpi-2b systemd[1]: mosquitto.service: Scheduled restart job, restart counter is at 5.
Oct 12 14:38:22 rpi-2b systemd[1]: Stopped Mosquitto MQTT v3.1/v3.1.1 Broker.
Oct 12 14:38:22 rpi-2b systemd[1]: mosquitto.service: Start request repeated too quickly.
Oct 12 14:38:22 rpi-2b systemd[1]: mosquitto.service: Failed with result 'exit-code'.
Oct 12 14:38:22 rpi-2b systemd[1]: Failed to start Mosquitto MQTT v3.1/v3.1.1 Broker.

pi@rpi-2b:~ $ sudo netstat -anp | grep 1883
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN      382/mosquitto
tcp6       0      0 :::1883                 :::*                    LISTEN      382/mosquitto
Sudo kill -kill 382 makes it possible to start mosquitto again (sudo kill 382 does not work correctly in ssh on my RPi)
Greetings McMelloW
User avatar
FireWizard
Posts: 1968
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: MQTT failure with boot and reboot

Post by FireWizard »

Hi @McMellow,

Could you check the contents of /lib/systemd/system/mosquitto.service

Mine looks like:

Code: Select all

[Unit]
Description=Mosquitto MQTT v3.1/v3.1.1 Broker
Documentation=man:mosquitto.conf(5) man:mosquitto(8)
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
NotifyAccess=main
ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Restart=on-failure

[Install]
WantedBy=multi-user.target

Hopefully it is not the same as: viewtopic.php?t=32157

Regards
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: MQTT failure with boot and reboot

Post by McMelloW »

Hoi @FireWizard
FireWizard wrote: Monday 12 October 2020 21:37 Hi @McMellow,

Could you check the contents of /lib/systemd/system/mosquitto.service

Mine looks like:
Mine looks exact as yours. I did not touched it at all.
Hopefully it is not the same as: viewtopic.php?t=32157

Regards
Did checked it already. it is not the case.
Greetings McMelloW
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

Re: MQTT failure with boot and reboot

Post by erem »

googling the error message yielded this

https://github.com/eclipse/mosquitto/issues/1419

downgrading mqtt may help.

to diagnose further you could try and disable starting thru systemd and check if port 1883 is still used.
from above link i read the error is caused by port 1883 already being used when systemd tries to start mqtt

keep us updated.
Regards,

Rob
User avatar
FireWizard
Posts: 1968
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: MQTT failure with boot and reboot

Post by FireWizard »

Hi @McMelloW

In addition to @erem post you could have a look at: /etc/mosquitto/mosquitto.conf.

Mine looks:

Code: Select all

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

port 1883

pid_file /var/run/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

#log_dest file /var/log/mosquitto/mosquitto.log

#include_dir /etc/mosquitto/conf.d
I found a post at: https://github.com/eclipse/mosquitto/issues/882
If you go to the post: chris-008 commented on 12 Aug 2018 you will find a solution that worked for him.
You can try to comment the line with the port no 1883.
No guarantee that it is the solution, as I have seen other posts, saying it doesn't work.
But worthwhile to try, at least.

Regards
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: MQTT failure with boot and reboot

Post by McMelloW »

@erem and @FireWizard.

Hey guys, Yess...Got it working!!!

Thank you so much for your support. Used the steps from the final post from chris008 as mentioned above.
Made changes to mosquitto.service and to mosquitto.conf.

Code: Select all

sudo systemctl daemon-reload
sudo reboot now 
Mosquitto is up and running.
Greetings McMelloW
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest