runit-man 1.8.3 → 1.8.4
Sign up to get free protection for your applications and to get access to all the features.
- data/i18n/en.yml +1 -0
- data/i18n/ru.yml +1 -0
- data/lib/runit-man/service_info.rb +1 -3
- data/lib/runit-man/service_status.rb +78 -52
- metadata +2 -2
data/i18n/en.yml
CHANGED
data/i18n/ru.yml
CHANGED
@@ -36,8 +36,7 @@ class ServiceInfo
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def stat
|
39
|
-
|
40
|
-
r ? r : 'inactive'
|
39
|
+
@status.inactive? ? 'inactive' : @status.to_s
|
41
40
|
end
|
42
41
|
|
43
42
|
def active?
|
@@ -227,7 +226,6 @@ private
|
|
227
226
|
def all_service_names
|
228
227
|
(active_service_names + inactive_service_names)
|
229
228
|
end
|
230
|
-
|
231
229
|
end
|
232
230
|
end
|
233
231
|
|
@@ -1,52 +1,78 @@
|
|
1
|
-
class ServiceStatus
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
1
|
+
class ServiceStatus
|
2
|
+
STATUS_SIZE = 20
|
3
|
+
# state
|
4
|
+
S_DOWN = 0
|
5
|
+
S_RUN = 1
|
6
|
+
S_FINISH = 2
|
7
|
+
|
8
|
+
def initialize(data)
|
9
|
+
# status in daemontools supervise format
|
10
|
+
# look at runit's sv.c for details
|
11
|
+
data = (!data.nil? && data.length == STATUS_SIZE) ? data : nil
|
12
|
+
@raw = data.nil? ? nil : data.unpack('NNxxxxVxa1CC')
|
13
|
+
end
|
14
|
+
|
15
|
+
def inactive?
|
16
|
+
@raw.nil?
|
17
|
+
end
|
18
|
+
|
19
|
+
def down?
|
20
|
+
status_byte == S_DOWN
|
21
|
+
end
|
22
|
+
|
23
|
+
def run?
|
24
|
+
status_byte == S_RUN
|
25
|
+
end
|
26
|
+
|
27
|
+
def finish?
|
28
|
+
status_byte == S_FINISH
|
29
|
+
end
|
30
|
+
|
31
|
+
def pid
|
32
|
+
@pid ||= down? ? nil : @raw[2]
|
33
|
+
end
|
34
|
+
|
35
|
+
def started_at
|
36
|
+
# from TAI to Unix
|
37
|
+
@started_at ||= @raw ? Time.at((@raw[0] << 32) + @raw[1] - 4611686018427387914) : nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def uptime
|
41
|
+
@uptime ||= down? ? nil : Time.now - started_at
|
42
|
+
end
|
43
|
+
|
44
|
+
def want_up?
|
45
|
+
@raw && !pid && @raw[3] == 'u'
|
46
|
+
end
|
47
|
+
|
48
|
+
def want_down?
|
49
|
+
pid && @raw[3] == 'd'
|
50
|
+
end
|
51
|
+
|
52
|
+
def got_term?
|
53
|
+
pid && @raw[4] != 0
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_s
|
57
|
+
# try to mimics stat behaviour to minimize readings
|
58
|
+
result = status_string
|
59
|
+
result += ', got TERM' if got_term?
|
60
|
+
result += ', want down' if want_down?
|
61
|
+
result += ', want up' if want_up?
|
62
|
+
result
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
def status_byte
|
67
|
+
@status_byte ||= @raw ? @raw[5] : 0
|
68
|
+
end
|
69
|
+
|
70
|
+
def status_string
|
71
|
+
case status_byte
|
72
|
+
when S_DOWN then 'down'
|
73
|
+
when S_RUN then 'run'
|
74
|
+
when S_FINISH then 'finish'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|