Class: Testjour::PidFile

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

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ PidFile

Returns a new instance of PidFile.



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

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

Instance Method Details

#removeObject



37
38
39
# File 'lib/testjour/pid_file.rb', line 37

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

#send_signal(signal) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/testjour/pid_file.rb', line 17

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



9
10
11
12
13
14
15
# File 'lib/testjour/pid_file.rb', line 9

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



29
30
31
32
33
34
35
# File 'lib/testjour/pid_file.rb', line 29

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