Class: Tagrity::PidFile
- Inherits:
-
Object
- Object
- Tagrity::PidFile
- Defined in:
- lib/tagrity/pid_file.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Class Method Summary collapse
- .alive_pid_files(dir: nil) ⇒ Object
- .delete(dir) ⇒ Object
- .revive_dead_pids ⇒ Object
- .write(pid_file) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #delete ⇒ Object
-
#initialize(dir, pid) ⇒ PidFile
constructor
A new instance of PidFile.
- #name ⇒ Object
Constructor Details
#initialize(dir, pid) ⇒ PidFile
Returns a new instance of PidFile.
66 67 68 69 |
# File 'lib/tagrity/pid_file.rb', line 66 def initialize(dir, pid) @dir = dir @pid = pid end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
64 65 66 |
# File 'lib/tagrity/pid_file.rb', line 64 def dir @dir end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
64 65 66 |
# File 'lib/tagrity/pid_file.rb', line 64 def pid @pid end |
Class Method Details
.alive_pid_files(dir: nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tagrity/pid_file.rb', line 22 def alive_pid_files(dir: nil) Dir.glob("#{Helper.run_dir}/*").reduce([]) do |pid_files, path| pid = pid_from_path(path) pid_file_dir = File.read(path) if dir.nil? || same_dirs?(pid_file_dir, dir) if Helper.alive?(pid) pid_files << PidFile.new(pid_file_dir, pid) else File.delete(path) end end pid_files end end |
.delete(dir) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/tagrity/pid_file.rb', line 10 def delete(dir) pid_file_paths = Dir.glob("#{Helper.run_dir}/#{dir.split('/').last}.*.pid").select do |path| full_dir = File.read(path) File.realdirpath(full_dir) == File.realdirpath(dir) end pid_file_paths.each do |path| File.delete(path) Helper.kill(pid_from_path(path)) end end |
.revive_dead_pids ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tagrity/pid_file.rb', line 39 def revive_dead_pids Dir.glob("#{Helper.run_dir}/*").reduce([]) do |pid_files, path| pid = pid_from_path(path) dir = File.read(path) if not Helper.alive?(pid) File.delete(path) Dir.chdir(File.realdirpath(dir)) do Process.spawn('tagrity start') end end end end |
.write(pid_file) ⇒ Object
6 7 8 |
# File 'lib/tagrity/pid_file.rb', line 6 def write(pid_file) File.write("#{Helper.run_dir}/#{pid_file.name}", pid_file.dir) end |
Instance Method Details
#==(other) ⇒ Object
71 72 73 74 |
# File 'lib/tagrity/pid_file.rb', line 71 def ==(other) @dir == other.dir @pid == other.pid end |
#delete ⇒ Object
80 81 82 83 |
# File 'lib/tagrity/pid_file.rb', line 80 def delete File.delete(pid_file_path) Helper.kill(pid.to_i) end |
#name ⇒ Object
76 77 78 |
# File 'lib/tagrity/pid_file.rb', line 76 def name "#{@dir.split('/').last}.#{@pid}.pid" end |