Created
October 22, 2009 22:44
-
-
Save eric/216414 to your computer and use it in GitHub Desktop.
Simple mechanism to make sure god doesn't use more than 40mb
This file contains 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 characters
# This relies on god 0.7.22 or later. | |
# | |
# Restart god when it reaches 40MB | |
if defined?(ORIGINAL_ARGV) | |
Thread.new do | |
loop do | |
memory_usage = God::System::Process.new(Process.pid).memory # in kilobytes | |
if memory_usage > 40.megabytes | |
applog(nil, :info, "Stopping god server. Memory usage limit reached: #{memory_usage}kb") | |
puts "Stopping god server. Memory usage limit reached: #{memory_usage}kb" | |
God.server.stop | |
applog(nil, :info, "Restarting #{$0} #{ORIGINAL_ARGV * ' '}") | |
puts "Restarting #{$0} #{ORIGINAL_ARGV * ' '}" | |
exec $0, *ORIGINAL_ARGV | |
end | |
sleep 60 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment