Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Asmodeus
- attr_accessor :pid_file
- def info text
- puts 'Asmodeus: %s' % text
- end
- def pid_check no_check=false
- return unless @pid_file
- unless no_check
- running = Process.getpgid(File.read(@pid_file).to_i) rescue false
- if running
- info 'running, exit'
- exit
- end
- end
- File.write(@pid_file, Process.pid)
- end
- def check
- if block_given? && !yield
- info 'func check failed'
- pid_check true
- else
- pid_check
- end
- true
- end
- end
- #
- test = Asmodeus.new
- test.pid_file = 'looper.pid'
- test.check { true }
- loop do
- puts rand
- sleep 0.5
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement