Class: Sensu::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/sensu/process.rb

Instance Method Summary collapse

Constructor Details

#initializeProcess

Returns a new instance of Process.



3
4
5
# File 'lib/sensu/process.rb', line 3

def initialize
  @logger = Logger.get
end

Instance Method Details

#daemonizeObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sensu/process.rb', line 21

def daemonize
  srand
  if fork
    exit
  end
  unless ::Process.setsid
    @logger.fatal('cannot detach from controlling terminal')
    @logger.fatal('SENSU NOT RUNNING!')
    exit 2
  end
  Signal.trap('SIGHUP', 'IGNORE')
  if fork
    exit
  end
  Dir.chdir('/')
  ObjectSpace.each_object(IO) do |io|
    unless [STDIN, STDOUT, STDERR].include?(io)
      begin
        unless io.closed?
          io.close
        end
      rescue
      end
    end
  end
end

#write_pid(file) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/sensu/process.rb', line 7

def write_pid(file)
  begin
    File.open(file, 'w') do |pid_file|
      pid_file.puts(::Process.pid)
    end
  rescue
    @logger.fatal('could not write to pid file', {
      :pid_file => file
    })
    @logger.fatal('SENSU NOT RUNNING!')
    exit 2
  end
end