openHABian - Mosquitto MQTT failed to start

made a mistake when writing. In openhub, I installed the mqtt binding

Hi Folks,

any progess on this subject? I also installed a brandnew Pi4B with 4 GB with the actual official openhabian image and have exactly the same issue (works fine until reboot; cannot find log-file).

which is not what @minorus wrote so it isn’t the same issue.
Properly state your problem if you want help.
What do systemctl status mosquitto.service and journalctl -xu mosquitto.service say?

I have just the same problem. I could not find a solution for mosquitto. I had to use embedded-mqtt-broker. There are no problems with him

Perhaps I used the wrong answer button. I refer to the start of this thread where @dexterbot80 wrote, that he had a fresh installation of openhabian from the official link, installed Mosquitto successfully through openhabian-config ending up with Mosquitto being unable to start after the first reboot caused by not beeing able to open the log-file, as the Mosquitto directory under var/log is not existing.

You helped him by guiding him to switch to the master version in openhabian-config, but as @Howard_Benn wrote, that did not help in my case either. And as this thread is some days old I hoped that there might be a solution now.

Here are the outputs you wanted, where you can see in journalctl, that the log-file is not available.

[08:22:45] openhabian@openhab2neu:~$ systemctl status mosquitto.service
● mosquitto.service - Mosquitto MQTT v3.1/v3.1.1 Broker
Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2020-11-04 08:19:29 CET; 3min 36s ago
Docs: man:mosquitto.conf(5)
man:mosquitto(8)
Process: 839 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, status=1/FAILURE)
Main PID: 839 (code=exited, status=1/FAILURE)

Nov 04 08:19:29 openhab2neu systemd[1]: mosquitto.service: Service RestartSec=100ms expired, scheduling restart.
Nov 04 08:19:29 openhab2neu systemd[1]: mosquitto.service: Scheduled restart job, restart counter is at 5.
Nov 04 08:19:29 openhab2neu systemd[1]: Stopped Mosquitto MQTT v3.1/v3.1.1 Broker.
Nov 04 08:19:29 openhab2neu systemd[1]: mosquitto.service: Start request repeated too quickly.
Nov 04 08:19:29 openhab2neu systemd[1]: mosquitto.service: Failed with result ‘exit-code’.
Nov 04 08:19:29 openhab2neu systemd[1]: Failed to start Mosquitto MQTT v3.1/v3.1.1 Broker.

 [08:23:46] openhabian@openhab2neu:~$ journalctl -xu mosquitto.service
    -- Logs begin at Tue 2020-11-03 08:20:43 CET, end at Wed 2020-11-04 08:25:01 CET. --
    Nov 03 18:15:42 openhab2neu systemd[1]: Starting Mosquitto MQTT v3.1/v3.1.1 Broker...
    -- Subject: A start job for unit mosquitto.service has begun execution
    -- Defined-By: systemd
    -- Support: https://www.debian.org/support
    --
    -- A start job for unit mosquitto.service has begun execution.
    --
    -- The job identifier is 109.
    Nov 03 18:15:43 openhab2neu mosquitto[504]: 1604423743: Error: Unable to open log file /var/log/mosquitto/mosquitto.log for writing.
    Nov 03 18:15:43 openhab2neu systemd[1]: mosquitto.service: Main process exited, code=exited, status=1/FAILURE
    -- Subject: Unit process exited
    -- Defined-By: systemd
    -- Support: https://www.debian.org/support
    --
    -- An ExecStart= process belonging to unit mosquitto.service has exited.
    --
    -- The process' exit code is 'exited' and its exit status is 1.
    Nov 03 18:15:43 openhab2neu systemd[1]: mosquitto.service: Failed with result 'exit-code'.
    -- Subject: Unit failed
    -- Defined-By: systemd
    -- Support: https://www.debian.org/support
    --
    -- The unit mosquitto.service has entered the 'failed' state with result 'exit-code'.
    Nov 03 18:15:43 openhab2neu systemd[1]: Failed to start Mosquitto MQTT v3.1/v3.1.1 Broker.
    -- Subject: A start job for unit mosquitto.service has failed
    -- Defined-By: systemd
    -- Support: https://www.debian.org/support
    --
    -- A start job for unit mosquitto.service has finished with a failure.
    --
    -- The job identifier is 109 and the job result is failed.
    Nov 03 18:15:43 openhab2neu systemd[1]: mosquitto.service: Service RestartSec=100ms expired, scheduling restart.
    Nov 03 18:15:43 openhab2neu systemd[1]: mosquitto.service: Scheduled restart job, restart counter is at 1.
    -- Subject: Automatic restarting of a unit has been scheduled
    -- Defined-By: systemd
    -- Support: https://www.debian.org/support
    --
    -- Automatic restarting of the unit mosquitto.service has been scheduled, as the result for
    -- the configured Restart= setting for the unit.
    Nov 03 18:15:43 openhab2neu systemd[1]: Stopped Mosquitto MQTT v3.1/v3.1.1 Broker.
    -- Subject: A stop job for unit mosquitto.service has finished
    -- Defined-By: systemd
    -- Support: https://www.debian.org/support
    --
    -- A stop job for unit mosquitto.service has finished.
    --
    -- The job identifier is 263 and the job result is done.
    Nov 03 18:15:43 openhab2neu systemd[1]: Starting Mosquitto MQTT v3.1/v3.1.1 Broker...
    -- Subject: A start job for unit mosquitto.service has begun execution
    -- Defined-By: systemd
    -- Support: https://www.debian.org/support
    --
    -- A start job for unit mosquitto.service has begun execution.
    --
    -- The job identifier is 263.
    Nov 03 18:15:43 openhab2neu mosquitto[597]: 1604423743: Error: Unable to open log file /var/log/mosquitto/mosquitto.log for writing.
    Nov 03 18:15:43 openhab2neu systemd[1]: mosquitto.service: Main process exited, code=exited, status=1/FAILURE
    -- Subject: Unit process exited
    -- Defined-By: systemd
    -- Support: https://www.debian.org/support
    --
    -- An ExecStart= process belonging to unit mosquitto.service has exited.
    --
    -- The process' exit code is 'exited' and its exit status is 1.
    Nov 03 18:15:43 openhab2neu systemd[1]: mosquitto.service: Failed with result 'exit-code'.
    -- Subject: Unit failed
    -- Defined-By: systemd
    -- Support: https://www.debian.org/support
    --
    -- The unit mosquitto.service has entered the 'failed' state with result 'exit-code'.
    Nov 03 18:15:43 openhab2neu systemd[1]: Failed to start Mosquitto MQTT v3.1/v3.1.1 Broker.
    -- Subject: A start job for unit mosquitto.service has failed
    -- Defined-By: systemd
    -- Support: https://www.debian.org/support
    --
    -- A start job for unit mosquitto.service has finished with a failure.
    --
    -- The job identifier is 263 and the job result is failed.
    Nov 03 18:15:43 openhab2neu systemd[1]: mosquitto.service: Service RestartSec=100ms expired, scheduling restart.
    Nov 03 18:15:43 openhab2neu systemd[1]: mosquitto.service: Scheduled restart job, restart counter is at 2.
    -- Subject: Automatic restarting of a unit has been scheduled
    -- Defined-By: systemd
    -- Support: https://www.debian.org/support

Try

mkdir -p /var/log/mosquitto /opt/zram/log.bind/mosquitto
chown mosquitto /var/log/mosquitto /opt/zram/log.bind/mosquitto
systemctl start mosquitto.service

Create /lib/systemd/system/mosquitto.service.d/override.conf to contain

[Unit]
After=network-online.target zram-config.service
Wants=network-online.target zram-config.service
5 Likes

Thanks for reply! Seems to work now. There still is a warning, but Mosquitto has started. Following the advice to restart the servis, the warning is gone, but comes back after a reeboot. Anything to worry about?

[13:24:01] openhabian@openhab2neu:~$ systemctl status mosquitto.service
Warning: The unit file, source configuration file or drop-ins of mosquitto.service changed on disk. Run 'sy
● mosquitto.service - Mosquitto MQTT v3.1/v3.1.1 Broker
   Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/mosquitto.service.d
           └─override.conf
   Active: active (running) since Wed 2020-11-04 13:20:08 CET; 3min 55s ago
     Docs: man:mosquitto.conf(5)
           man:mosquitto(8)
 Main PID: 1014 (mosquitto)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/mosquitto.service
           └─1014 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Nov 04 13:20:07 openhab2neu systemd[1]: Starting Mosquitto MQTT v3.1/v3.1.1 Broker...
Nov 04 13:20:08 openhab2neu systemd[1]: Started Mosquitto MQTT v3.1/v3.1.1 Broker.

Not restart but systemctl daemon-reload.
Might still appear after but that’s probably a known cosmetic bug then.

OK, then I will leave it this way. Thanks again!

I’m not sure what to do about this now.

I am having the same problem. I am trying to migrate my Pi 3 to a new Pi 4 setup with more reliable backups and so on. So I started with a new RPi. Everything else moves across OK, rules, items, bindings. I even managed to work out how to move Node-Red and its credentials.

But the Mosquitto broker will not run. It fails on startup and I get the same error as others here about not being able to access /var/log/mosquitto/mosquitto.log.

I tried disabling zram (is this related to the cause?) and I’ve tried reinstalling Mosquitto with the same error as others again

There was an error or interruption during the execution of: │
│ “20 | Optional Components”

I’ve read through this thread and I’m not sure if we’ve found the answer. The more I muck about with trying different things, the further away from a clean standard installation I get and I worry if I’m breaking something else or future upgrades.

This is a device that controls things I use every day (wife not happy if something fails) so I prefer to keep to stable packages with as little deviation from standard setups as possible. I’m not a beginner with Openhab but I am no Linux or RPi expert so I’m just following people who know more than me.

Does anyone have a definitive summary view on why a clean installation of the latest Openhabian downloadable image onto a 16GB card installed in a brand new 2GB Pi4 cannot run Mosquitto? Better still, a way to make it work without making my system “non-standard” and perhaps not upgradeable. Even better, is there a fix coming for the standard Openhabian download?

Post #41 does not work for you ?

That’s what I added as a fix to openHABian, too. So if you install from scratch it should work right away. Just make sure you use the master branch to install (default is stable).

Ah - super. That’s what I was looking for. Many thanks

I was a bit concerned that if I make a structural change it might get undone on the next update and then mission-critical stuff like my entire heating system falls over! I’m a bit reluctant to go creating new directories and changing ownerships to make something work but now I know you’re right on top of it and it is being incorporated in later versions too then I am happy.

I’ll make the change tonight and hopefully I’m all good

Many thanks for the reply Markus

Can confirm: Installing mosquitto from the setup menu (sudo openhabian-config) works perfectly, set up several devices, all in proper working order. Reboot, no mosquitto. Manually restarting it results in authentication errors from the OH bridge thing. So something is definitely up here.

Update: It turns out the MQTT bridge was not configured correctly, although it boggles my mind how it worked on initial installation but not after reboot. At any rate, adding username/password to the thing configuration resolves the issue. Although the restart issue still remains, but that’s easy enough to hack around.

1 Like

Can confirm what ? Which openHABian branch did you install and when ? Did you check if the code from post 41 is present already ?

Can confirm what’s in the post right above you: Mosquitto installs from openhabian-config, works fine until reboot/restart. Post 41 code doesn’t fix anything.

openHAB Distribution Version Information

build-no : Release Build
online-repo : https://openhab.jfrog.io/openhab/libs-release

Repository Version

openhab-distro : 2.5.4
openhab-core : 2.5.0
openhab1-addons : 1.14.0
openhab2-addons : 2.5.4
karaf : 4.2.7

I realize this isn’t a “help desk” (as seems to be pointed out quite often here), just letting folks know the problem still exists.

Well AFAIK you’re the only one with this problem. You didn’t answer which openHABian branch you use. Does journalctl -xu mosquitto.service give any hint ?
openHAB version is not of interest and I don’t know what an “OA bridge” is so can’t tell if that’s related.
I doubt you run a OH core 2.5.0. Either way, that’s pretty old. Is your openHABian installation even buster based ? Have you ever upgraded openHABian OS packages (menu 02) ?
You should move to openHABian master and could try to uninstall and reinstall zram then eventually reinstall mosquitto.

Update: Discovered the problem: In addition to the ‘:’ character, there are apparently other prohibited password characters not enumerated in the mosquitto_passwd manpage. One of these is apparently ‘$’. Don’t bother using it in your password; authentication will fail.

Here is what is misleading: For whatever reason, when mosquitto is first installed from openhabian-config, access is set to ‘allow_anonymous true’. This allows any publisher/subscriber to connect, even though it might appear that authentication is being used. If the mosquitto daemon is restarted, allow_anonymous reverts to whatever is in the .conf file (false by default).

Obviously not an OH issue, but might still cause some issues due to lack of documentation.

Original post: It was installed from one of the pre-built OpenHABian images, probably mid-2019. I really can’t speak for the accuracy of the version info that’s installed with OpenHABian; I would assume it is at least close to be correct. At any rate, I doubt it’s an OH issue, so it probably has nothing to do with the OpenHABian branch that the image was built from.

If I find a solution I’ll post here to help others who might run into this problem.

Thanks Marcus for your prompt help. I suffered the same issue with a new install of the openhabian image on RPi3b.
Following your instructions, repeated below for those that need it too, everything works as it should, no errors:

"mkdir -p /var/log/mosquitto /opt/zram/log.bind/mosquitto
chown mosquitto /var/log/mosquitto /opt/zram/log.bind/mosquitto
systemctl start mosquitto.service

Create /lib/systemd/system/mosquitto.service.d/override.conf to contain

[Unit]
After=network-online.target zram-config.service
Wants=network-online.target zram-config.service
"
Thanks for your help.

Hello! Post 41 solved this issue for me after fresh openhabian install with latest 1.6 openhabian
Thank you!

I was having a similar issue. After installing Mosquitto using openhabian-config, everything seemed to work fine. But after doing some troubleshooting to get MQTT working, Mosquitto stopped working. I tried to find log files, run files, etc., but couldn’t find any indication there was a working version on the Pi (3B+). I tried reinstalling it a few times (as per the instructions) - no go. I tried removing it with apt and reinstalling with openhabian-config - same issue. Finally, I removed it and reinstalled it with apt - it is working again, well kind-of. Being my first iteration of MQTT, I’m having other issues, but at least the broker is online.