Mosquitto doesn't autostart after upgrade of Raspbian and Python

I did the upgrade of Jessie to Stretch and Python to 3.6.3 yesterday, also my setup is on a Pi2 in virtualenv. I’ve mostly been following Bruh automation guides. After the upgrade, i get a mqtt error card in HA. Try to go through Bruh’s guide again, and it’s still installed, the config file is still there and still as it was before. trying to run mosquitto_sub or .../pub gives me Error: Connection refused. I tried to delete the pwfile and regenerate it, but no change. I google around and tried the following:

sudo systemctl enable mosquitto.service
sudo systemctl start mosquitto.service
sudo systemctl status mosquitto.service

but still nothing, even with restart of only HA. Now, if i run the command mosquitto only, it seems to be starting. And then HA works after a restart, but not on reboot. I nano into /etc/init/mosquitto.conf, /etc/mosquitto/mosquitto.conf and /etc/init.d/mosquitto and they all look good.

TL;DR: I think i found the issue, I just don’t know how to fix it. The /etc/systemd/system/mosquitto.service is missing, and i have no idea how to regenerate it. I’ve seen several inconsistent examples of what it should look like, so i’m thinking it should be generated and not copy/pasted. Any input on this?

I found a solution myself. I’m sure there is a way to regenerate /etc/systemd/system/mosquitto.service, but since I don’t know how to, I basically just uninstalled and installed it again:

sudo apt-get purge mosquitto
sudo apt-get purge mosquitto-clients
sudo rm /etc/mosquitto/pwfile
sudo reboot

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install mosquitto
sudo apt-get install mosquitto-clients
sudo nano /etc/mosquitto/mosquitto.conf

    #include_dir /etc/mosquitto/conf.d <---This line is to be removed/commented out

    allow_anonymous false
    password_file /etc/mosquitto/pwfile
    listener 1883

sudo mosquitto_passwd -c /etc/mosquitto/pwfile username (Replace username, set your own)
sudo reboot

That’s it, happy days :slight_smile:

1 Like

Great.

Btw. after modifying systemd service you have to run sudo systemctl daemon-reload. That might be what you have been looking for.