Class: Testjour::PidFile
- Inherits:
-
Object
- Object
- Testjour::PidFile
- Defined in:
- lib/testjour/pid_file.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path) ⇒ PidFile
constructor
A new instance of PidFile.
- #remove ⇒ Object
- #send_signal(signal) ⇒ Object
- #verify_doesnt_exist ⇒ Object
- #write ⇒ Object
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.(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
#remove ⇒ Object
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_exist ⇒ Object
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 |
#write ⇒ Object
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 |