Class: ServiceStatus
- Inherits:
-
Object
- Object
- ServiceStatus
- Defined in:
- lib/runit-man/service_status.rb
Constant Summary collapse
- STATUS_SIZE =
20
- S_DOWN =
state
0
- S_RUN =
1
- S_FINISH =
2
Instance Method Summary collapse
- #down? ⇒ Boolean
- #finish? ⇒ Boolean
- #got_term? ⇒ Boolean
- #inactive? ⇒ Boolean
-
#initialize(data) ⇒ ServiceStatus
constructor
A new instance of ServiceStatus.
- #pid ⇒ Object
- #run? ⇒ Boolean
- #started_at ⇒ Object
- #to_s ⇒ Object
- #uptime ⇒ Object
- #want_down? ⇒ Boolean
- #want_up? ⇒ Boolean
Constructor Details
#initialize(data) ⇒ ServiceStatus
Returns a new instance of ServiceStatus.
8 9 10 11 12 13 |
# File 'lib/runit-man/service_status.rb', line 8 def initialize(data) # status in daemontools supervise format # look at runit's sv.c for details data = (!data.nil? && data.length == STATUS_SIZE) ? data : nil @raw = data.nil? ? nil : data.unpack('NNxxxxVxa1CC') end |
Instance Method Details
#down? ⇒ Boolean
19 20 21 |
# File 'lib/runit-man/service_status.rb', line 19 def down? status_byte == S_DOWN end |
#finish? ⇒ Boolean
27 28 29 |
# File 'lib/runit-man/service_status.rb', line 27 def finish? status_byte == S_FINISH end |
#got_term? ⇒ Boolean
52 53 54 |
# File 'lib/runit-man/service_status.rb', line 52 def got_term? pid && @raw[4] != 0 end |
#inactive? ⇒ Boolean
15 16 17 |
# File 'lib/runit-man/service_status.rb', line 15 def inactive? @raw.nil? end |
#pid ⇒ Object
31 32 33 |
# File 'lib/runit-man/service_status.rb', line 31 def pid @pid ||= down? ? nil : @raw[2] end |
#run? ⇒ Boolean
23 24 25 |
# File 'lib/runit-man/service_status.rb', line 23 def run? status_byte == S_RUN end |
#started_at ⇒ Object
35 36 37 38 |
# File 'lib/runit-man/service_status.rb', line 35 def started_at # from TAI to Unix @started_at ||= @raw ? Time.at((@raw[0] << 32) + @raw[1] - 4611686018427387914) : nil end |
#to_s ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/runit-man/service_status.rb', line 56 def to_s return 'inactive' if inactive? # try to mimics stat behaviour to minimize readings result = status_string result += ', got TERM' if got_term? result += ', want down' if want_down? result += ', want up' if want_up? result end |
#uptime ⇒ Object
40 41 42 |
# File 'lib/runit-man/service_status.rb', line 40 def uptime @uptime ||= down? ? nil : Time.now - started_at end |
#want_down? ⇒ Boolean
48 49 50 |
# File 'lib/runit-man/service_status.rb', line 48 def want_down? pid && @raw[3] == 'd' end |
#want_up? ⇒ Boolean
44 45 46 |
# File 'lib/runit-man/service_status.rb', line 44 def want_up? @raw && !pid && @raw[3] == 'u' end |