Sha256: 530ee2d00f73095aace9d414eaab66efe5ec1d6aace979a9c481320c77259055

Contents?: true

Size: 913 Bytes

Versions: 6

Compression:

Stored size: 913 Bytes

Contents

class ServiceStatus
  def initialize(data)
    # status in daemontools supervise format
    # look at runit's sv.c for details
    data = !data.nil? && data.length == 20 ? data : nil
    @raw = data.nil? ? nil : data.unpack('NNxxxxVxa1CC')
  end

  def down?
    status_byte == 0
  end

  def run?
    status_byte == 1
  end

  def finish?
    status_byte == 2
  end

  def pid
    @pid ||= down? ? nil : @raw[2]
  end

  def started_at
    # from TAI to Unix
    @started_at ||= @raw ? Time.at((@raw[0] << 32) + @raw[1] - 4611686018427387914) : nil
  end

  def uptime
    @uptime ||= down? ? nil : Time.now - started_at
  end

  def want_up?
    @raw && !pid && @raw[3] == 'u'
  end

  def want_down?
    pid && @raw[3] == 'd'
  end

  def got_term?
    pid && @raw[4] != 0
  end

private
  def status_byte
    @status_byte ||= @raw ? @raw[5] : 0
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
runit-man-1.8.3 lib/runit-man/service_status.rb
runit-man-1.8.2 lib/runit-man/service_status.rb
runit-man-1.8.1 lib/runit-man/service_status.rb
runit-man-1.8.0 lib/runit-man/service_status.rb
runit-man-1.7.4 lib/runit-man/service_status.rb
runit-man-1.7.3 lib/runit-man/service_status.rb