Skip to content

Instantly share code, notes, and snippets.

@nathanhumbert
Created September 8, 2010 23:59
Show Gist options
  • Save nathanhumbert/571095 to your computer and use it in GitHub Desktop.
Save nathanhumbert/571095 to your computer and use it in GitHub Desktop.
module God
module Conditions
class RestartFileTouched < PollCondition
attr_accessor :restart_file
def initialize
super
end
def process_start_time
Time.parse(`ps -o lstart -p #{self.watch.pid} --no-heading`)
end
def restart_file_modification_time
File.mtime(self.restart_file)
end
def valid?
valid = true
valid &= complain("Attribute 'restart_file' must be specified", self) if self.restart_file.nil?
valid
end
def test
if process_start_time < restart_file_modification_time
return true
else
return false
end
end
end
end
end
@zenlor
Copy link

zenlor commented Jan 14, 2011

there is a small unhandled exception in case the restart file doesn't exists, here's what I did:

  def file_modification_time
    (File.exists?(self.file))? File.mtime(self.file) : Time.at(0)
  end

@damienbrz
Copy link

Where do you put the RestartFIleTouched.rb and where do you load it ?

@zenlor
Copy link

zenlor commented Jul 1, 2011

you can put it in your lib path, or where you whant just load it with a simple require '/my_path_to/RestartFileTouched'

@pmahoney
Copy link

The '--no-heading' option doesn't work on Mac OS X.

I had success with "ps -o lstart= -p #{pid}". Note the trailing equals sign (=). This sets a custom header to blank, which causes both Linux and Mac OS X ps to omit the header line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment