Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. class Asmodeus
  2. attr_accessor :pid_file
  3.  
  4. def info text
  5. puts 'Asmodeus: %s' % text
  6. end
  7.  
  8. def pid_check no_check=false
  9. return unless @pid_file
  10.  
  11. unless no_check
  12. running = Process.getpgid(File.read(@pid_file).to_i) rescue false
  13.  
  14. if running
  15. info 'running, exit'
  16. exit
  17. end
  18. end
  19.  
  20. File.write(@pid_file, Process.pid)
  21. end
  22.  
  23. def check
  24. if block_given? && !yield
  25. info 'func check failed'
  26. pid_check true
  27. else
  28. pid_check
  29. end
  30.  
  31. true
  32. end
  33. end
  34.  
  35. #
  36.  
  37. test = Asmodeus.new
  38. test.pid_file = 'looper.pid'
  39. test.check { true }
  40.  
  41. loop do
  42. puts rand
  43. sleep 0.5
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement