Can't start mosquitto on raspbian jessie using systemctl

13k views Asked by At

First did this:

systemctl stop mosquitto
update-rc.d mosquitto remove
rm /etc/init.d/mosquitto

Unit file as follows:

[Unit]
Description=MQTT v3.1 message broker
After=network.target
Requires=network.target

[Service]
Type=simple
ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Restart=always

[Install]
WantedBy=multi-user.target

Result of:

sudo systemctl status mosquitto -l

is:

● mosquitto.service - MQTT v3.1 message broker
   Loaded: loaded (/etc/systemd/system/mosquitto.service; enabled)
   Active: failed (Result: start-limit) since Sun 2017-01-01 19:44:03 GMT; 3min 23s ago
  Process: 683 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, status=1/FAILURE)
 Main PID: 683 (code=exited, status=1/FAILURE)

Jan 01 19:44:03 raspberrypi systemd[1]: Unit mosquitto.service entered failed state.
Jan 01 19:44:03 raspberrypi systemd[1]: mosquitto.service holdoff time over, scheduling restart.
Jan 01 19:44:03 raspberrypi systemd[1]: Stopping MQTT v3.1 message broker...
Jan 01 19:44:03 raspberrypi systemd[1]: Starting MQTT v3.1 message broker...
Jan 01 19:44:03 raspberrypi systemd[1]: mosquitto.service start request repeated too quickly, refusing to start.
Jan 01 19:44:03 raspberrypi systemd[1]: Failed to start MQTT v3.1 message broker.
Jan 01 19:44:03 raspberrypi systemd[1]: Unit mosquitto.service entered failed state.

I've done a lot of googling, and tried a few similar unit files, but nothing seems to work.

Running that command manually (/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf) gives:

Error: Unable to open log file /var/log/mosquitto/mosquitto.log for writing.
Error found at /etc/mosquitto/mosquitto.conf:11.
Error: Unable to open configuration file.

Strangely, running /usr/sbin/mosquitto, i.e. without specifying a .conf file, works fine. /etc/mosquitto/mosquitto.conf is the default .conf file, though, so it should use it even if I don't specify it...

1

There are 1 answers

0
umläute On BEST ANSWER

If something goes wrong, a good start is usually to look at the logfiles (all commands assumed to be run as root):

journalctl -u mosquitto

Now your specific errors (Error: Unable to open log file /var/log/mosquitto/mosquitto.log for writing.) hint that you are running into a permission problem.

  • Check the user the mosquitto daemon is running under.
  • Check that this user has read resp. write access to all necessary files (e.g. the logfiles)

Note: It's pretty easy to get wrong permissions of generated files, if you run the file-creating process under a wrong user (only once is enough - e.g. during testing)