Class: ServiceStatus
- Inherits:
-
Object
- Object
- ServiceStatus
- Defined in:
- lib/runit-man/service_status.rb
Overview
see runit's sv.c source code for details.
Represents service status in daemontools supervise format.
Constant Summary collapse
- STATUS_SIZE =
Size of status data in bytes
20
- S_DOWN =
Service is down.
0
- S_RUN =
Service is running.
1
- S_FINISH =
Service is finishing.
2
Instance Method Summary collapse
-
#down? ⇒ Boolean
Is service down?.
-
#finish? ⇒ Boolean
Is service finishing?.
-
#got_term? ⇒ Boolean
Is service got TERM signal?.
-
#inactive? ⇒ Boolean
Is service inactive?.
-
#initialize(data) ⇒ ServiceStatus
constructor
Initializes service status by binary data.
-
#pid ⇒ Fixnum
Gets service process id.
-
#run? ⇒ Boolean
Is service running?.
-
#started_at ⇒ Time
Gets service start time.
-
#to_s ⇒ String
Gets service status in string format.
-
#uptime ⇒ Float
Gets service uptime in seconds.
-
#want_down? ⇒ Boolean
Is service want down?.
-
#want_up? ⇒ Boolean
Is service want up?.
Constructor Details
#initialize(data) ⇒ ServiceStatus
Initializes service status by binary data.
15 16 17 18 19 20 21 22 23 |
# File 'lib/runit-man/service_status.rb', line 15 def initialize(data) @raw = nil unless data.nil? data_size = data.respond_to?(:bytesize) ? data.bytesize : data.size if data_size == STATUS_SIZE @raw = data.unpack('NNxxxxVxa1CC') end end end |
Instance Method Details
#down? ⇒ Boolean
Is service down?
31 32 33 |
# File 'lib/runit-man/service_status.rb', line 31 def down? status_byte == S_DOWN end |
#finish? ⇒ Boolean
Is service finishing?
41 42 43 |
# File 'lib/runit-man/service_status.rb', line 41 def finish? status_byte == S_FINISH end |
#got_term? ⇒ Boolean
Is service got TERM signal?
75 76 77 |
# File 'lib/runit-man/service_status.rb', line 75 def got_term? pid && @raw[4] != 0 end |
#inactive? ⇒ Boolean
Is service inactive?
26 27 28 |
# File 'lib/runit-man/service_status.rb', line 26 def inactive? @raw.nil? end |
#pid ⇒ Fixnum
Gets service process id.
47 48 49 |
# File 'lib/runit-man/service_status.rb', line 47 def pid @pid ||= down? ? nil : @raw[2] end |
#run? ⇒ Boolean
Is service running?
36 37 38 |
# File 'lib/runit-man/service_status.rb', line 36 def run? status_byte == S_RUN end |
#started_at ⇒ Time
Gets service start time.
53 54 55 56 |
# File 'lib/runit-man/service_status.rb', line 53 def started_at # from TAI to Unix @started_at ||= @raw ? Time.at((@raw[0] << 32) + @raw[1] - 4611686018427387914) : nil end |
#to_s ⇒ String
Gets service status in string format.
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/runit-man/service_status.rb', line 81 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 ⇒ Float
Gets service uptime in seconds.
60 61 62 |
# File 'lib/runit-man/service_status.rb', line 60 def uptime @uptime ||= down? ? nil : Time.now - started_at end |
#want_down? ⇒ Boolean
Is service want down?
70 71 72 |
# File 'lib/runit-man/service_status.rb', line 70 def want_down? pid && @raw[3] == 'd' end |
#want_up? ⇒ Boolean
Is service want up?
65 66 67 |
# File 'lib/runit-man/service_status.rb', line 65 def want_up? @raw && !pid && @raw[3] == 'u' end |