Class: Djinn::Base::PidFile

Inherits:
Object
  • Object
show all
Defined in:
lib/djinn/base/pid_file.rb

Overview

pid files are what bind your Djinn to the material plane

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ PidFile

Returns a new instance of PidFile.



8
9
10
# File 'lib/djinn/base/pid_file.rb', line 8

def initialize(file)
  @file = file 
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



6
7
8
# File 'lib/djinn/base/pid_file.rb', line 6

def file
  @file
end

Instance Method Details

#createObject



20
21
22
# File 'lib/djinn/base/pid_file.rb', line 20

def create
  File.open(@file, "w") { |f| f.write($$) }
end

#ensure_emptyObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/djinn/base/pid_file.rb', line 24

def ensure_empty
  _pid = self.pid
  if _pid
    $stdout.puts <<-MSG
It looks like this Djinn is already running, not starting.
Alternatively, you could just have an orphaned pid file,
try running this command to check:

    ps aux | grep #{_pid}
      MSG
    exit 1
  end
end

#pidObject



12
13
14
# File 'lib/djinn/base/pid_file.rb', line 12

def pid
  File.exists?(@file) and IO.read(@file).to_i
end

#removeObject



16
17
18
# File 'lib/djinn/base/pid_file.rb', line 16

def remove
  File.unlink(@file) if pid
end