openhab / openhabian

openHABian - empowering the smart home, for Raspberry Pi and Debian systems
https://community.openhab.org/t/13379
ISC License
820 stars 251 forks source link

Mosquitto install not working ? #1538

Closed mstormi closed 3 years ago

mstormi commented 3 years ago

@ecdye see https://community.openhab.org/t/openhabian-mosquitto-mqtt-failed-to-start/102951/86

I was able to reproduce by flashing an image, installing mosquitto from the menu and then reboot. See below for status after reboot. So the reason is /var/log/mosquitto is gone. Manually purged + installed mosquitto again via menu: /var/log/mosquitto is back. Rebooted again, /var/log/mosquitto is gone again.

There's a report this happens with openhab and homegear, too (although I don't trust that statement as it obviously isn't true for openhab) but it's sign of a common zram issue.

Note unlike some other packages we create the systemd config for, the mosquitto package comes with its own mosquitto.service so we would need to sed-edit or replace that OR use the override config as in my post #41 see there for my fix. That is not in our code though.

[14:43:31] root@smarthouse:/home/admin# systemctl start mosquitto
Job for mosquitto.service failed because the control process exited with error code.
See "systemctl status mosquitto.service" and "journalctl -xe" for details.
[13:13:10] root@smarthouse:/home/admin# zramctl
NAME       ALGORITHM DISKSIZE  DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram3 zstd          450M 27.4M  1.2M  1.6M       4 /opt/zram/zram3
/dev/zram2 zstd          350M 16.3M  6.1K  100K       4 /opt/zram/zram2
/dev/zram1 zstd          350M 16.3M  3.7K   68K       4 /opt/zram/zram1
/dev/zram0 lzo-rle       450M    4K   86B   12K       4 [SWAP]

[13:13:01] root@smarthouse:/home/admin# cat /lib/systemd/system/mosquitto.service
[Unit]
Description=Mosquitto MQTT v3.1/v3.1.1 Broker
Documentation=man:mosquitto.conf(5) man:mosquitto(8)
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
NotifyAccess=main
ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Restart=on-failure

[Install]
WantedBy=multi-user.target

[13:13:19] root@smarthouse:/home/admin# /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
1623928413: Error: Unable to open log file /var/log/mosquitto/mosquitto.log for writing.
[13:13:33] root@smarthouse:/home/admin# ls -ld /var/log
drwxr-xr-x 1 root root 4096 Jun 17 12:13 /var/log
[13:13:55] root@smarthouse:/home/admin#
mstormi commented 3 years ago

This worked as a post-install fix:

mkdir -p /opt/zram/log.bind/mosquitto
chown mosquitto /opt/zram/log.bind/mosquitto

That's creating the directory on the lowerFS so it's there when zram starts. Do you think that is a proper fix ? Not sure why zram-config.service didn't sync back /var/log/mosquitto.

mstormi commented 3 years ago

I was able to reproduce this for grafana and homegear, too. Same fix applies.

ecdye commented 3 years ago

Sorry for the delayed response, I was out camping with my Family and just got back, I'll try to look at this and the other issues over the weekend and figure out the best solution.

mstormi commented 3 years ago

No worries, there's a life beyond the screen, too. Just returned from my son's vaccination.