Class: DanarchyDeploy::Pid

Inherits:
Object
  • Object
show all
Defined in:
lib/danarchy_deploy/pid.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePid

Returns a new instance of Pid.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/danarchy_deploy/pid.rb', line 7

def initialize
  @pidfile = '/var/run/danarchy_deploy.pid'
  @pid = File.exist?(@pidfile) ? File.read(@pidfile).chomp.to_i : nil
  @locked = false

  if @pid
    begin
      Process.getpgid(@pid)
      @locked = true
      @message = "dAnarchy Deploy is already running as PID: #{@pid}"
    rescue Errno::ESRCH => e
      @locked = false
      @message = "dAnarchy Deploy is not currently running."
    end
  end

  if @locked == false
    @pid = Process.pid
    @locked = false
    @message = "dAnarchy Deploy has started as PID: #{@pid}"
    File.write(@pidfile, @pid)
  end
end

Instance Attribute Details

#lockedObject (readonly)

Returns the value of attribute locked.



4
5
6
# File 'lib/danarchy_deploy/pid.rb', line 4

def locked
  @locked
end

#messageObject (readonly)

Returns the value of attribute message.



5
6
7
# File 'lib/danarchy_deploy/pid.rb', line 5

def message
  @message
end

#pidObject (readonly)

Returns the value of attribute pid.



3
4
5
# File 'lib/danarchy_deploy/pid.rb', line 3

def pid
  @pid
end

Instance Method Details

#cleanupObject



31
32
33
34
35
36
# File 'lib/danarchy_deploy/pid.rb', line 31

def cleanup
  File.delete(@pidfile)
  @pid = nil
  @locked = false
  @message = "dAnarchy Deploy has completed. Cleaning up PID"
end