]> git.openstreetmap.org Git - rails.git/blobdiff - public/dispatch.fcgi
Update Potlatch 2 to 2.2-41-gec89ae9 build
[rails.git] / public / dispatch.fcgi
index cd76b6113a89ec3192f5543cdd5e9fed61189f70..3a13f230c24c709bc51a7f8fbf0dbaa9a4a5fcf8 100755 (executable)
 require File.dirname(__FILE__) + "/../config/environment"
 require 'fcgi_handler'
 
-RailsFCGIHandler.process! nil, 10
+class OpenStreetMapFCGIHandler < RailsFCGIHandler
+protected
+  def process_request(cgi)
+    # Call superclass to process the request
+    super
+
+    # Restart if we've hit our memory limit
+    if resident_size > 512
+      dispatcher_log :info, "restarting due to memory limit"
+      restart!
+    end
+  end
+
+  def resident_size
+    # Read statm to get process sizes. Format is
+    #   Size RSS Shared Text Lib Data
+    fields = File.open("/proc/self/statm") do |file|
+      fields = file.gets.split(" ")
+    end
+
+    # Return resident size in megabytes
+    return fields[1].to_i / 256
+  end
+end
+
+OpenStreetMapFCGIHandler.process!