Skip to content

Instantly share code, notes, and snippets.

@eric
Created October 22, 2009 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eric/216414 to your computer and use it in GitHub Desktop.
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 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