Sha256: e8ca00b1b6f91238868a59c634edc183e5a57b3d8c70841435d0baf6135323f2

Contents?: true

Size: 658 Bytes

Versions: 10

Compression:

Stored size: 658 Bytes

Contents

module FakeSQS
  class Daemonize

    attr_reader :pid

    def initialize(options)
      @pid = options.fetch(:pid) {
        warn "No PID file specified while daemonizing!"
        exit 1
      }
    end

    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

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
fake_sqs-0.4.3 lib/fake_sqs/daemonize.rb
fake_sqs-0.4.2 lib/fake_sqs/daemonize.rb
fake_sqs-0.4.1 lib/fake_sqs/daemonize.rb
fake_sqs-0.4.0 lib/fake_sqs/daemonize.rb
fake_sqs-0.3.1 lib/fake_sqs/daemonize.rb
fake_sqs-0.3.0 lib/fake_sqs/daemonize.rb
fake_sqs-0.2.0 lib/fake_sqs/daemonize.rb
fake_sqs-0.1.0 lib/fake_sqs/daemonize.rb
fake_sqs-0.0.11 lib/fake_sqs/daemonize.rb
fake_sqs-0.0.10 lib/fake_sqs/daemonize.rb