mosquitto - auto start not functioning - manual startup needed

Created on 14 Jul 2018  Â·  15Comments  Â·  Source: eclipse/mosquitto

Hi,

After reboot of my pi, mosquitto won't start even though when checking the status, it says it's active:

pi@orangepizero:~$ sudo systemctl status mosquitto.service
â—Ź mosquitto.service - Mosquitto MQTT Broker
Loaded: loaded (/etc/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2018-07-14 23:51:07 CEST; 15ms ago
Docs: man:mosquitto(8)
man:mosquitto.conf(5)
Main PID: 1330 (mosquitto)
Tasks: 0 (limit: 4915)
CGroup: /system.slice/mosquitto.service
└─1330 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Jul 14 23:51:07 orangepizero systemd[1]: Started Mosquitto MQTT Broker.

It's only after i manually start
sudo mosquitto
that everything starts working.

I checked all auto start after reboot sequences and tried them but nothing helps so far?

Any help is much appreciated!!

need-more-information

All 15 comments

Have you had a look at the mosquitto log file? ( cat /var/log/mosquitto.log, if i recall correctly)

Try this

sudo systemctl enable mosquitto

Hi guys,
Can’t seem to find the log file.
Tried the enable option already but doesn’t help.
Thx for your suggestions though

Your conf file will define where the log file is located have a look in /etc/mosquitto/mosquitto.conf
which will tell you.

@chris-008 did you find the log file?

@chris-008 If this is still an issue, try running manually with exactly the same command as systemd uses:

/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

This may highlight the error.

hi guys, sorry haven't been online much lately during the summer holidays.
Thanks for the info though , will check it soon and give feedback!

so I found the log file under /var/log/mosquitto/mosquitto.log.
Next error is produced frequently:

1531629123: mosquitto version 1.5 starting
1531629123: Config loaded from /etc/mosquitto/mosquitto.conf.
1531629123: Opening ipv4 listen socket on port 1883.
1531629123: Error: Address already in use

After some googling, I found that it seems because two copies of mosquitto are running?
after checking my installations, I only found one install though:

apt list --installed:
...
mosquitto/stretch,now 1.5-0mosquitto2 armhf [installed]
mosquitto-clients/stretch,now 1.5-0mosquitto2 armhf [installed]
...

After a Pi reboot, the mosquitto service seems to be running:
pi@orangepizero:~$ systemctl status mosquitto.service
â—Ź mosquitto.service - Mosquitto MQTT Broker daemon
Loaded: loaded (/etc/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Sat 2018-08-11 23:13:39 CEST; 1min 49s ago
Process: 524 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf -d (code=exited, status=0/SUCCESS)
Main PID: 524 (code=exited, status=0/SUCCESS)

Aug 11 23:13:39 orangepizero systemd[1]: Started Mosquitto MQTT Broker daemon.

However, it doesn't work. Only after manually starting mosquitto it will work?

Thanks. I found the same "Error: Address already in use" reported on #894 .

Here is a copy of my conf file:

Place your local configuration in /etc/mosquitto/conf.d/

#

A full description of the configuration file is at

/usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /var/run/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

log_type all

allow_anonymous false
password_file /etc/mosquitto/passwd
listener 1883

I tried changing the mosquitto username and passwordfile again,as this in some cases helped, but to no avail.

pi@orangepizero:~$ mosquitto -c /etc/mosquitto/mosquitto.conf
1534028168: Error: Unable to open log file /var/log/mosquitto/mosquitto.log for writing.

So it seems like I don't have write acces to the " /var/log/mosquitto/mosquitto.log" file ?

Referring to #894, I have commented out the listener 1883 and rebooted, but no change.

try this :
$ touch /var/log/mosquitto/mosquitto.log
$ chmod 777 /var/log/mosquitto/mosquitto.log

thx for the help, the error is gone.
Still not working though.

after checking the mosquitto service status, I also noticed next line:

Active: inactive (dead) since Sun 2018-08-12 02:02:00 CEST; 6s ago

I assume this indicates that Mosquitto is not running?
I tried systemctl start mosquitto and enable the service, but no change.

I read that it could be systemd related.

Here are the results of the mosquitto service file, anything weird in it?

[Unit]
Description=Mosquitto MQTT Broker daemon
ConditionPathExists=/etc/mosquitto/mosquitto.conf
Requires=network.target

[Service]
Type=simple
ExecStartPre=/bin/sh -c '/usr/bin/test -d /var/run/mosquitto || /bin/mkdir /var/run/mosquitto || /bin/chown mosquitto:mosquitto /var/run/mosquitto || /bin/rm -f /var/run/mosquitto/mosquitto.pid’
ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf -d
ExecReload=/bin/kill -HUP $MAINPID
PIDFile=/var/run/mosquitto/mosquitto.pid
Restart=on-failure

[Install]
WantedBy=multi-user.target

Yess...Got it working!!!

Went through quite a lot of websites about this matter, seems to be a known (systemd) problem.
So this worked for me:
Have the mosquitto.service file configured as follows:

image

then comment the listener 1883 line in the mosquitto conf file :

image
image

hope this helps!

@chris-008
Thanks for the code.
However, I see that all the logs go to the syslog file rather than the log destination mentioned in the mosquitto conf file.
log_dest file /var/log/mosquitto/mosquitto.log

Was this page helpful?
0 / 5 - 0 ratings