What is the best way to stop a Unicorn Server process from running? Whenever I try to stop it using kill -p 902开发者_如何学C34
it does not work. It is most likely something I am doing wrong.
Thanks.
Have a look at the Unicorn SIGNALS page. If the master is behaving correctly and you just want to turn it off, you should send a QUIT signal:
kill -QUIT 1234 # where 1234 is the real process id, of course
That gracefully stops all the workers, letting them finish any requests that they're in the middle of serving.
I use this:
ps aux | grep 'unicorn' | awk '{print $2}' | xargs sudo kill -9
I just looked back at this two months later. This is craziness, and don't use this if you have more than one Unicorn master and you only want to kill one of them.
Interesting that no-one considered the pid file that unicorn creates? My usual config puts it in ./tmp/unicorn.pid, so perhaps the safest way is
kill -QUIT `cat tmp/unicorn.pid`
and the pid file is then properly deleted by the departing process. I always put the pid file in the same relative place so I guess I could alias that for convenience, although when I am developing I don't usually daemonize unicorn.
I would probably go with:
sudo pkill unicorn_rails
ps aux | grep unicorn
#=> root 4393 2.0 0.9 65448 20764 ? S 20:06 0:35 unicorn_rails m
kill 4393
Ultimately, the key is the following line which targets the master unicorn process and kills it
kill $(ps aux | grep '[u]nicorn_rails master' | awk '{print $2}')
Usually I'm lazy and I just kill by name:
$ killall processname
Simple Things There - In Terminal type "ps" and have a look for the Master Unicorn Process. Copy the PID of it and then type "kill −9 90234" (where 90234 is PID of master unicorn process). After that worker process should disappear itself.
for those using chef and seeing that none of the above works (because the processes are respawned as soon as you kill them):
sudo sv stop APP_NAME
sv
is the control for runit
.
To quit a specific Unicorn server you can use something like the following:
pkill -QUIT --pidfile /path/to/app/shared/tmp/pids/unicorn.pid
This way you can selectively kill any process and you don't have to use shell evaluation/expansion which may not be available.
精彩评论