13

When I ran the Mosquitto (MQTT) broker for the first time there was no issue. But however from he second time when i ran it using default config I could not run the code successfully because of the following error:

1379497253: mosquitto version 1.2 (build date 2013-09-17 17:59:39+0530) starting
1379497253: Using default config.
1379497253: Opening ipv6 listen socket on port 1883.
1379497253: Error: Address already in use

I would like to know how to stop the broker from command line. It'll be nice if someone can help.

hardillb
  • 54,545
  • 11
  • 67
  • 105
user2430996
  • 341
  • 1
  • 4
  • 12

6 Answers6

18

mosquitto starts to be a service.

sudo vi /etc/mosquitto/mosquitto.conf #more detail in `man mosquitto.conf`

sudo vi /etc/mosquitto/conf.d/custom.conf #add or change listening port as your need

sudo service mosquitto restart
ileadu
  • 181
  • 1
  • 4
13

If you don't know the PID, than you can use "pkill" instead of "kill" in linux. Command: "pkill mosquitto"

KingAlex1985
  • 659
  • 1
  • 8
  • 9
  • PKill works for me. my vps does not have servicectl and "service mosquitto stop" not also working. so thanx. – XBasic3000 May 15 '21 at 04:32
6

You don't say which OS you are using, but assuming it's Linux and you have mosquitto running in the background, you just use the kill command.

Use ps to find the pid of the currently running mosquitto instance then kill the pid.

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • kill the pid should not be the best answer. As it runs as a service, stop the service is a better approach – manasouza Mar 24 '18 at 19:48
  • 1
    @manasouza given the complete lack of information given in the question it was the only guaranteed way to ensure it was stopped. We did not know for sure it was running as a service. – hardillb Mar 24 '18 at 20:28
3

You can use your own batch script file like mosquit.sh in bash. This is my script to stop it on CentOS.

#!/bin/sh
sudo kill $(ps aux |awk '/mosquitto/ {print $2}')
tommybee
  • 2,409
  • 1
  • 20
  • 23
1

Assuming it's the linux service, a kill command will only stop using that particular socket, and will open up on another socket upon killing the PID. On redhat, to kill the service would be systemctl stop mosquitto

John Green
  • 11
  • 1
  • 1
1

For Windows, open a Console as Administrator and use

taskkill /im <programname.exe> /f

Where /im = select by program (image) name, and /f = force -

C:\Users\bburns
> taskkill /im mosquitto.exe
ERROR: The process "mosquitto.exe" with PID 5344 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).

C:\Users\bburns
> taskkill /im mosquitto.exe /f
SUCCESS: The process "mosquitto.exe" with PID 5344 has been terminated.
Brian Burns
  • 20,575
  • 8
  • 83
  • 77