Created
July 3, 2017 18:06
-
-
Save t27duck/2420569d5be8af7f9845f80deea3e2bc to your computer and use it in GitHub Desktop.
Revisions
-
t27duck created this gist
Jul 3, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ #! /usr/bin/env ruby unicorn_worker_memory_limit = 460_000 loop do begin # unicorn workers # # ps output line format: # 31580 275444 unicorn_rails worker[15] -c /data/github/current/config/unicorn.rb -E production -D # pid ram command lines = `ps -e -www -o pid,rss,command | grep '[u]nicorn_rails worker'`.split("\n") lines.each do |line| parts = line.split(' ') if parts[1].to_i > unicorn_worker_memory_limit # tell the worker to die after it finishes serving its request ::Process.kill('QUIT', parts[0].to_i) end end rescue Object # don't die ever once we've tested this nil end sleep 60 end