I installed via the all-in-one installer. I was under the impression that mosquitto would start at boot but it hasn’t been. I ran the systemctl status and got this:
pi@homeassistant:~ $ sudo systemctl status mosquitto.service -l
● mosquitto.service - Mosquitto MQTT Broker daemon
Loaded: loaded (/etc/systemd/system/mosquitto.service; enabled)
Active: activating (auto-restart) (Result: exit-code) since Wed 2017-01-04 23:08:58 PST; 250ms ago
Process: 1688 ExecStart=/usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf -d (code=exited, status=3)
Jan 04 23:08:58 homeassistant systemd[1]: Failed to start Mosquitto MQTT Broker daemon.
Jan 04 23:08:58 homeassistant systemd[1]: Unit mosquitto.service entered failed state.
Jan 04 23:08:58 homeassistant mosquitto[1688]: Error found at /etc/mosquitto/mosquitto.conf:19.
Jan 04 23:08:58 homeassistant mosquitto[1688]: Error: Unable to open configuration file.
I looked at line 19 in my config file and it is log_dest /var/log/mosquitto/mosquitto.log
I commented it out and then I get this:
pi@homeassistant:~ $ sudo systemctl start mosquitto.service
Job for mosquitto.service failed. See 'systemctl status mosquitto.service' and 'journalctl -xn' for details.
pi@homeassistant:~ $ sudo systemctl status mosquitto.service -l
● mosquitto.service - Mosquitto MQTT Broker daemon
Loaded: loaded (/etc/systemd/system/mosquitto.service; enabled)
Active: activating (auto-restart) (Result: resources) since Wed 2017-01-04 23:11:56 PST; 1s ago
Process: 1979 ExecStart=/usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf -d (code=exited, status=0/SUCCESS)
Jan 04 23:11:56 homeassistant systemd[1]: Unit mosquitto.service entered failed state.
I’m not sure its the problem, but this line only has one t. Reading the man page, it should be the same as in the password_file, so I would check that is the case.
That’s weird, somehow autocorrect must have changed that when I copy/pasted it here from my text editor. it is “mosquitto” in my config file. Thanks for the suggestion!
When I launch mosquitto from the command line it works as expected. It just won’t auto-start with systemctl.
also, when I do launch mosquitto from the prompt that way, it tells my its using the default configuration. I don’t know if that means it’s not using my config file?
pi@homeassistant:~ $ mosquitto
1483630748: mosquitto version 1.4.9 (build date 2016-11-22 14:44:16-0800) starting
1483630748: Using default config.
1483630748: Opening ipv4 listen socket on port 1883.
1483630748: Opening ipv6 listen socket on port 1883.
By default, mosquitto doesn’t read the config file, so its probably something in your config file that is stopping it working. I suggest specifying a different config file and adding each line until it stops.
Thanks for that tip. I found there is an error opening the pwfile. I see that the file is owned by user “mosquitto” while everything else in the directory is owned by “pi” or “root”
pi@homeassistant:~ $ mosquitto -c /etc/mosquitto/mosquitto.conf
1483734032: mosquitto version 1.4.9 (build date 2016-11-22 14:44:16-0800) starting
1483734032: Config loaded from /etc/mosquitto/mosquitto.conf.
1483734032: Error: Unable to open pwfile "/etc/mosquitto/pwfile".
1483734032: Error opening password file "/etc/mosquitto/pwfile".
pi@homeassistant:/etc/mosquitto $ ls -l
total 92
-rw-r--r-- 1 root root 230 Nov 22 14:47 aclfile.example
-rwxrwxrwx 1 pi pi 37019 Jan 5 07:37 mosquitto.conf
-rw-r--r-- 1 root root 36806 Nov 22 14:47 mosquitto.conf.example
-rw-r--r-- 1 root root 23 Nov 22 14:47 pskfile.example
-rw------- 1 mosquitto mosquitto 13 Nov 23 14:48 pwfile
-rw-r--r-- 1 root root 355 Nov 22 14:47 pwfile.example
I assume I need to change this. does this need to be a root file or owned by ‘pi’? How about the permissions?
pi@homeassistant:~ $ mosquitto -c /etc/mosquitto/mosquitto.conf
1483736874: mosquitto version 1.4.9 (build date 2016-11-22 14:44:16-0800) starting
1483736874: Config loaded from /etc/mosquitto/mosquitto.conf.
1483736874: Opening websockets listen socket on port 9001.
1483736874: Error: Unable to create websockets listener on port 9001.
That would imply that something is probably already listening on 9001. You can see that through netstat (although not sure what all is included on pi as I use an ubuntu box).
Is there a reason you aren’t using 1883 (unencrypted) or 8883 (encrypted)? Those are standard MQTT ports.
Also, as I am sure you figured out from your comment above, whatever user you start mosquitto under needs read access. You would have to do a "sudo -u " if you wanted to test it under the mosquitto user to see how it really runs instead of trying to just do “mosquitto -c …”.
Actually, the pwfile has those permissions because mosquitto is configured to be run as the user mosquitto, and only that user should have persmission to read the pwfile - as a security precaution.
As @mstberto said above, you can use sudo -u mosquitto … to run the program as the mosquitto user, which will be the final goal.
Hey guys, thanks a bunch for all the replies. I managed to get it working! I’m still not sure what the original problem was but after I deleted the password file and created a new one it worked.
The reason the port was busy when I checked it with mosquitto -c /etc/mosquitto/mosquitto.conf was because my fix allowed the systemctl to actually launch when I rebooted but I didn’t realize it.
I set it to 9001 for a reason I don’t remember…probably just some tutorial I was following or because of some conflict with another service. Oh well, it works fine now! Cheers
I just wanted to thank everyone is this topic to also help me resolve my issue of mosquitto no longer working.
Running mosquitto -c /etc/mosquitto/mosquitto.conf gave me a first clue and there the problem was that my /var/log was 100% full.
After resolving that issue, the problem became that mosquitto would start on port 1883 but immediately shutdown again. The mosquitto.log indicated a second attempt to start another instance on port 1883. After some research, it seems something might have changed in version 1.5.
By commenting out the listener 1883 as suggested in the mosquitto.conf, everything is working again.