Killing Processes Spawned by Foreman
Asked Answered
W

3

14

I have the following Procfile:

web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
redis: bundle exec redis-server /usr/local/etc/redis.conf
worker: bundle exec sidekiq

Running $ foreman start starts up Unicorn, Redis and Sidekiq, but how should i stop them again?

Killing Foreman leaves all three up. I can see this using ps:

$ ps aux | grep redis | grep -v grep
    me           61560   0.0  0.0  2506784   1740 s000  S+    9:36am   0:01.28 redis-server /usr/local/etc/redis.conf
$ ps aux | grep sidekiq  | grep -v grep
    me           61561   0.0  1.0  2683796 173284 s000  S+    9:36am   0:14.18 sidekiq 2.17.0 pathways [0 of 25 busy]
$ ps aux | grep unicorn | grep -v grep
    me           61616   0.0  0.2  2615284  28312 s000  S+    9:37am   0:00.06 unicorn worker[2] -p 5000 -c ./config/unicorn.rb
    me           61615   0.0  0.2  2615284  27920 s000  S+    9:37am   0:00.06 unicorn worker[1] -p 5000 -c ./config/unicorn.rb
    me           61614   0.0  0.2  2615284  27772 s000  S+    9:37am   0:00.06 unicorn worker[0] -p 5000 -c ./config/unicorn.rb
    me           61559   0.0  1.0  2615284 160988 s000  S+    9:36am   0:09.87 unicorn master -p 5000 -c ./config/unicorn.rb

So obviously I can manually kill each process, but how can I kill all at once? It doesn't seem like Foreman supports this.

Wernick answered 25/11, 2013 at 10:44 Comment(0)
W
12

To kill them all with a one-liner:

$ kill $(ps aux | grep -E 'redis|sidekiq|unicorn' | grep -v grep | awk '{print $2}')
Wernick answered 25/11, 2013 at 11:14 Comment(1)
Thank you! This helped me realize the rails port wasn't the only one I need to kill!Baelbeer
N
4

Or you can do this

$ killall "foreman: master"
Neuberger answered 3/6, 2015 at 8:38 Comment(0)
L
1

I'm not sure that Foreman supports this. I use subcontractor and use it like so:

web: subcontract --rbenv '1.9.3-p362' --chdir ../website --signal INT -- bundle exec thin start -p 3000

Log answered 25/11, 2013 at 11:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.