Sha256: b674cb001c5d4d02da074892b551c2615876ffb5f5b627fce2c71e48b7b6d3ad
Contents?: true
Size: 1.73 KB
Versions: 1
Compression:
Stored size: 1.73 KB
Contents
# frozen_string_literal: true module God module Conditions # Trigger when a process is running or not running depending on attributes. # # Examples # # # Trigger if process IS NOT running. # on.condition(:process_running) do |c| # c.running = false # end # # # Trigger if process IS running. # on.condition(:process_running) do |c| # c.running = true # end # # # Non-Watch Tasks must specify a PID file. # on.condition(:process_running) do |c| # c.running = false # c.pid_file = "/var/run/mongrel.3000.pid" # end class ProcessRunning < PollCondition # Public: The Boolean specifying whether you want to trigger if the # process is running (true) or if it is not running (false). attr_accessor :running # Public: The String PID file location of the process in question. # Automatically populated for Watches. attr_accessor :pid_file def pid pid_file ? File.read(pid_file).strip.to_i : watch.pid end def valid? valid = true valid &= complain("Attribute 'pid_file' must be specified", self) if pid_file.nil? && watch.pid_file.nil? valid &= complain("Attribute 'running' must be specified", self) if running.nil? valid end def test self.info = [] pid = self.pid active = pid && System::Process.new(pid).exists? if running && active info.push('process is running') true elsif !running && !active info.push('process is not running') true else info.push('process is not running') if running false end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
resurrected_god-1.1.1 | lib/god/conditions/process_running.rb |