Mosquitto MQTT broker does not restart after altering the config file

I have installed the Mosquitto MQTT broker on my Pi as per this tuturial:
https://randomnerdtutorials.com/how-to-install-mosquitto-broker-on-raspberry-pi/
After altering the config file to enable user names and password authentication I’m getting this error when restarting the broker:

ko@raspberrypi:~ $ sudo systemctl restart mosquitto
Job for mosquitto.service failed because the control process exited with error code.
See “systemctl status mosquitto.service” and “journalctl -xeu mosquitto.service” for details.

Here the ouput from the two logs suggested:

ko@raspberrypi:~ $ systemctl status mosquitto.service
× mosquitto.service - Mosquitto MQTT Broker
Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; preset: enabled)
Active: failed (Result: exit-code) since Tue 2024-02-27 20:15:13 +07; 29min ago
Duration: 1w 2h 12min 30.372s
Docs: man:mosquitto.conf(5)
man:mosquitto(8)
Process: 185416 ExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto (code=exited, status=0/SUCCESS)
Process: 185417 ExecStartPre=/bin/chown mosquitto /var/log/mosquitto (code=exited, status=0/SUCCESS)
Process: 185418 ExecStartPre=/bin/mkdir -m 740 -p /run/mosquitto (code=exited, status=0/SUCCESS)
Process: 185419 ExecStartPre=/bin/chown mosquitto /run/mosquitto (code=exited, status=0/SUCCESS)
Process: 185420 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, status=1/FAILURE)
Main PID: 185420 (code=exited, status=1/FAILURE)
CPU: 27ms
Feb 27 20:15:13 raspberrypi systemd[1]: mosquitto.service: Scheduled restart job, restart counter is at 5.
Feb 27 20:15:13 raspberrypi systemd[1]: Stopped mosquitto.service - Mosquitto MQTT Broker.
Feb 27 20:15:13 raspberrypi systemd[1]: mosquitto.service: Start request repeated too quickly.
Feb 27 20:15:13 raspberrypi systemd[1]: mosquitto.service: Failed with result ‘exit-code’.
Feb 27 20:15:13 raspberrypi systemd[1]: Failed to start mosquitto.service - Mosquitto MQTT Broker.

ko@raspberrypi:~ $ journalctl -xeu mosquitto.service
░░ Subject: A start job for unit mosquitto.service has failed
░░ Defined-By: systemd
░░ Support: Debian -- User Support
░░
░░ A start job for unit mosquitto.service has finished with a failure.
░░
░░ The job identifier is 37624 and the job result is failed.
Feb 27 20:15:13 raspberrypi systemd[1]: mosquitto.service: Scheduled restart job, restart counter is at 5.
░░ Subject: Automatic restarting of a unit has been scheduled
░░ Defined-By: systemd
░░ Support: Debian -- User Support
░░
░░ Automatic restarting of the unit mosquitto.service has been scheduled, as the result for
░░ the configured Restart= setting for the unit.
Feb 27 20:15:13 raspberrypi systemd[1]: Stopped mosquitto.service - Mosquitto MQTT Broker.
░░ Subject: A stop job for unit mosquitto.service has finished
░░ Defined-By: systemd
░░ Support: Debian -- User Support
░░
░░ A stop job for unit mosquitto.service has finished.
░░
░░ The job identifier is 37702 and the job result is done.
Feb 27 20:15:13 raspberrypi systemd[1]: mosquitto.service: Start request repeated too quickly.
Feb 27 20:15:13 raspberrypi systemd[1]: mosquitto.service: Failed with result ‘exit-code’.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: Debian -- User Support
░░
░░ The unit mosquitto.service has entered the ‘failed’ state with result ‘exit-code’.
Feb 27 20:15:13 raspberrypi systemd[1]: Failed to start mosquitto.service - Mosquitto MQTT Broker.
░░ Subject: A start job for unit mosquitto.service has failed
░░ Defined-By: systemd
░░ Support: Debian -- User Support
░░
░░ A start job for unit mosquitto.service has finished with a failure.
░░
░░ The job identifier is 37702 and the job result is failed.

Can anyone identify what the issue is here?

1 Like

Basic troubleshooting questions, sorry if I’m being too basic…
Did it start up and work properly before setting up the username and password?
If you change “allow_anonymous” to true (in /etc/mosquitto/conf.d”) will it start?
My .conf file on the Mosquitto broker that I’m using a username and password on is shown below, if that helps.

pid_file /run/mosquitto/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

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

include_dir /etc/mosquitto/conf.d

allow_anonymous false

listener 1883
password_file /etc/mosquitto/pwdfile

I found it. Apparently the listener port 1883 was being used by some other service. I have no idea which. After changing it to 1884 mosquitto restarts normally again.

1 Like