Module: PassengerMonit::PidfileManager
- Extended by:
- PidfileManager
- Included in:
- PidfileManager
- Defined in:
- lib/passenger_monit/pidfile_manager.rb
Constant Summary collapse
- BASENAME =
'/var/tmp/rack.*.pid'
Instance Method Summary collapse
Instance Method Details
#remove_pid_file ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/passenger_monit/pidfile_manager.rb', line 32 def remove_pid_file pid = Process.pid go_over_pid_files do |file, saved_pid| if pid == saved_pid File.unlink(file) break end end end |
#write_pid_file ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/passenger_monit/pidfile_manager.rb', line 6 def write_pid_file pid = Process.pid count = 1 pidfile = nil go_over_pid_files do |file, saved_pid| file_id = file[/(\d+)/,1].to_i # Increase counter only if we met the same file id count += 1 if file_id == count # We're already there return if saved_pid == pid # Check if the process is alive res = begin Process.kill(0, saved_pid) rescue Errno::ESRCH nil end # It's dead, reuse unless res pidfile = file break end end pidfile ||= BASENAME.sub('*', count.to_s) File.open(pidfile, 'w') {|f| f.write(pid.to_s)} end |