15

In my ongoing endeavors to get my Raspberry Pi to command my stuff I set up a Mosquitto MQTT broker. In the base settings everything went reasonably fine.

I could post test messages with the publish command and receive them with the subscribe command. Then I decided to up the log level and modified the mosquitto.conf file as follows. The version with essentially the whole log section commented out works. The other doesn't.

I narrowed it down to the line with the log file.

$ diff mosquitto.conf mosquitto.conf.old
408,410c408,410
< #log_dest file /var/log/mosquitto/mosquitto.log
---
> log_dest file /var/log/mosquitto/mosquitto.log

The file exists and is owned by mosquitto:mosquitto, the user which runs the service.

The very helpful message I do get when trying with the logging is the following:

mosquitto_pub -h localhost -t thisisme -m 5
Error: Connection refused

By now, I'm sure that the service dies a silent death.

$ sudo service mosquitto status
● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker
   Loaded: loaded (/etc/init.d/mosquitto)
   Active: active (exited) since Fri 2017-01-06 11:16:38 CET; 4min 24s ago
  Process: 2222 ExecStop=/etc/init.d/mosquitto stop (code=exited, status=0/SUCCESS)
  Process: 2230 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCCESS)

Jan 06 11:16:38 T-Pi mosquitto[2230]: Starting network daemon:: mosquitto.
Jan 06 11:16:38 T-Pi systemd[1]: Started LSB: mosquitto MQTT v3.1 message broker.

I'm running Raspbian GNU/Linux 8 (jessie) with the following mosquitto packages:

libmosquitto1/stable,now 1.3.4-2 armhf [installed,automatic]
mosquitto/stable,now 1.3.4-2 armhf [installed]
mosquitto-clients/stable,now 1.3.4-2 armhf [installed]
python-mosquitto/stable,now 1.3.4-2 all [installed]

Further comment requested information:

ls -ld /var /var/log /var/log/mosquitto /var/log/mosquitto/mosquitto.log
drwxr-xr-x 11 root      root       4096 Sep 23 06:02 /var
drwxr-xr-x  8 root      root       4096 Jan  6 21:07 /var/log
drwxr-xr-x  2 mosquitto mosquitto  4096 Jan  5 14:36 /var/log/mosquitto
-rw-r--r--  1 mosquitto mosquitto 14233 Jan  6 21:07 /var/log/mosquitto/mosquitto.log

The only log file in /var/log that gets modified is the auth.log from my sudo.

What did I break?

Helmar
  • 8,450
  • 6
  • 36
  • 84

3 Answers3

9

One way to debug this would be to run mosquitto manually with the same options as your init system is using, then look at the output. For example:

mosquitto -v -c <path to config file>

Adding -v will ensure that you have verbose logging, regardless of the config file settings.

ralight
  • 880
  • 4
  • 5
6

The log directory/file should be owned by the mosquitto user or the user that you have setup in the conf file and group. I tried with two conf files one with out log_dest file /var/log/mosquitto/mosquitto.log and one with log destination to file.

On my server Mosquitto is running with mosquitto user.

With log_dest file /var/log/mosquitto/mosquitto.log owned by root user is not working with service status error. This probably might be the case for you also. Check the service status after you add log_dest.

I tried changing the ownership of /var/log/mosquitto folder to mosquitto.

sudo chown -R mosquitto:mosquitto /var/log/mosquitto

Then started the service. It's working fine now.

Helmar
  • 8,450
  • 6
  • 36
  • 84
bravokeyl
  • 1,550
  • 1
  • 13
  • 27
6

On Arch Linux (4.4.37-1-ARCH) with mosquitto 1.4.10-2 and an existing logfile/path with permissions as such I cannot reproduce this error.

/var/log/mosquitto $ ls -l
-rw-r--r-- 1 mosquitto root 7832 Jan 5 18:15 mosquitto.log

If the permissions of the logfile however differ, or it does not exist and the directories permission do not allow mosquitto to write to it, starting the broker daemon fails. Which than leads to Error: Connection refused upon publishing or subscribing topics. At least the service does not die a silent death but announces it well in the syslog.

In short with the directory /var/log/mosquitto owned by and writeable by the mosquitto user a log_dest file [...] line in mosquitto's config works just fine.

Helmar
  • 8,450
  • 6
  • 36
  • 84
Ghanima
  • 2,539
  • 1
  • 19
  • 46