Class: FakeSQS::Daemonize
- Inherits:
-
Object
- Object
- FakeSQS::Daemonize
- Defined in:
- lib/fake_sqs/daemonize.rb
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(options) ⇒ Daemonize
constructor
A new instance of Daemonize.
Constructor Details
#initialize(options) ⇒ Daemonize
Returns a new instance of Daemonize.
6 7 8 9 10 11 |
# File 'lib/fake_sqs/daemonize.rb', line 6 def initialize() @pid = .fetch(:pid) { warn "No PID file specified while daemonizing!" exit 1 } end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
4 5 6 |
# File 'lib/fake_sqs/daemonize.rb', line 4 def pid @pid end |
Instance Method Details
#call ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fake_sqs/daemonize.rb', line 13 def call Process.daemon(true, true) if File.exist?(pid) existing_pid = File.open(pid, 'r').read.chomp.to_i running = Process.getpgid(existing_pid) rescue false if running warn "Error, Process #{existing_pid} already running" exit 1 else warn "Cleaning up stale pid at #{pid}" end end File.open(pid, 'w') { |f| f.write(Process.pid) } end |