eclipse / mosquitto

Eclipse Mosquitto - An open source MQTT broker
https://mosquitto.org
Other
8.61k stars 2.33k forks source link

Can't start mosquitto.service #1603

Open Coelhomatias opened 4 years ago

Coelhomatias commented 4 years ago

hi, installed with the apt-get install method. Can't autostart so I ran sudo systemctl start mosquitto.service and then sudo systemctl status mosquitto.service and this is the output:

Loaded: loaded (/etc/systemd/system/mosquitto.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Tue 2020-02-18 18:54:47 WET; 4s ago Docs: man:mosquitto.conf(5) man:mosquitto(8) Process: 1949 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, status=1/FAILURE) Main PID: 1949 (code=exited, status=1/FAILURE)

Feb 18 18:54:47 raspberrypi systemd[1]: mosquitto.service: Service RestartSec=100ms expired, scheduling restart. Feb 18 18:54:47 raspberrypi systemd[1]: mosquitto.service: Scheduled restart job, restart counter is at 5. Feb 18 18:54:47 raspberrypi systemd[1]: Stopped Mosquitto MQTT v3.1/v3.1.1 Broker. Feb 18 18:54:47 raspberrypi systemd[1]: mosquitto.service: Start request repeated too quickly. Feb 18 18:54:47 raspberrypi systemd[1]: mosquitto.service: Failed with result 'exit-code'. Feb 18 18:54:47 raspberrypi systemd[1]: Failed to start Mosquitto MQTT v3.1/v3.1.1 Broker.

so i executed /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf and it outputed:

1582051833: mosquitto version 1.5.7 starting 1582051833: Config loaded from /etc/mosquitto/mosquitto.conf. 1582051833: Error: Unable to open pwfile "/etc/mosquitto/passwd ". 1582051833: Error opening password file "/etc/mosquitto/passwd ".

it seems to be a permissions problem, tried some things but can't get it to work. Can anybody help pls?

ralight commented 4 years ago

Try doing sudo /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf instead - I doubt your user would (or should) have access to /etc/mosquitto/passwd. Hopefully that will tell you why it is failing.

onire77 commented 3 years ago

Hi, I have the same problem on openSuse, my user is root:

vmi:/etc/mosquitto # service mosquitto status
● mosquitto.service - Mosquitto MQTT v3.1/v3.1.1 Broker
   Loaded: loaded (/usr/lib/systemd/system/mosquitto.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2020-09-16 09:22:43 CEST; 7min ago
     Docs: man:mosquitto.conf(5)
           man:mosquitto(8)
  Process: 1676 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, status=1/FAILURE)
 Main PID: 1676 (code=exited, status=1/FAILURE)

Sep 16 09:22:43 vmi436410 systemd[1]: Started Mosquitto MQTT v3.1/v3.1.1 Broker.
Sep 16 09:22:43 vmi436410 mosquitto[1676]: 1600240963: Loading config file /etc/mosquitto/conf.d/TLSconfig.conf
Sep 16 09:22:43 vmi436410 mosquitto[1676]: mosquitto version 1.6.12 starting
Sep 16 09:22:43 vmi436410 mosquitto[1676]: Config loaded from /etc/mosquitto/mosquitto.conf.
Sep 16 09:22:43 vmi436410 mosquitto[1676]: Error: Unable to open pwfile "/etc/mosquitto/passwd".
Sep 16 09:22:43 vmi436410 mosquitto[1676]: Error opening password file "/etc/mosquitto/passwd".
Sep 16 09:22:43 vmi436410 systemd[1]: mosquitto.service: Main process exited, code=exited, status=1/FAILURE
Sep 16 09:22:43 vmi436410 systemd[1]: mosquitto.service: Unit entered failed state.
Sep 16 09:22:43 vmi436410 systemd[1]: mosquitto.service: Failed with result 'exit-code'.
vmi:/etc/mosquitto #

for a few weeks it worked and since yesterday it no longer works.

karelhuis commented 3 years ago

Dear people, i am a newbee and im proud to got the instal on mij raspberri pi. (domnoticz works fine)

A have a mqtt stick, it works fine i think, i can ad and a see the zigbee sensor but than... Nothing, got a tip i should test if the server is running, It dit not, so thats the problem. I found in ssh the error, but i have no clou..

Hope you know what i could do.. Best regards Karel

● 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-12-30 21:47:33 CET; 1min 15s ago Docs: man:mosquitto.conf(5) man:mosquitto(8) Process: 504 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, status=1/FAILURE) Main PID: 504 (code=exited, status=1/FAILURE)

dec 30 21:47:33 raspberrypi systemd[1]: mosquitto.service: Service RestartSec=100ms expired, scheduling restart. dec 30 21:47:33 raspberrypi systemd[1]: mosquitto.service: Scheduled restart job, restart counter is at 5. dec 30 21:47:33 raspberrypi systemd[1]: Stopped Mosquitto MQTT v3.1/v3.1.1 Broker. dec 30 21:47:33 raspberrypi systemd[1]: mosquitto.service: Start request repeated too quickly. dec 30 21:47:33 raspberrypi systemd[1]: mosquitto.service: Failed with result 'exit-code'. dec 30 21:47:33 raspberrypi systemd[1]: Failed to start Mosquitto MQTT v3.1/v3.1.1 Broker.

lost-RD commented 3 years ago

In my case the issue is that the log file at /var/log/mosquitto/mosquitto.log is corrupt. This is the first time I've seen a corrupt file on a GNU/Linux system.

$ ls -la /var/log/mosquitto/
ls: cannot access '/var/log/mosquitto/mosquitto.log': No such file or directory
total 40
drwxr-xr-x 2 root root  4096 Feb 3 00:00 .
drwxr-xr-x 1 root root  4096 Feb 5 00:00 ..
c????????? ? ?    ?        ?           ? mosquitto.log
-rw-rw-rw- 1 root root 27127 Feb 3 00:00 mosquitto.log.1.gz

I did have a power outage a couple of days ago but the system came back online without a hitch, it was only after a proper system shutdown last night that mosquitto wouldn't start. No idea whether this is a mosquitto issue or a system issue, everything else seems unaffected though.

ralight commented 3 years ago

@lost-RD wow, that looks like filesystem corruption to me - I'd make sure you've got your data off there.

Everybody else - my comment about running sudo /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf to get more information still stands.

lost-RD commented 3 years ago

Wrote an empty file to the file address and chmod 666 and mosquitto is back up and running, I'll take that advice and backup.

briveramelo commented 3 years ago

@lost-RD I had a similar file corruption happen recently to my mosquitto log file too. I'm working in a multi-tenant environment, so I do not have the permissions to remove the corrupted file myself. I'm using the most recent docker image as of 2/19/2021

ralight commented 3 years ago

On further reading you can get this sort of effect if the stat() call fails. The stat man page lists these reasons for possible failure:

In conclusion - I'm not much the wiser as to what could have caused it, or why it's showing as it is.

WombatHollow commented 3 years ago

It sounds like you might be trying to start Mosquitto twice, the first time is a leftover from earlier versions that need deletion. The words below are from a post in another thread.

There was a root CRON job that runs launcher.shwhich contained sudo mosquitto -d

How did I find it. Well once I found CRON has a @reboot option I looked further and found CRON is by user including root. So I winged it and tried sudo crontab -l hoping the use of sudo finds root cronjobs instead of pi user jobs and there as a another job.

After that it was a tidy up of all the other things I had tweaked and re-enable the systemd job on reboot. sudo systemctl enable mosquitto.service

So now have 2.0.11 working as I like. I suspect that CRON job was a left over from earlier versions of Mosquitto (I was on 1.5 or 1.6) but the update to 2.0.11 didn't delete it when it created the mosquitto.service job.

Pritish9 commented 3 years ago

I had the same issue after typing the command sudo /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf got

1624240992: Loading config file /etc/mosquitto/conf.d/bk_default.conf 
1624240992: Loading config file /etc/mosquitto/conf.d/custom.conf
1624240992: Error: Duplicate password_file value in configuration.
1624240992: Error found at /etc/mosquitto/conf.d/custom.conf:2.
1624240992: Error found at /etc/mosquitto/mosquitto.conf:11.

I found out I had multiple config files, so I removed the old ones.

Hope it helps!

ACavdar commented 2 years ago

: mosquitto.service: Scheduled restart job, restart counter is at 5. : Stopped Mosquitto MQTT Broker. : mosquitto.service: Start request repeated too quickly. : mosquitto.service: Failed with result 'exit-code'. : Failed to start Mosquitto MQTT Broker.

When I checked service logs via

journalctl -u mosquitto.service

It pointed out default configuration file line 11 where it includes custom configurations directory. Then I noticed a whitespace at the end of the line

include_dir /etc/mosquitto/conf.d

I removed the whitespace character and saved the file. It's all OK now.

rolo98 commented 2 years ago

I have a similar problem

sudo systemctl start mosquitto.service Failed to start mosquitto.service: Unit mosquitto.service not found.

litehacker commented 1 year ago

I have run into this problem after making configured SSL for a droplet server running on NGINX. Configurations I have for mymain domain:

server{
    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.ge/fullchain.pem; # managed by>
    ssl_certificate_key /etc/letsencrypt/live/example.ge/privkey.pem; # managed >
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    server_name example.ge www.example.ge;
    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        # location /overview {
        #     proxy_pass http://127.0.0.1:3000$request_uri;
        #     proxy_redirect off;
        # }
    }
}

server {
    if ($host = mtkvaripay.ge) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = www.mtkvaripay.ge) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

        listen 80;
        listen [::]:80;

        server_name example.ge www.example.ge;
        return 404; # managed by Certbot
}

the idea was to add sumdomain mqtt.example.ge and have secured SSL there too. so I followed an outdated the only existing tutorial on Digital Ocean for the purpose How to Install and Secure the Mosquitto MQTT Messaging Broker on Ubuntu 18.04

Here are /etc/mosquitto/conf.d/default.conf configs:

allow_anonymous false
password_file /etc/mosquitto/passwd

listener 1883 localhost

listener 8883
certfile /etc/letsencrypt/live/mqtt.example.ge/cert.pem
cafile /etc/letsencrypt/live/mqtt.example.ge/chain.pem
keyfile /etc/letsencrypt/live/mqtt.example.ge/privkey.pem

listener 8083
protocol websockets
certfile /etc/letsencrypt/live/mqtt.example.ge/cert.pem
cafile /etc/letsencrypt/live/mqtt.example.ge/chain.pem
keyfile /etc/letsencrypt/live/mqtt.example.ge/privkey.pem
zamnut commented 1 month ago

I ran into a similar problem (shown below). By looking at /var/log/mosquitto/mosquitto.log I figured out I needed to change the permissions/user of the passwd file:

sudo chmod 700 passwd sudo chown mosquitto passwd sudo chgrp mosquitto passwd

it went from: -rw------- 1 root root 120 May 18 12:39 passwd to: -rwx------ 1 mosquitto mosquitto 120 May 18 12:39 passwd

it works now.

mosquitto.service - Mosquitto MQTT Broker Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Sat 2024-05-18 16:47:43 EDT; 7s ago Docs: man:mosquitto.conf(5) man:mosquitto(8) Process: 57222 ExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto (code=exited, status=0/SUCCESS) Process: 57223 ExecStartPre=/bin/chown mosquitto:mosquitto /var/log/mosquitto (code=exited, status=0/SUCCESS) Process: 57224 ExecStartPre=/bin/mkdir -m 740 -p /run/mosquitto (code=exited, status=0/SUCCESS) Process: 57225 ExecStartPre=/bin/chown mosquitto:mosquitto /run/mosquitto (code=exited, status=0/SUCCESS) Process: 57226 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, status=13) Main PID: 57226 (code=exited, status=13)

May 18 16:47:43 focus systemd[1]: mosquitto.service: Scheduled restart job, restart counter is at 5. May 18 16:47:43 focus systemd[1]: Stopped Mosquitto MQTT Broker. May 18 16:47:43 focus systemd[1]: mosquitto.service: Start request repeated too quickly. May 18 16:47:43 focus systemd[1]: mosquitto.service: Failed with result 'exit-code'. May 18 16:47:43 focus systemd[1]: Failed to start Mosquitto MQTT Broker.