Stop the mosquitto (MQTT) broker from listening to a port using the command line - sockets

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.

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

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

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.

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}')

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

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.

Related

docker CMD run supervisord in background

is there any way to run supervisord in the background. means start the process and get out of shell.
I have a docker file where i try to run a script that suppose to start the postgresql and then get out. so I have a process running and i can create users.
Docker command
CMD ["/runprocess.sh"]
script runproccess.sh
#!/bin/bash
supervisord -c "/etc/supervisord.conf"
I have also tried to run it in background, but no luck
#!/bin/bash
supervisord -c "/etc/supervisord.conf" &
supervisord starts the process and just stays on screen for ever.
i want it to run the process and get out. so I can run other part of my script.
you can remove setting nodaemon or set it to false in supervisord.conf
[supervisord]
nodaemon=false ; Docker利用ではtrueにする必要あり
this will make supervisor start in background.

redhat linux upstart (initctl) issue on reboot

Morning,
I have monit I am testing on redhat 6.4 system. I setup a /etc/init/monit.conf:
description "Monit service manager"
limit core unlimited unlimited
start on runlevel [2345]
stop on runlevel [!2345]
expect daemon
respawn
exec /local/mis/monit/bin/monit -c /local/mis/monit/etc/monitrc
pre-stop exec /local/mis/monit/bin/monit -c /local/mis/monit/etc/monitrc quit
At the command line as root I can run stop monit and start monit just fine and it shows pid number. However, during reboot, it does not start. It shows start/running with no pid if I run initctl list, but if you check with ps -ef monit is not running. I can run stop monit and then run start monit just fine after a reboot. I am at a lose with how to troubleshoot. My system has /var/log/messages, but no /var/log/syslog. I see options to use log-priority info, but I am not sure how to set that as the level for logging during the reboot. The /var/log/message does not mention monit and /var/log/boot.log does not either. dmesg shows nothing.
this sounds like the same problem we just fixed.
We run monit as user "monit". upstart was trying to start it as root and the monit files where owned my user "monit". And we were getting identical symptoms you were getting.
To fix it i altered /etc/init/monit to
exec su -c "/web/bin/monit -c /web/etc/monitrc" monit
now when i start monitI see::
# start monit
monit start/running, process 3421
The final solution I ended up using: description "Monit service manager"
start on (net-device-up IFACE=eth0 and started networking and runlevel [2345])
stop on runlevel [!2345]
limit core unlimited unlimited
expect daemon
respawn
Had to do a pre-start script to loop until successful with nslookup of mail server listed in the monitrc file.
pre-start script
while [ 0 ]; do
i=/usr/bin/nslookup outlookwebapp.na.sas.com | grep Name
if [ ! -z "$i" ]; then
break
fi
sleep 4
done
end script
exec /local/mis/monit/bin/monit -c /local/mis/monit/etc/monitrc
pre-stop exec /local/mis/monit/bin/monit -c /local/mis/monit/etc/monitrc quit

How do you stop a perl Dancer/Starman/Plack server?

I started a Dancer/Starman server using:
sudo plackup -s Starman -p 5001 -E deployment --workers=10 -a mywebapp/bin/app.pl
but I'm unsure how I can stop the server. Can someone provide me with a quick way of stopping it and all the workers it has spawned?
Use the
--pid /path/to/the/pid.file
and you can kill the process based on his PID
So, using the above options, you can use
kill $(cat /path/to/the/pid.file)
the pid.file simply stores the master's PID - don't need analyze the ps output...
pkill -f starman
Kill processes based on name.
On Windows you can do "CTRL + C" like making a copy but Cancel in this case. Tested working.

Why is sleep needed after fabric call to pg_ctl restart

I'm using Fabric to initialize a postgres server. I have to add a "sleep 1" at the end of the command or the postgres server processes die without explanation or an entry in the log:
sudo('%(pgbin)s/pg_ctl -D %(pgdata)s -l /tmp/pg.log restart && sleep 1' % env, user='postgres')
That is, I see this output on the terminal:
[dbserv] Executing task 'setup_postgres'
[dbserv] run: /bin/bash -l -c "sudo -u postgres /usr/lib/postgresql/9.1/bin/pg_ctl -D /data/pg -l /tmp/pg.log restart && sleep 1"
[dbserv] out: waiting for server to shut down.... done
[dbserv] out: server stopped
[dbserv] out: server starting
Without the && sleep 1, there's nothing in /tmp/pg.log (though the file is created), and no postgres processes are running. With the sleep, everything works fine.
(And if I execute the same command directly on target machine's command line, it works fine without the sleep.)
Since it's working, it doesn't really matter, but I'm asking anyway: Does someone know what the sleep is allowing to happen and why?
You might try also using the pty option set it to false and see if it's related to how fabric handles pseudo-ttys.

start mongodb and return to terminal

I can start mongodb on terminal via command
./mongod
It starts the mongodb server and then display me information that server is running on this port. but It does not give my terminal back. How can I start mongodb and can get terminal back so mongodb is running the background.
Also how to shutdown if its running in background
Use
./mongod --fork
or
./mongod &
To shutdown you have to send it a TERM signal.
ps aux | grep mongod - to find a PID
kill -TERM PID - send it a TERM signal, and using the first example we can use the PID file:
kill -TERM $(cat /var/run/mongodb/mongod.pid)
Also you can shut it down from the shell.
$ ./mongo
> use admin
> db.shutdownServer()
--
And another method:
./mongod --fork --pidfilepath /var/run/mongodb/mongod.pid
then (please notice the ticks around the cat)
kill -9 `cat /var/run/mongodb/mongod.pid`
./mongod &
You will see a number in the output, something similar to
[1]+ ./mongod &
To kill the process execute a kill %1 where 1 is the number between the angular brackets.