Class: Djinn::Base::PidFile
- Inherits:
-
Object
- Object
- Djinn::Base::PidFile
- Defined in:
- lib/djinn/base/pid_file.rb
Overview
pid files are what bind your Djinn to the material plane
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
- #create ⇒ Object
- #ensure_empty ⇒ Object
-
#initialize(file) ⇒ PidFile
constructor
A new instance of PidFile.
- #pid ⇒ Object
- #remove ⇒ Object
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
#file ⇒ Object (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
#create ⇒ Object
20 21 22 |
# File 'lib/djinn/base/pid_file.rb', line 20 def create File.open(@file, "w") { |f| f.write($$) } end |
#ensure_empty ⇒ Object
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 |
#pid ⇒ Object
12 13 14 |
# File 'lib/djinn/base/pid_file.rb', line 12 def pid File.exists?(@file) and IO.read(@file).to_i end |
#remove ⇒ Object
16 17 18 |
# File 'lib/djinn/base/pid_file.rb', line 16 def remove File.unlink(@file) if pid end |