5

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...

Alex
  • 2,270
  • 3
  • 33
  • 65
  • so what happens if you start mosquitto manually using `/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf`?? – umläute Jan 01 '17 at 20:39
  • @umläute The answer to that is quite long, so I've put it in the question. – Alex Jan 01 '17 at 21:06
  • thanks for putting the additional info into the question (this is where it belongs). the issue seems to be mainly with permissions (e.g. you are running the process as the wrong user); what is the output of `journalctl -u mosquitto` (after a failed attempt to start it via systemctl) – umläute Jan 01 '17 at 21:13
  • It seems to work now. I chown'd the log file as it didn't seem to be owned by the user mosquitto. It is now, and it's working. Thanks for your help! – Alex Jan 01 '17 at 21:22

1 Answers1

6

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)

umläute
  • 28,885
  • 9
  • 68
  • 122