- 
      
- 
        Save adamcooke/213628 to your computer and use it in GitHub Desktop. 
Revisions
- 
        adamcooke revised this gist Oct 19, 2009 . 1 changed file with 1 addition and 7 deletions.There are no files selected for viewingThis 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 @@ -3,13 +3,7 @@ require 'rubygems' require 'daemons' Daemons.run_proc('PassengerMonitor') do command = 'sudo passenger-memory-stats' memory_limit = 250 
- 
        adamcooke revised this gist Oct 19, 2009 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewingThis 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 @@ -38,8 +38,8 @@ Daemons.run_proc('PassengerMonitor', options) do else puts "Process ##{pid} is not above limit (#{private}MB)" end end sleep 120 end end 
- 
        adamcooke revised this gist Oct 19, 2009 . 1 changed file with 44 additions and 26 deletions.There are no files selected for viewingThis 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 @@ -1,27 +1,45 @@ #!/usr/bin/env ruby require 'rubygems' require 'daemons' options = {} options[:log_output] = true options[:dir] = File.expand_path('../../log/', __FILE__) options[:dir_mode] = :normal Daemons.run_proc('PassengerMonitor', options) do command = 'sudo passenger-memory-stats' memory_limit = 250 def running?(pid) begin return Process.getpgid(pid) != -1 rescue Errno::ESRCH return false end end loop do `#{command}`.each_line do |line| next unless /(\d+)\s+\d+\s+(\d+\.\d+)\s+MB\s+(\d+\.\d+)\s+MB\s+Rails:/.match(line) all, pid, vm_size, private = $~.to_a if private.to_i > memory_limit puts "#{Time.now}: Killing #{pid}, memory usage == #{private}" Process.kill("SIGUSR1", pid.to_i) puts "Finished kill attempt. Sleeping for 20 seconds to give it time to die..." sleep 20 if running?(pid.to_i) puts "Process is still running - die bitch" Process.kill("KILL", pid.to_i) end else puts "Process ##{pid} is not above limit (#{private}MB)" end sleep 120 end end end 
- 
        wmoxam revised this gist Mar 5, 2009 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewingThis 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 @@ -21,7 +21,7 @@ end sleep 20 if running?(pid.to_i) puts "Process is still running, sending term signal" Process.kill("KILL", pid.to_i) end end end 
- 
        wmoxam created this gist Dec 30, 2008 .There are no files selected for viewingThis 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 command = '/opt/ruby-enterprise-1.8.6-20080810/bin/passenger-memory-stats' memory_limit = 200 # megabytes def running?(pid) begin return Process.getpgid(pid) != -1 rescue Errno::ESRCH return false end end `#{command}`.each_line do |line| next unless /(\d+)\s+\d+\s+(\d+\.\d+)\s+MB\s+(\d+\.\d+)\s+MB\s+Rails:/.match(line) all, pid, vm_size, private = $~.to_a if private.to_i > memory_limit puts "#{Time.now}: Killing #{pid}, memory usage == #{private}" Process.kill("SIGUSR1", pid.to_i) puts "Finished kill attempt. Sleeping for 20 seconds..." sleep 20 if running?(pid.to_i) puts "Process is still running, sending term signal" Process.kill("TERM", pid.to_i) end end end 
 adamcooke
              revised
            
            this gist
            
              adamcooke
              revised
            
            this gist  wmoxam
              revised
            
            this gist
            
              wmoxam
              revised
            
            this gist