Class: Testjour::PidFile

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ PidFile

Returns a new instance of PidFile.



9
10
11
# File 'lib/testjour/pid_file.rb', line 9

def initialize(path)
  @path = File.expand_path(path)
end

Class Method Details

.term(path) ⇒ Object



5
6
7
# File 'lib/testjour/pid_file.rb', line 5

def self.term(path)
  new(path).send_signal("TERM")
end

Instance Method Details

#removeObject



41
42
43
# File 'lib/testjour/pid_file.rb', line 41

def remove
  File.unlink(@path) if @path and File.exists?(@path)
end

#send_signal(signal) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/testjour/pid_file.rb', line 21

def send_signal(signal)
  pid = open(@path).read.to_i
  print "Sending #{signal} to Testjour at PID #{pid}..."
  begin
    Process.kill(signal, pid)
  rescue Errno::ESRCH
    puts "Process does not exist.  Not running."
  end

  puts "Done."
end

#verify_doesnt_existObject



13
14
15
16
17
18
19
# File 'lib/testjour/pid_file.rb', line 13

def verify_doesnt_exist
  if File.exist?(@path)
    puts "!!! PID file #{@path} already exists.  testjour could be running already."
    puts "!!! Exiting with error.  You must stop testjour and clear the .pid before I'll attempt a start."
    exit 1
  end
end

#writeObject



33
34
35
36
37
38
39
# File 'lib/testjour/pid_file.rb', line 33

def write
  open(@path, "w") { |f| f.write(Process.pid) }
  open(@path, "w") do |f|
    f.write(Process.pid)
    File.chmod(0644, @path)
  end
end