Whenever I shut down my development server (unicorn), the port 8080 does not get released until I close Terminal and reload it from start.
→ unicorn_rails
I, [2012-06-09T09:56:05.919307 #6635] INFO -- : listening on addr=0.0.0.0:8080 fd=3
I, [2012-06-09T09:56:05.919716 #6635] INFO -- : worker=0 spawning...
I, [2012-06-09T09:56:05.921280 #6635] INFO -- : master process ready
I, [2012-06-09T09:56:05.923884 #6636] INFO -- : worker=0 spawned pid=6636
I, [2012-06-09T09:56:05.924617 #6636] INFO -- : Refreshing Gem list
I, [2012-06-09T09:56:35.156762 #6636] INFO -- : worker=0 ready
I, [2012-06-09T10:12:01.217846 #6635] INFO -- : SIGWINCH ignored because we're not daemonized
^Z
[3]+ Stopped unicorn_rails
When I try to restart
→ unicorn_rails
E, [2012-06-09T11:48:24.172525 #9741] ERROR -- : adding listener failed addr=0.0.0.0:8080 (in use)
E, [2012-06-09T11:48:24.172783 #9741] ERROR -- : retrying in 0.5 seconds (4 tries left)
I shut down the server with Control Z
Am I using wrong command?
Yes ctrl-z sends it to a background job. To shut it down, use ctrl-c.
If you have sent it to a background job, you can use fg to return it to the foreground, or look for it's process id, using ps, and then kill it using kill -9 <pid> (where <pid> is the process id found earlier).
Related
I'm trying to use rabbitmq for a django tutorial but when I want to start the server I get this error:
~$ sudo rabbitmq-server
Configuring logger redirection
14:49:57.041 [error]
14:49:57.044 [error] BOOT FAILED
BOOT FAILED
14:49:57.044 [error] ===========
===========
14:49:57.044 [error] ERROR: could not bind to distribution port 25672, it is in use by another node: rabbit#wss
ERROR: could not bind to distribution port 25672, it is in use by another node: rabbit#wss
14:49:57.045 [error]
14:49:58.046 [error] Supervisor rabbit_prelaunch_sup had child prelaunch started with rabbit_prelaunch:run_prelaunch_first_phase() at undefined exit with reason {dist_port_already_used,25672,"rabbit","wss"} in context start_error
14:49:58.046 [error] CRASH REPORT Process <0.153.0> with 0 neighbours exited with reason: {{shutdown,{failed_to_start_child,prelaunch,{dist_port_already_used,25672,"rabbit","wss"}}},{rabbit_prelaunch_app,start,[normal,[]]}} in application_master:init/4 line 138
{"Kernel pid terminated",application_controller,"{application_start_failure,rabbitmq_prelaunch,{{shutdown,{failed_to_start_child,prelaunch,{dist_port_already_used,25672,\"rabbit\",\"wss\"}}},{rabbit_prelaunch_app,start,[normal,[]]}}}"}
Kernel pid terminated (application_controller) ({application_start_failure,rabbitmq_prelaunch,{{shutdown,{failed_to_start_child,prelaunch,{dist_port_already_used,25672,"rabbit","wss"}}},{rabbit_prelau
Crash dump is being written to: erl_crash.dump...done
I've searched for port to see that if it's in use or not and I used lsof -i :25672 and I get nothing.
I don't know too much about these things so if you need anything please tell me.
Try:
sudo lsof -i :25672
sudo kill <PID>
sudo rabbitmq-server
Where <PID> is the process ID that is occupying port 25672
I have encountered this issue. I figured out that this issue is coming because the rabbitmq-server is already running on the machine.
I have used the following command
rabbitmqctl.bat status to know the status of the rabbitmq-server. This helped me to know if the server is up or down.
If it is up, this could the reason you are getting the error that you have specified in your post.
You can issue the following command to make the server down
rabbitmqctl.bat stop
Now you can try starting the rabbitmq-server by issuing the following command
rabbitmq-server start
Note that I am using Windows. And I have executed these commands by pointing the command prompt to C:\Program Files\RabbitMQ\rabbitmq_server-3.8.14\sbin as my rabbitmq installation directory is C:\Program Files\RabbitMQ\rabbitmq_server-3.8.14.
I have encountered this before. Here is what caused it and how I fixed it:
This is one of those commands which requires the magic word sudo (i.e it needs a superuser privilege).
If you forget to add sudo to the command, it begins the process but later fails when it hits a superuser-only roadblock. This leaves you with an incomplete process. Now when you decide to add sudo, it attempts the same process again but finds out that someone without the right privilege has made a mess or is still messing around.
Then the solution will be to cancel out whatever the first command has started and try again.
sudo lsof -i :25672
This list out details about the port 25672
You will see the PID (process ID) e.g 1301
Then stop the process on that port with:
sudo kill <PID>
for example, sudo kill 1301
And make sure you are killing the right process if not you may get into trouble.
Now, retry the command with sudo:
sudo rabbitmq-server
ALSO,
In most cases, this error occurs because without deliberately stopping the rabbitmq-server, it always keeps running even after you restart you system.
another way to stop rabitmq server windows+R then type "services.msc" and then find for RabitMq.slelect and stop from left top corner.
Then re run your rabitmq server.
-Hi guys, I am putting up an answer that can help Googlers to run multiple rabbitmq-server on the same machine. Trying to achieve the latter, I ran into a similar error reported in the first place and solved that by defining:
export RABBITMQ_DIST_PORT=anything_other_than_25672
as stated in the documentation:
https://www.rabbitmq.com/networking.html#epmd-inet-dist-port-range
if you are using windows go to task manager and stop rabbitmq from running...
then reload the rabbitmq-server
For Linux others answered but in Windows you should press Ctrl+Alt+delete and select task management and in that end proccess that depends on erlang.
Note that it requires Administrator previlage.
Now enter this command to start rabbitmq-server:
rabbitmq-server start
Every time you restart your computer you should do these steps.For prevent do them again you should stop rabbitmq service from startup services.
went through same problem in windows, it is already running after installation as a service
so just enable the plugins from the rabbitmq commandline by entering the code as
rabbitmq-plugins enable management_plugin
than go to the localhost:15672 and good to go.
This means that your port 25672 is already in use
try: -
sudo lsof -i :25672
sudo kill <PID>
and now start your rabbitmq server using
sudo rabbitmq-server
I am attempting to dockerize a GUI app and have had some success. If I build the dockerfile into an image and then perform a docker run --name testcontainer testimage it appears that the process begins but the abruptly stops. I then check the container with docker ps to confirm no containers are running. Then I check docker ps -a and can see that it exited with status code exit(0). Then if I run the command docker start testcontainer, it appears to start the ENTRYPOINT command again, but this time it is able to continue and the GUI pops up.
My best guess is that I think that when I run the docker run command, the process begins but might be forked into a background process, causing the container to exit since the foreground process has ended. Although that could be way off because you would think the docker start command would result in the same outcome. I was thinking of trying to force the process to stay in the foreground, but do not know how to do that. Any suggestions?
UPDATE: I editted my Dockerfile to use supervisord to manage the starting of the GUI app. Now my docker run command will start supervisor, which will start my GUI app, and it works. Some things to note about this are that supervisor shows:
INFO spawned: myguiapp with pid 7
INFO success: myguiapp entered RUNNING state
INFO: exited: myguiapp (exit status 0; expected)
Supervisor and the container are still running at this point, which seems to indicate that the main process kicks off a child process. Since supervisor is still running, my container stays up and the GUI app does show up and I can use it. When I close the GUI, supervisor reports:
CRIT reaped unknown pid 93
Supervisor remains running, causing the container NOT to close. So I have to CTRL-C to kill supervisor. I'd rather not use supervisor, but if I need to, I would like for supervisor to close itself gracefully when that child process ends. If I could figure out how to get my container or supervisor to track child processes of the main process, then I think this would be solved.
The first issue is probably because your application requires a tty and you are not allocating a pseudo tty. Try running your container like this:
docker run -t --name testcontainer testimage
When you do a docker start the second time around it somehow allocates the pseudo-tty and the process keeps on running. I tried it myself. I couldn't find this info anywhere in the Docker docs though.
Also, if your UI is interactive you would want:
docker run -t -i --name testcontainer testimage
I'm having a problem monitoring a program using monit.
I'm running this on a raspberry pi, having built monit 5.11 from source; I tried using the version from the repositories, but it was 5.4 and didn't support some of syntax below that I want.
I'm trying to follow the "Q: I have a program that does not create its own pid file. Since monit requires all programs to have a pid file, what do I do?" entry in the FAQ.
Here's my start_sensors.sh script (which just runs my python program, instead of
the java program in the wiki example):
#!/bin/bash
case $1 in
start)
echo $$ > /var/run/start_sensors.pid;
exec 2>&1 /usr/bin/python /home/pi/temperature/post_temps.py 1>/tmp/post_temps.out
;;
stop)
kill `cat /var/run/start_sensors.pid` ;;
*)
echo "usage: start_sensors {start|stop}" ;;
esac
exit 0
Here's my /etc/monit/monitrc entry:
# Run temperature sensor monitor
check process start_sensors.sh with pidfile /var/run/start_sensors.pid
start = "/home/pi/temperature/start_sensors.sh start"
stop = "/home/pi/temperature/start_sensors.sh stop"
The output in the monit log looks like:
[EST Jan 24 14:21:16] info : 'raspberrypi' Monit reloaded
[EST Jan 24 14:21:16] error : 'start_sensors.sh' process is not running
[EST Jan 24 14:21:16] info : 'start_sensors.sh' trying to restart
[EST Jan 24 14:21:16] info : 'start_sensors.sh' start: /home/pi/temperature/start_sensors. sh
[EST Jan 24 14:21:46] error : 'start_sensors.sh' failed to start (exit status -1) -- Program /home/pi/temperature/start_sensors.sh timed out
So as you can see, monit starts up the program, it runs fine, and then monit kills it thirty seconds later due to the "timeout".
My program is running fine, and producing the proper output
that I'm sending to the /tmp/post_temps.out file.
I don't understand why monit is timing the program out... it's supposed to be a long-running process!
I've tried changing the start_sensors.sh script so that it puts the program in the background (and has it write its own /var/run/start_sensors.pid file), but then monit starts a new instance up every thirty seconds or so, not stopping the old ones, and writing over the pid file. It's like it's not even looking at the pid file.
THANKS!
The following works:
#!/bin/bash
case $1 in
start)
/usr/bin/python /home/pi/temperature/post_temps.py 1>/tmp/post_temps.out &
echo $! > /var/run/start_sensors.pid ;
;;
stop)
kill `cat /var/run/start_sensors.pid` ;;
*)
echo "usage: start_sensors {start|stop}" ;;
esac
exit 0
I am deploying Rubyonrails web app with ruby 1.9.2p280, rubyonrails 3.07 with apache passenger and delayed_job as background job.
I would like to monitor my passenger as well as delayed_job background job.
I could not find any step by step guide.
Thanks you very much
Add the following .monitrc files as mention below and run the command monit reload to load the configuration.
/etc/monit/web.monitrc
check process apache with pidfile /var/run/apache2.pid
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
if cpu > 80% for 5 cycles then restart
if totalmem > 300.0 MB for 5 cycles then restart
if children > 250 then alert
if failed port 80 with timeout 10 seconds then restart
if 3 restarts within 5 cycles then timeout
mode manual
group web
/etc/monit/delayed_job.monitrc
check process delayed_job with pidfile /mnt/<project>/tmp/pids/delayed_job.pid
start program = "/usr/bin/delayed_job_start"
stop program = "/usr/bin/delayed_job_stop"
mode manual
group delayed_job
/usr/bin/delayed_job_start
#!/bin/sh
cd /mnt/<project> && RAILS_ENV=production ruby script/delayed_job start
The current section in my supervisord.conf looks like:
[program:rabbitmq]
command=/usr/sbin/rabbitmq-server
When I try to stop the rabbitmq with supervisord ( supervisorctl stop rabbitmq), the rabbitmq processes simply do not shut down. The rabbitmq documentation also mentions to never use kill but rather use rabbitmqctl stop . I'm guessing supervisord simply kills the processes - hence the poor results with rabbitmq. I couldn't find any options in supervisord to specify a custom stop command.
Do you have any recommendations?
My solution is to write a wrapper script named rabbitmq.sh as follows:
# call "rabbitmqctl stop" when exiting
trap "{ echo Stopping rabbitmq; rabbitmqctl stop; exit 0; }" EXIT
echo Starting rabbitmq
rabbitmq-server
After that, modify supervisord.conf:
[program:rabbitmq]
command=path/to/rabbitmq.sh
You have answered your own question. In normal operation, never use kill on any process unless that is the documented normal way of managing it. In the case of RabbitMQ, the documented process is to use rabbitmqctl stop or to use rabbitmqserver stop.
There is no good reason to manage RabbitMQ with anything more sophisticated than a shell script that makes one attempt to restart via rabbitmqserver start. If that doesn't work right away, then RabbitMQ is down hard due to something like, lack of RAM, ran out of disk space, or a rogue system management tool deleted some of the rabbitmq binary components.
In normal operation RabbitMQ has an internal supervisor that will attempt to shutdown and restart RabbitMQ, so if you delete binaries, it will fail to restart. When using tools like chef, puppet, cfengine, don't repeatedly push out binary package files. Just check that everything is there as it should be.
This script starts RabbitMQ as a background process (using '&') which causes a pid file to be updated/created (see 'wait' under http://www.rabbitmq.com/man/rabbitmqctl.1.man.html).
After rabbit has been started, a loop is used to verify that the pid is still running. If rabbit crashes or is manually shut down (outside of supervisord) then the script will exit with 1 and supervisord takes over.
The echo >> ./rmq.txt file is there for debugging purposes and can be commented out in production (I used this to monitor the startup/shutdown/died status).
supervisord is happy because it can see a running process and an EXIT will trigger the stop_rmq function which calls 'rabbitmqctl stop' for a clean shutdown.
#!/bin/bash
# Script to manage RMQ with supervisord
# Shut down rmq
function stop_rmq {
echo "Stopping RabbitMQ..."
echo "Stopping RabbitMQ..." >> ./rmq.txt
rabbitmqctl stop
echo "RabbitMQ stopped"
echo "RabbitMQ stopped" >> ./rmq.txt
#exit 0
}
# Set up the trap
#trap stop_rabbit TERM KILL HUP INT SIGTERM SIGKILL SIGHUP SIGINT
trap stop_rmq exit
# Start rmq
echo "Starting RabbitMQ..."
echo "Starting RabbitMQ..." >> ./rmq.txt
# Start Rabbitmq in the background (causes the pid file to be updated)
# Note that the pid file location can be overridden with the rmq 'RABBITMQ_PID_FILE' variable
/usr/sbin/rabbitmq-server &
rabbitmqctl wait /var/lib/rabbitmq/mnesia/rabbit#$HOSTNAME.pid
echo "RabbitMQ Started"
echo "RabbitMQ Started" >> ./rmq.txt
while true; do
#ps $(cat /var/lib/rabbitmq/mnesia/rabbit#$HOSTNAME.pid)
ps -o pid,cmd,etime $(cat /var/lib/rabbitmq/mnesia/rabbit#$HOSTNAME.pid)
if (($? > 0)); then
echo "RabbitMQ Died"
echo "RabbitMQ Died" >> ./rmq.txt
exit 1
fi
#echo "Sleeping..."
sleep 10
done
Here's the output generated by the script to supervisord:
foo#bar:/# supervisorctl tail rmq
Starting RabbitMQ...
Waiting for rabbit#a2d2c8f9cad2 ...
pid is 45220 ...
RabbitMQ 3.3.5. Copyright (C) 2007-2014 GoPivotal, Inc.
## ## Licensed under the MPL. See http://www.rabbitmq.com/
## ##
########## Logs: /var/log/rabbitmq/rabbit#a2d2c8f9cad2.log
###### ## /var/log/rabbitmq/rabbit#a2d2c8f9cad2-sasl.log
##########
Starting broker... completed with 0 plugins.
...done.
RabbitMQ Started
PID CMD ELAPSED
45220 /usr/lib/erlang/erts-6.1/bi 00:05
PID CMD ELAPSED
45220 /usr/lib/erlang/erts-6.1/bi 00:15
PID CMD ELAPSED
45220 /usr/lib/erlang/erts-6.1/bi 00:25
PID CMD ELAPSED
45220 /usr/lib/erlang/erts-6.1/bi 00:35
PID CMD ELAPSED
45220 /usr/lib/erlang/erts-6.1/bi 00:45
PID CMD ELAPSED
45220 /usr/lib/erlang/erts-6.1/bi 00:55
PID CMD ELAPSED
45220 /usr/lib/erlang/erts-6.1/bi 01:05
PID CMD ELAPSED
45220 /usr/lib/erlang/erts-6.1/bi 01:15
PID CMD ELAPSED
45220 /usr/lib/erlang/erts-6.1/bi 01:25
I would advise you to use Monit (http://mmonit.com/), it is better suited for daemons such as RabbitMQ and it is also feature rich.
First of all, you must install the Monit package. If you are under Ubuntu/Debian:
sudo apt-get update
sudo apt-get install monit
Afterwards, you must create a configuration script.
Here is a sample script to get you running (place it on /etc/monit/conf.d/):
set daemon 1800
set logfile /var/log/monit.log
check process rabbit with pidfile /var/run/rabbitmq/pid
start program = "/etc/init.d/rabbitmq-server start"
stop program = "/etc/init.d/rabbitmq-server stop"
noalert foo#bar
Then, just restarts monit and you are finished:
sudo /etc/init.d/monit restart