Class: DanarchyDeploy::Pid
- Inherits:
-
Object
- Object
- DanarchyDeploy::Pid
- Defined in:
- lib/danarchy_deploy/pid.rb
Instance Attribute Summary collapse
-
#locked ⇒ Object
readonly
Returns the value of attribute locked.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
- #cleanup ⇒ Object
-
#initialize ⇒ Pid
constructor
A new instance of Pid.
Constructor Details
#initialize ⇒ Pid
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
#locked ⇒ Object (readonly)
Returns the value of attribute locked.
4 5 6 |
# File 'lib/danarchy_deploy/pid.rb', line 4 def locked @locked end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
5 6 7 |
# File 'lib/danarchy_deploy/pid.rb', line 5 def @message end |
#pid ⇒ Object (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
#cleanup ⇒ Object
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 |