runit-man 1.6.4 → 1.7.0
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/log_location_cache.rb +1 -1
- data/lib/runit-man/service_info.rb +53 -8
- data/views/_service_info.erb +1 -0
- data/views/_services.erb +1 -0
- metadata +4 -4
data/i18n/en.yml
CHANGED
data/i18n/ru.yml
CHANGED
@@ -4,12 +4,14 @@ class ServiceInfo
|
|
4
4
|
attr_reader :name
|
5
5
|
|
6
6
|
def initialize(a_name)
|
7
|
-
@name
|
7
|
+
@name = a_name
|
8
|
+
@data = ''
|
9
|
+
@files = {}
|
8
10
|
end
|
9
11
|
|
10
12
|
def to_json(*a)
|
11
13
|
data = {}
|
12
|
-
[ :name, :stat, :active?, :logged?, :switchable?, :run?, :pid, :log_pid, :log_file_location ].each do |sym|
|
14
|
+
[ :name, :stat, :active?, :logged?, :switchable?, :run?, :pid, :log_pid, :log_file_location, :finish?, :down?, :started_at, :uptime ].each do |sym|
|
13
15
|
data[sym] = send(sym)
|
14
16
|
end
|
15
17
|
data.to_json(*a)
|
@@ -20,7 +22,7 @@ class ServiceInfo
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def stat
|
23
|
-
r =
|
25
|
+
r = data_from_file(File.join(supervise_folder, 'stat'))
|
24
26
|
r ? r : 'inactive'
|
25
27
|
end
|
26
28
|
|
@@ -32,8 +34,16 @@ class ServiceInfo
|
|
32
34
|
File.symlink?(active_service_folder) || File.directory?(inactive_service_folder)
|
33
35
|
end
|
34
36
|
|
37
|
+
def down?
|
38
|
+
status_byte == 0
|
39
|
+
end
|
40
|
+
|
35
41
|
def run?
|
36
|
-
|
42
|
+
status_byte == 1
|
43
|
+
end
|
44
|
+
|
45
|
+
def finish?
|
46
|
+
status_byte == 2
|
37
47
|
end
|
38
48
|
|
39
49
|
def up!
|
@@ -59,11 +69,25 @@ class ServiceInfo
|
|
59
69
|
end
|
60
70
|
|
61
71
|
def pid
|
62
|
-
|
72
|
+
return nil if down?
|
73
|
+
st = raw_status
|
74
|
+
st.unpack('xxxxxxxxxxxxV').first
|
75
|
+
end
|
76
|
+
|
77
|
+
def started_at
|
78
|
+
st = raw_status
|
79
|
+
return nil unless st
|
80
|
+
vals = st.unpack('NN')
|
81
|
+
Time.at((vals[0] << 32) + vals[1] - 4611686018427387914)
|
82
|
+
end
|
83
|
+
|
84
|
+
def uptime
|
85
|
+
return nil if down?
|
86
|
+
Time.now - started_at
|
63
87
|
end
|
64
88
|
|
65
89
|
def log_pid
|
66
|
-
|
90
|
+
data_from_file(File.join(log_supervise_folder, 'pid'))
|
67
91
|
end
|
68
92
|
|
69
93
|
def log_file_location
|
@@ -96,7 +120,7 @@ class ServiceInfo
|
|
96
120
|
Dir.entries(urls_to_view_folder).select do |name|
|
97
121
|
name =~ /\.url$/ && File.file?(File.join(urls_to_view_folder, name))
|
98
122
|
end.map do |name|
|
99
|
-
|
123
|
+
data_from_file(File.join(urls_to_view_folder, name))
|
100
124
|
end.select do |url|
|
101
125
|
!url.nil?
|
102
126
|
end
|
@@ -135,6 +159,27 @@ private
|
|
135
159
|
File.directory?(supervise_folder)
|
136
160
|
end
|
137
161
|
|
162
|
+
def raw_status
|
163
|
+
# status in daemontools supervise format
|
164
|
+
# look at runit's sv.c for details
|
165
|
+
if @data == ''
|
166
|
+
data = data_from_file(File.join(supervise_folder, 'status'))
|
167
|
+
@data = !data.nil? && data.length == 20 ? data : nil
|
168
|
+
end
|
169
|
+
@data
|
170
|
+
end
|
171
|
+
|
172
|
+
def status_byte
|
173
|
+
st = raw_status
|
174
|
+
return 0 unless st
|
175
|
+
st.unpack('xxxxxxxxxxxxxxxxxxxC').first
|
176
|
+
end
|
177
|
+
|
178
|
+
def data_from_file(file_name)
|
179
|
+
return @files[file_name] if @files.include?(file_name)
|
180
|
+
@files[file_name] = self.class.real_data_from_file(file_name)
|
181
|
+
end
|
182
|
+
|
138
183
|
class << self
|
139
184
|
def all
|
140
185
|
all_service_names.sort.map do |name|
|
@@ -153,7 +198,7 @@ private
|
|
153
198
|
@log_location_cache
|
154
199
|
end
|
155
200
|
|
156
|
-
def
|
201
|
+
def real_data_from_file(file_name)
|
157
202
|
return nil unless File.readable?(file_name)
|
158
203
|
data = IO.read(file_name)
|
159
204
|
data.chomp! unless data.nil?
|
data/views/_service_info.erb
CHANGED
@@ -4,6 +4,7 @@ need_second_row = !service_info.files_to_view.empty? || !service_info.urls_to_vi
|
|
4
4
|
<tr class="<%= even_or_odd ? 'even' : 'odd' %>">
|
5
5
|
<td<%= need_second_row ? ' rowspan="2"' : '' %>><%= h(service_info.pid) %></td>
|
6
6
|
<th scope="row"><%= h(service_info.name) %></th>
|
7
|
+
<td><%= '%5.2d' % service_info.uptime) %></td>
|
7
8
|
<td><%= stat_subst(service_info.stat) %></td>
|
8
9
|
<td>
|
9
10
|
<% if service_info.active? %>
|
data/views/_services.erb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
<tr>
|
5
5
|
<th><%= h(t.runit.services.table.headers.pid) %></th>
|
6
6
|
<th><%= h(t.runit.services.table.headers.name) %></th>
|
7
|
+
<th><%= h(t.runit.services.table.headers.uptime) %></th>
|
7
8
|
<th><%= h(t.runit.services.table.headers.stat) %></th>
|
8
9
|
<th><%= h(t.runit.services.table.headers.actions) %></th>
|
9
10
|
<th><%= h(t.runit.services.table.headers.log_file) %></th>
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 1.
|
7
|
+
- 7
|
8
|
+
- 0
|
9
|
+
version: 1.7.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Akzhan Abdulin
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-21 00:00:00 +04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|