MQTT mosquitto installation failed

Tags: #<Tag:0x00007efeccdbf7c8> #<Tag:0x00007efeccdbf6d8>

Dear all,
i am trying to install mosquitto broker on my raspberry pi 3+.
On this device also openhabian is running.

Howevery i always receive failure messages.
I googled and tried a lot but still i am stuck.

I also tried to re-install it several times.
Maybe someone of you can help :slight_smile:

Manual installation and by using the openhabian-config result in the same:

sudo apt-get install -y mosquitto mosquitto-clients
Reading package lists... Done
Building dependency tree
Reading state information... Done
mosquitto-clients is already the newest version (1.5.7-1+deb10u1).
The following packages were automatically installed and are no longer required:
  rpi-eeprom-images triggerhappy
Use 'sudo apt autoremove' to remove them.
Suggested packages:
  apparmor
The following NEW packages will be installed:
  mosquitto
0 upgraded, 1 newly installed, 0 to remove and 6 not upgraded.
Need to get 0 B/143 kB of archives.
After this operation, 318 kB of additional disk space will be used.
Selecting previously unselected package mosquitto.
(Reading database ... 49969 files and directories currently installed.)
Preparing to unpack .../mosquitto_1.5.7-1+deb10u1_armhf.deb ...
Unpacking mosquitto (1.5.7-1+deb10u1) ...
Setting up mosquitto (1.5.7-1+deb10u1) ...
Job for mosquitto.service failed because the control process exited with error code.
See "systemctl status mosquitto.service" and "journalctl -xe" for details.
invoke-rc.d: initscript mosquitto, action "start" failed.
● mosquitto.service - Mosquitto MQTT v3.1/v3.1.1 Broker
   Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Sun 2020-11-22 19:56:49 CET; 32ms ago
     Docs: man:mosquitto.conf(5)
           man:mosquitto(8)
  Process: 5617 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, status=1/FAILURE)
 Main PID: 5617 (code=exited, status=1/FAILURE)
dpkg: error processing package mosquitto (--configure):
 installed mosquitto package post-installation script subprocess returned error exit status 1
Processing triggers for man-db (2.8.5-2) ...
Processing triggers for systemd (241-7~deb10u4+rpi1) ...
Errors were encountered while processing:
 mosquitto
Updating FireMotD available updates count ...
E: Sub-process /usr/bin/dpkg returned an error code (1)

sudo service mosquitto status shows this:

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 Sun 2020-11-22 19:56:52 CET; 7min ago
     Docs: man:mosquitto.conf(5)
           man:mosquitto(8)
  Process: 5808 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, status=
 Main PID: 5808 (code=exited, status=1/FAILURE)

Nov 22 19:56:52 openhab systemd[1]: mosquitto.service: Service RestartSec=100ms expired, scheduling
Nov 22 19:56:52 openhab systemd[1]: mosquitto.service: Scheduled restart job, restart counter is at
Nov 22 19:56:52 openhab systemd[1]: Stopped Mosquitto MQTT v3.1/v3.1.1 Broker.
Nov 22 19:56:52 openhab systemd[1]: mosquitto.service: Start request repeated too quickly.
Nov 22 19:56:52 openhab systemd[1]: mosquitto.service: Failed with result 'exit-code'.
Nov 22 19:56:52 openhab systemd[1]: Failed to start Mosquitto MQTT v3.1/v3.1.1 Broker.

mosquitto -v shows this:

mosquitto -v
1606071881: mosquitto version 1.5.7 starting
1606071881: Using default config.
1606071881: Opening ipv4 listen socket on port 1883.
1606071881: Error: Address already in use

More details from installation:

systemctl status mosquitto.service
● 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 Sun 2020-11-22 19:56:52 CET; 9min ago
     Docs: man:mosquitto.conf(5)
           man:mosquitto(8)
  Process: 5808 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, status=
 Main PID: 5808 (code=exited, status=1/FAILURE)

Nov 22 19:56:52 openhab systemd[1]: mosquitto.service: Service RestartSec=100ms expired, scheduling
Nov 22 19:56:52 openhab systemd[1]: mosquitto.service: Scheduled restart job, restart counter is at
Nov 22 19:56:52 openhab systemd[1]: Stopped Mosquitto MQTT v3.1/v3.1.1 Broker.
Nov 22 19:56:52 openhab systemd[1]: mosquitto.service: Start request repeated too quickly.
Nov 22 19:56:52 openhab systemd[1]: mosquitto.service: Failed with result 'exit-code'.
Nov 22 19:56:52 openhab systemd[1]: Failed to start Mosquitto MQTT v3.1/v3.1.1 Broker.
1606071881: Error: Address already in use

What else have you got running on port 1883?

How can i check this? :slight_smile:

What does

journalctl -xe

show ?

means that the related port ( 1883 ) is already used by a service.
Do

netstat -tulpe

to check what is running on that port

2 Likes
journalctl -xe
-- Subject: Session 75 has been terminated
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- Documentation: https://www.freedesktop.org/wiki/Software/systemd/multiseat
--
-- A session with the ID 75 has been terminated.
Nov 22 20:07:47 openhab sudo[6563]:  openhab : TTY=unknown ; PWD=/var/lib/openhab2 ; USER=root ; COM
Nov 22 20:07:47 openhab sudo[6563]: pam_unix(sudo:session): session opened for user root by (uid=0)
Nov 22 20:07:47 openhab sudo[6565]:     root : TTY=unknown ; PWD=/var/lib/openhab2 ; USER=root ; COM
Nov 22 20:07:47 openhab sudo[6565]: pam_unix(sudo:session): session opened for user root by (uid=0)
Nov 22 20:07:47 openhab sudo[6565]: pam_unix(sudo:session): session closed for user root
Nov 22 20:07:47 openhab sudo[6568]:     root : TTY=unknown ; PWD=/var/lib/openhab2 ; USER=root ; COM
Nov 22 20:07:47 openhab sudo[6568]: pam_unix(sudo:session): session opened for user root by (uid=0)
Nov 22 20:07:47 openhab kernel: debugfs: File 'le_min_key_size' in directory 'hci0' already present!
Nov 22 20:07:47 openhab kernel: debugfs: File 'le_max_key_size' in directory 'hci0' already present!
Nov 22 20:07:47 openhab sudo[6568]: pam_unix(sudo:session): session closed for user root
Nov 22 20:07:56 openhab sudo[6527]: pam_unix(sudo:session): session closed for user root
Nov 22 20:08:27 openhab sudo[6563]: pam_unix(sudo:session): session closed for user root
Nov 22 20:09:11 openhab dhcpcd[605]: wlan0: Router Advertisement from fe80::de53:7cff:fead:4049
Nov 22 20:09:32 openhab sudo[6667]:  openhab : TTY=unknown ; PWD=/var/lib/openhab2 ; USER=root ; COM
Nov 22 20:09:32 openhab sudo[6667]: pam_unix(sudo:session): session opened for user root by (uid=0)
Nov 22 20:09:32 openhab sudo[6669]:     root : TTY=unknown ; PWD=/var/lib/openhab2 ; USER=root ; COM
Nov 22 20:09:32 openhab sudo[6669]: pam_unix(sudo:session): session opened for user root by (uid=0)
Nov 22 20:09:32 openhab sudo[6669]: pam_unix(sudo:session): session closed for user root
Nov 22 20:09:32 openhab sudo[6671]:     root : TTY=unknown ; PWD=/var/lib/openhab2 ; USER=root ; COM
Nov 22 20:09:32 openhab sudo[6671]: pam_unix(sudo:session): session opened for user root by (uid=0)
Nov 22 20:09:32 openhab kernel: debugfs: File 'le_min_key_size' in directory 'hci0' already present!
Nov 22 20:09:32 openhab kernel: debugfs: File 'le_max_key_size' in directory 'hci0' already present!
Nov 22 20:09:32 openhab sudo[6671]: pam_unix(sudo:session): session closed for user root
Nov 22 20:10:12 openhab sudo[6667]: pam_unix(sudo:session): session closed for user root
Nov 22 20:12:08 openhab sudo[6750]: openhabian : TTY=pts/3 ; PWD=/home/openhabian ; USER=root ; COMM
Nov 22 20:12:08 openhab sudo[6750]: pam_unix(sudo:session): session opened for user root by openhabi
Nov 22 20:12:09 openhab systemd[1]: Configuration file /etc/systemd/system/pilight.service is marked
Nov 22 20:12:11 openhab sudo[6750]: pam_unix(sudo:session): session closed for user root
Nov 22 20:12:16 openhab sudo[6762]:  openhab : TTY=unknown ; PWD=/var/lib/openhab2 ; USER=root ; COM
Nov 22 20:12:16 openhab sudo[6762]: pam_unix(sudo:session): session opened for user root by (uid=0)
Nov 22 20:12:16 openhab sudo[6764]:     root : TTY=unknown ; PWD=/var/lib/openhab2 ; USER=root ; COM
Nov 22 20:12:16 openhab sudo[6764]: pam_unix(sudo:session): session opened for user root by (uid=0)
Nov 22 20:12:16 openhab sudo[6764]: pam_unix(sudo:session): session closed for user root
Nov 22 20:12:16 openhab sudo[6766]:     root : TTY=unknown ; PWD=/var/lib/openhab2 ; USER=root ; COM
Nov 22 20:12:16 openhab sudo[6766]: pam_unix(sudo:session): session opened for user root by (uid=0)
Nov 22 20:12:16 openhab kernel: debugfs: File 'le_min_key_size' in directory 'hci0' already present!
Nov 22 20:12:16 openhab kernel: debugfs: File 'le_max_key_size' in directory 'hci0' already present!
Nov 22 20:12:16 openhab sudo[6766]: pam_unix(sudo:session): session closed for user root

i only see this related to port 1883:

netstat -tulpe
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode      PID/Program name
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN      root       18901

Can you try

sudo netstat -tulpe

the related process might not be shown if it’s executed without root privileges but the process belongs e.g. to root.

This is the ouput:

sudo netstat -tulpe
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode      PID/Program name

tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN      root       998117     7071/pilight-daemon

As you can see the pilight-daemon uses port 1883 and that is why mosquitto cannot use that port.
I don’t know what pilight-daemon is. in case both services are required one or the other needs to use another port.

Ahhh ok understand.
However i dont see a possibility to change this in the pilight config.
Is it possible to change it in the mosquitto config?

Yes: https://mosquitto.org/man/mosquitto-conf-5.html

Scroll to port

Bear in mind that MQTT has 1883 as the default for everything, so you will always have extra configuration when setting up your MQTT devices!

I think this

pilight now contains a MQTT broker

is the reason.

According to https://forum.pilight.org/showthread.php?tid=3675 it should be able to disable MQTT that comes with pilight and it will use mosquitto as external broker then.

1 Like

This i didnt knew!
So i disable pilight and tried it again.

mosquitto -v
1606074003: mosquitto version 1.5.7 starting
1606074003: Using default config.
1606074003: Opening ipv4 listen socket on port 1883.
1606074003: Opening ipv6 listen socket on port 1883.
^C1606074047: mosquitto version 1.5.7 terminating

Because this was not doing anything for 5 minutes i did strg+c.

Also this is the same:

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 Sun 2020-11-22 19:56:52 CET; 43min ago
     Docs: man:mosquitto.conf(5)
           man:mosquitto(8)
  Process: 5808 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, status=1/FAILURE)
 Main PID: 5808 (code=exited, status=1/FAILURE)

Nov 22 19:56:52 openhab systemd[1]: mosquitto.service: Service RestartSec=100ms expired, scheduling restart.
Nov 22 19:56:52 openhab systemd[1]: mosquitto.service: Scheduled restart job, restart counter is at 10.
Nov 22 19:56:52 openhab systemd[1]: Stopped Mosquitto MQTT v3.1/v3.1.1 Broker.
Nov 22 19:56:52 openhab systemd[1]: mosquitto.service: Start request repeated too quickly.
Nov 22 19:56:52 openhab systemd[1]: mosquitto.service: Failed with result 'exit-code'.
Nov 22 19:56:52 openhab systemd[1]: Failed to start Mosquitto MQTT v3.1/v3.1.1 Broker.

EDIT:
I disabled the mqtt in the pilight settings and re-installed mosquitto again and now it works!!
Thank you for your help :slight_smile:

1 Like