runit-man 2.3.15 → 2.3.16
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/runit-man/app.rb +11 -5
- data/lib/runit-man/helpers.rb +2 -2
- data/lib/runit-man/log_location_cache/logger.rb +1 -1
- data/lib/runit-man/service_info.rb +6 -332
- data/lib/runit-man/service_info/base.rb +246 -0
- data/lib/runit-man/service_info/logger.rb +48 -0
- data/lib/runit-man/service_info/svlogd.rb +45 -0
- data/lib/runit-man/version.rb +1 -1
- metadata +31 -28
data/lib/runit-man/app.rb
CHANGED
@@ -69,6 +69,12 @@ class RunitMan < Sinatra::Base
|
|
69
69
|
end
|
70
70
|
|
71
71
|
before do
|
72
|
+
case RunitMan.runit_logger
|
73
|
+
when RunitMan::DEFAULT_LOGGER;
|
74
|
+
ServiceInfo.klass = ServiceInfo::Svlogd
|
75
|
+
else
|
76
|
+
ServiceInfo.klass = ServiceInfo::Logger
|
77
|
+
end
|
72
78
|
@read_write_mode = RunitMan.read_write_mode
|
73
79
|
@scripts = []
|
74
80
|
base_content_type = CONTENT_TYPES.keys.detect do |t|
|
@@ -139,7 +145,7 @@ class RunitMan < Sinatra::Base
|
|
139
145
|
count = count.to_i
|
140
146
|
count = MIN_TAIL if count < MIN_TAIL
|
141
147
|
count = MAX_TAIL if count > MAX_TAIL
|
142
|
-
srv = ServiceInfo[name]
|
148
|
+
srv = ServiceInfo.klass[name]
|
143
149
|
return nil if srv.nil? || !srv.logged?
|
144
150
|
text = ''
|
145
151
|
File::Tail::Logfile.open(srv.log_file_location, :backward => count, :return_if_eof => true) do |log|
|
@@ -194,7 +200,7 @@ class RunitMan < Sinatra::Base
|
|
194
200
|
end
|
195
201
|
|
196
202
|
get %r[^/([^/]+)/log\-downloads/?$] do |name|
|
197
|
-
srv = ServiceInfo[name]
|
203
|
+
srv = ServiceInfo.klass[name]
|
198
204
|
return not_found if srv.nil? || !srv.logged?
|
199
205
|
haml :log_downloads, :locals => {
|
200
206
|
:name => name,
|
@@ -203,7 +209,7 @@ class RunitMan < Sinatra::Base
|
|
203
209
|
end
|
204
210
|
|
205
211
|
get %r[^/([^/]+)/log\-download/(.+)$] do |name, file_name|
|
206
|
-
srv = ServiceInfo[name]
|
212
|
+
srv = ServiceInfo.klass[name]
|
207
213
|
return not_found if srv.nil? || !srv.logged?
|
208
214
|
f = srv.log_files.detect { |f| f[:name] == file_name }
|
209
215
|
return not_found unless f
|
@@ -241,7 +247,7 @@ class RunitMan < Sinatra::Base
|
|
241
247
|
|
242
248
|
post '/:name/signal/:signal' do |name, signal|
|
243
249
|
unless readonly?
|
244
|
-
service = ServiceInfo[name]
|
250
|
+
service = ServiceInfo.klass[name]
|
245
251
|
return not_found if service.nil?
|
246
252
|
service.send_signal(signal)
|
247
253
|
log_action(name, "send signal \"#{signal}\"")
|
@@ -253,7 +259,7 @@ class RunitMan < Sinatra::Base
|
|
253
259
|
|
254
260
|
post '/:name/:action' do |name, action|
|
255
261
|
unless readonly?
|
256
|
-
service = ServiceInfo[name]
|
262
|
+
service = ServiceInfo.klass[name]
|
257
263
|
action = "#{action}!".to_sym
|
258
264
|
return not_found if service.nil? || !service.respond_to?(action)
|
259
265
|
service.send(action)
|
data/lib/runit-man/helpers.rb
CHANGED
@@ -1,336 +1,10 @@
|
|
1
|
-
|
2
|
-
require 'runit-man/log_location_cache/svlogd'
|
3
|
-
require 'runit-man/log_location_cache/logger'
|
4
|
-
require 'runit-man/service_status'
|
5
|
-
require 'runit-man/utils'
|
6
|
-
|
7
|
-
class ServiceInfo
|
8
|
-
SPECIAL_LOG_FILES = %w(lock config state newstate).freeze
|
9
|
-
|
10
|
-
attr_reader :name
|
11
|
-
|
12
|
-
def initialize(a_name)
|
13
|
-
@name = a_name
|
14
|
-
@files = {}
|
15
|
-
|
16
|
-
@status = ServiceStatus.new(data_from_file(File.join(supervise_folder, 'status')))
|
17
|
-
@log_status = ServiceStatus.new(data_from_file(File.join(log_supervise_folder, 'status')))
|
18
|
-
end
|
19
|
-
|
20
|
-
def to_hash
|
21
|
-
data = {}
|
22
|
-
[
|
23
|
-
:name, :stat, :active?, :logged?, :switchable?,
|
24
|
-
:log_file_location, :log_pid
|
25
|
-
].each do |sym|
|
26
|
-
data[sym] = send(sym)
|
27
|
-
end
|
28
|
-
|
29
|
-
[
|
30
|
-
:run?, :pid, :finish?, :down?,
|
31
|
-
:want_up?, :want_down?, :got_term?,
|
32
|
-
:started_at, :uptime
|
33
|
-
].each do |sym|
|
34
|
-
data[sym] = @status.send(sym)
|
35
|
-
end
|
36
|
-
data
|
37
|
-
end
|
38
|
-
|
39
|
-
def to_json(*args)
|
40
|
-
Yajl::Encoder.encode(to_hash, *args)
|
41
|
-
end
|
42
|
-
|
43
|
-
def logged?
|
44
|
-
File.directory?(log_supervise_folder)
|
45
|
-
end
|
46
|
-
|
47
|
-
def stat
|
48
|
-
@status.to_s
|
49
|
-
end
|
50
|
-
|
51
|
-
def active?
|
52
|
-
File.directory?(active_service_folder) || File.symlink?(active_service_folder)
|
53
|
-
end
|
54
|
-
|
55
|
-
def switchable?
|
56
|
-
File.symlink?(active_service_folder) || File.directory?(inactive_service_folder)
|
57
|
-
end
|
58
|
-
|
59
|
-
def down?
|
60
|
-
@status.down?
|
61
|
-
end
|
62
|
-
|
63
|
-
def run?
|
64
|
-
@status.run?
|
65
|
-
end
|
66
|
-
|
67
|
-
def up!
|
68
|
-
send_signal :u
|
69
|
-
end
|
70
|
-
|
71
|
-
def down!
|
72
|
-
send_signal :d
|
73
|
-
end
|
74
|
-
|
75
|
-
def switch_down!
|
76
|
-
down!
|
77
|
-
File.unlink(active_service_folder)
|
78
|
-
end
|
79
|
-
|
80
|
-
def switch_up!
|
81
|
-
File.symlink(inactive_service_folder, active_service_folder)
|
82
|
-
end
|
83
|
-
|
84
|
-
def restart!
|
85
|
-
down!
|
86
|
-
up!
|
87
|
-
end
|
88
|
-
|
89
|
-
def started_at
|
90
|
-
@status.started_at
|
91
|
-
end
|
92
|
-
|
93
|
-
def pid
|
94
|
-
@status.pid
|
95
|
-
end
|
96
|
-
|
97
|
-
def uptime
|
98
|
-
@status.uptime
|
99
|
-
end
|
100
|
-
|
101
|
-
def log_pid
|
102
|
-
@log_status.pid
|
103
|
-
end
|
104
|
-
|
105
|
-
def log_file_location
|
106
|
-
rel_path = ServiceInfo.log_location_cache[log_pid]
|
107
|
-
return nil if rel_path.nil?
|
108
|
-
File.expand_path(rel_path, log_run_folder)
|
109
|
-
end
|
110
|
-
|
111
|
-
def svlogd_log_file_path(file_name)
|
112
|
-
dir_name = File.dirname(log_file_location)
|
113
|
-
File.expand_path(file_name, dir_name)
|
114
|
-
end
|
115
|
-
|
116
|
-
def logger_log_file_path(file_name)
|
117
|
-
dir_name = File.dirname(File.dirname(log_file_location))
|
118
|
-
loc = File.expand_path(File.join(file_name, "#{name}.log"), dir_name)
|
119
|
-
loc = "#{loc}.gz" unless File.exists?(loc)
|
120
|
-
loc = nil unless File.exists?(loc)
|
121
|
-
loc
|
122
|
-
end
|
123
|
-
|
124
|
-
def log_file_path(file_name)
|
125
|
-
case RunitMan.runit_logger
|
126
|
-
when RunitMan::DEFAULT_LOGGER then svlogd_log_file_path(file_name)
|
127
|
-
when /^logger(?:\:.+)?/ then logger_log_file_path(file_name)
|
128
|
-
else nil
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
def sorted_log_files(log_files)
|
133
|
-
return log_files if log_files.length < 2
|
134
|
-
log_files.sort { |a, b| a[:created] <=> b[:created] }
|
135
|
-
end
|
136
|
-
|
137
|
-
def svlogd_log_files
|
138
|
-
r = []
|
139
|
-
dir_name = File.dirname(log_file_location)
|
140
|
-
Dir.foreach(dir_name) do |name|
|
141
|
-
next if ServiceInfo.itself_or_parent?(name)
|
142
|
-
next if SPECIAL_LOG_FILES.include?(name)
|
143
|
-
full_name = File.expand_path(name, dir_name)
|
144
|
-
stats = File.stat(full_name)
|
145
|
-
stat_times = [stats.ctime.utc, stats.atime.utc, stats.mtime.utc]
|
146
|
-
min_time, max_time = stat_times.min, stat_times.max
|
147
|
-
|
148
|
-
label = "#{Utils.host_name}-#{self.name}-#{I18n.l(min_time)}-#{I18n.l(max_time)}.log"
|
149
|
-
label = label.gsub(/[\:\s\,]/, '-').gsub(/[\\\/]/, '.')
|
150
|
-
r << {
|
151
|
-
:name => name,
|
152
|
-
:label => label,
|
153
|
-
:size => stats.size,
|
154
|
-
:created => min_time,
|
155
|
-
:modified => max_time
|
156
|
-
}
|
157
|
-
end
|
158
|
-
sorted_log_files(r)
|
159
|
-
end
|
160
|
-
|
161
|
-
def logger_log_files
|
162
|
-
r = []
|
163
|
-
dir_name = File.dirname(File.dirname(log_file_location))
|
164
|
-
Dir.foreach(dir_name) do |name|
|
165
|
-
next if ServiceInfo.itself_or_parent?(name)
|
166
|
-
full_name = File.expand_path(name, dir_name)
|
167
|
-
next unless File.directory?(full_name)
|
168
|
-
file_name = File.join(full_name, "#{self.name}.log")
|
169
|
-
label = "#{Utils.host_name}-#{self.name}-#{name}.log"
|
170
|
-
unless File.exists?(file_name)
|
171
|
-
file_name = "#{file_name}.gz"
|
172
|
-
label = "#{label}.gz"
|
173
|
-
end
|
174
|
-
stats = File.stat(file_name)
|
175
|
-
stat_times = [stats.ctime.utc, stats.atime.utc, stats.mtime.utc]
|
176
|
-
min_time, max_time = stat_times.min, stat_times.max
|
177
|
-
|
178
|
-
r << {
|
179
|
-
:name => name,
|
180
|
-
:label => label,
|
181
|
-
:size => stats.size,
|
182
|
-
:created => min_time,
|
183
|
-
:modified => max_time
|
184
|
-
}
|
185
|
-
end
|
186
|
-
sorted_log_files(r)
|
187
|
-
end
|
188
|
-
|
189
|
-
def log_files
|
190
|
-
case RunitMan.runit_logger
|
191
|
-
when RunitMan::DEFAULT_LOGGER then svlogd_log_files
|
192
|
-
when /^logger(?:\:.+)?/ then logger_log_files
|
193
|
-
else []
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
|
198
|
-
def send_signal(signal)
|
199
|
-
return unless supervise?
|
200
|
-
File.open(File.join(supervise_folder, 'control'), 'w') do |f|
|
201
|
-
f.print signal.to_s
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
def files_to_view
|
206
|
-
return [] unless File.directory?(files_to_view_folder)
|
207
|
-
Dir.entries(files_to_view_folder).select do |name|
|
208
|
-
File.symlink?(File.join(files_to_view_folder, name))
|
209
|
-
end.map do |name|
|
210
|
-
File.expand_path(
|
211
|
-
File.readlink(File.join(files_to_view_folder, name)),
|
212
|
-
files_to_view_folder
|
213
|
-
)
|
214
|
-
end.select do |file_path|
|
215
|
-
File.file?(file_path)
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
def urls_to_view
|
220
|
-
return [] unless File.directory?(urls_to_view_folder)
|
221
|
-
Dir.entries(urls_to_view_folder).select do |name|
|
222
|
-
name =~ /\.url$/ && File.file?(File.join(urls_to_view_folder, name))
|
223
|
-
end.map do |name|
|
224
|
-
data_from_file(File.join(urls_to_view_folder, name))
|
225
|
-
end.select do |url|
|
226
|
-
!url.nil?
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
def allowed_signals
|
231
|
-
return [] unless File.directory?(allowed_signals_folder)
|
232
|
-
Dir.entries(allowed_signals_folder).reject do |name|
|
233
|
-
ServiceInfo.itself_or_parent?(name)
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
private
|
238
|
-
def inactive_service_folder
|
239
|
-
File.join(RunitMan.all_services_directory, name)
|
240
|
-
end
|
241
|
-
|
242
|
-
def active_service_folder
|
243
|
-
File.join(RunitMan.active_services_directory, name)
|
244
|
-
end
|
245
|
-
|
246
|
-
def files_to_view_folder
|
247
|
-
File.join(active_service_folder, 'runit-man', 'files-to-view')
|
248
|
-
end
|
249
|
-
|
250
|
-
def urls_to_view_folder
|
251
|
-
File.join(active_service_folder, 'runit-man', 'urls-to-view')
|
252
|
-
end
|
253
|
-
|
254
|
-
def allowed_signals_folder
|
255
|
-
File.join(active_service_folder, 'runit-man', 'allowed-signals')
|
256
|
-
end
|
257
|
-
|
258
|
-
def supervise_folder
|
259
|
-
File.join(active_service_folder, 'supervise')
|
260
|
-
end
|
261
|
-
|
262
|
-
def log_run_folder
|
263
|
-
File.join(active_service_folder, 'log')
|
264
|
-
end
|
265
|
-
|
266
|
-
def log_supervise_folder
|
267
|
-
File.join(log_run_folder, 'supervise')
|
268
|
-
end
|
269
|
-
|
270
|
-
def supervise?
|
271
|
-
File.directory?(supervise_folder)
|
272
|
-
end
|
273
|
-
|
274
|
-
def data_from_file(file_name)
|
275
|
-
return @files[file_name] if @files.include?(file_name)
|
276
|
-
@files[file_name] = ServiceInfo.real_data_from_file(file_name)
|
277
|
-
end
|
278
|
-
|
1
|
+
module ServiceInfo
|
279
2
|
class << self
|
280
|
-
|
281
|
-
all_service_names.sort.map do |name|
|
282
|
-
ServiceInfo.new(name)
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
def [](name)
|
287
|
-
all_service_names.include?(name) ? ServiceInfo.new(name) : nil
|
288
|
-
end
|
289
|
-
|
290
|
-
def log_location_cache
|
291
|
-
@log_location_cache ||= case RunitMan.runit_logger
|
292
|
-
when RunitMan::DEFAULT_LOGGER; LogLocationCache::Svlogd.new
|
293
|
-
when /^logger\b/; LogLocationCache::Logger.new(RunitMan.runit_logger)
|
294
|
-
else raise NotImplementedError.new
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
def real_data_from_file(file_name)
|
299
|
-
return nil unless File.readable?(file_name)
|
300
|
-
if RUBY_VERSION >= '1.9'
|
301
|
-
data = IO.read(file_name, :external_encoding => 'ASCII-8BIT')
|
302
|
-
else
|
303
|
-
data = IO.read(file_name)
|
304
|
-
end
|
305
|
-
data.chomp! unless data.nil?
|
306
|
-
data.empty? ? nil : data
|
307
|
-
end
|
308
|
-
|
309
|
-
def itself_or_parent?(name)
|
310
|
-
name == '.' || name == '..'
|
311
|
-
end
|
312
|
-
|
313
|
-
private
|
314
|
-
def active_service_names
|
315
|
-
return [] unless File.directory?(RunitMan.active_services_directory)
|
316
|
-
Dir.entries(RunitMan.active_services_directory).reject do |name|
|
317
|
-
full_name = File.join(RunitMan.active_services_directory, name)
|
318
|
-
itself_or_parent?(name) || (!File.symlink?(full_name) && !File.directory?(full_name))
|
319
|
-
end
|
320
|
-
end
|
321
|
-
|
322
|
-
def inactive_service_names
|
323
|
-
return [] unless File.directory?(RunitMan.all_services_directory)
|
324
|
-
actives = active_service_names
|
325
|
-
Dir.entries(RunitMan.all_services_directory).reject do |name|
|
326
|
-
full_name = File.join(RunitMan.all_services_directory, name)
|
327
|
-
itself_or_parent?(name) || !File.directory?(full_name) || actives.include?(name)
|
328
|
-
end
|
329
|
-
end
|
330
|
-
|
331
|
-
def all_service_names
|
332
|
-
(active_service_names + inactive_service_names)
|
333
|
-
end
|
3
|
+
attr_accessor :klass
|
334
4
|
end
|
335
5
|
end
|
336
6
|
|
7
|
+
require 'runit-man/service_info/base'
|
8
|
+
require 'runit-man/service_info/svlogd'
|
9
|
+
require 'runit-man/service_info/logger'
|
10
|
+
|
@@ -0,0 +1,246 @@
|
|
1
|
+
require 'runit-man/log_location_cache/base'
|
2
|
+
require 'runit-man/service_status'
|
3
|
+
require 'runit-man/utils'
|
4
|
+
|
5
|
+
class ServiceInfo::Base
|
6
|
+
|
7
|
+
attr_reader :name
|
8
|
+
|
9
|
+
def initialize(a_name)
|
10
|
+
@name = a_name
|
11
|
+
@files = {}
|
12
|
+
|
13
|
+
@status = ServiceStatus.new(data_from_file(File.join(supervise_folder, 'status')))
|
14
|
+
@log_status = ServiceStatus.new(data_from_file(File.join(log_supervise_folder, 'status')))
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_hash
|
18
|
+
data = {}
|
19
|
+
[
|
20
|
+
:name, :stat, :active?, :logged?, :switchable?,
|
21
|
+
:log_file_location, :log_pid
|
22
|
+
].each do |sym|
|
23
|
+
data[sym] = send(sym)
|
24
|
+
end
|
25
|
+
|
26
|
+
[
|
27
|
+
:run?, :pid, :finish?, :down?,
|
28
|
+
:want_up?, :want_down?, :got_term?,
|
29
|
+
:started_at, :uptime
|
30
|
+
].each do |sym|
|
31
|
+
data[sym] = @status.send(sym)
|
32
|
+
end
|
33
|
+
data
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_json(*args)
|
37
|
+
Yajl::Encoder.encode(to_hash, *args)
|
38
|
+
end
|
39
|
+
|
40
|
+
def logged?
|
41
|
+
File.directory?(log_supervise_folder)
|
42
|
+
end
|
43
|
+
|
44
|
+
def stat
|
45
|
+
@status.to_s
|
46
|
+
end
|
47
|
+
|
48
|
+
def active?
|
49
|
+
File.directory?(active_service_folder) || File.symlink?(active_service_folder)
|
50
|
+
end
|
51
|
+
|
52
|
+
def switchable?
|
53
|
+
File.symlink?(active_service_folder) || File.directory?(inactive_service_folder)
|
54
|
+
end
|
55
|
+
|
56
|
+
def down?
|
57
|
+
@status.down?
|
58
|
+
end
|
59
|
+
|
60
|
+
def run?
|
61
|
+
@status.run?
|
62
|
+
end
|
63
|
+
|
64
|
+
def up!
|
65
|
+
send_signal :u
|
66
|
+
end
|
67
|
+
|
68
|
+
def down!
|
69
|
+
send_signal :d
|
70
|
+
end
|
71
|
+
|
72
|
+
def switch_down!
|
73
|
+
down!
|
74
|
+
File.unlink(active_service_folder)
|
75
|
+
end
|
76
|
+
|
77
|
+
def switch_up!
|
78
|
+
File.symlink(inactive_service_folder, active_service_folder)
|
79
|
+
end
|
80
|
+
|
81
|
+
def restart!
|
82
|
+
down!
|
83
|
+
up!
|
84
|
+
end
|
85
|
+
|
86
|
+
def started_at
|
87
|
+
@status.started_at
|
88
|
+
end
|
89
|
+
|
90
|
+
def pid
|
91
|
+
@status.pid
|
92
|
+
end
|
93
|
+
|
94
|
+
def uptime
|
95
|
+
@status.uptime
|
96
|
+
end
|
97
|
+
|
98
|
+
def log_pid
|
99
|
+
@log_status.pid
|
100
|
+
end
|
101
|
+
|
102
|
+
def log_file_location
|
103
|
+
rel_path = ServiceInfo.klass.log_location_cache[log_pid]
|
104
|
+
return nil if rel_path.nil?
|
105
|
+
File.expand_path(rel_path, log_run_folder)
|
106
|
+
end
|
107
|
+
|
108
|
+
def log_file_path(file_name)
|
109
|
+
nil
|
110
|
+
end
|
111
|
+
|
112
|
+
def log_files
|
113
|
+
[]
|
114
|
+
end
|
115
|
+
|
116
|
+
def send_signal(signal)
|
117
|
+
return unless supervise?
|
118
|
+
File.open(File.join(supervise_folder, 'control'), 'w') do |f|
|
119
|
+
f.print signal.to_s
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def files_to_view
|
124
|
+
return [] unless File.directory?(files_to_view_folder)
|
125
|
+
Dir.entries(files_to_view_folder).select do |name|
|
126
|
+
File.symlink?(File.join(files_to_view_folder, name))
|
127
|
+
end.map do |name|
|
128
|
+
File.expand_path(
|
129
|
+
File.readlink(File.join(files_to_view_folder, name)),
|
130
|
+
files_to_view_folder
|
131
|
+
)
|
132
|
+
end.select do |file_path|
|
133
|
+
File.file?(file_path)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def urls_to_view
|
138
|
+
return [] unless File.directory?(urls_to_view_folder)
|
139
|
+
Dir.entries(urls_to_view_folder).select do |name|
|
140
|
+
name =~ /\.url$/ && File.file?(File.join(urls_to_view_folder, name))
|
141
|
+
end.map do |name|
|
142
|
+
data_from_file(File.join(urls_to_view_folder, name))
|
143
|
+
end.select do |url|
|
144
|
+
!url.nil?
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def allowed_signals
|
149
|
+
return [] unless File.directory?(allowed_signals_folder)
|
150
|
+
Dir.entries(allowed_signals_folder).reject do |name|
|
151
|
+
ServiceInfo::Base.itself_or_parent?(name)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
protected
|
156
|
+
def inactive_service_folder
|
157
|
+
File.join(RunitMan.all_services_directory, name)
|
158
|
+
end
|
159
|
+
|
160
|
+
def active_service_folder
|
161
|
+
File.join(RunitMan.active_services_directory, name)
|
162
|
+
end
|
163
|
+
|
164
|
+
def files_to_view_folder
|
165
|
+
File.join(active_service_folder, 'runit-man', 'files-to-view')
|
166
|
+
end
|
167
|
+
|
168
|
+
def urls_to_view_folder
|
169
|
+
File.join(active_service_folder, 'runit-man', 'urls-to-view')
|
170
|
+
end
|
171
|
+
|
172
|
+
def allowed_signals_folder
|
173
|
+
File.join(active_service_folder, 'runit-man', 'allowed-signals')
|
174
|
+
end
|
175
|
+
|
176
|
+
def supervise_folder
|
177
|
+
File.join(active_service_folder, 'supervise')
|
178
|
+
end
|
179
|
+
|
180
|
+
def log_run_folder
|
181
|
+
File.join(active_service_folder, 'log')
|
182
|
+
end
|
183
|
+
|
184
|
+
def log_supervise_folder
|
185
|
+
File.join(log_run_folder, 'supervise')
|
186
|
+
end
|
187
|
+
|
188
|
+
def supervise?
|
189
|
+
File.directory?(supervise_folder)
|
190
|
+
end
|
191
|
+
|
192
|
+
def data_from_file(file_name)
|
193
|
+
return @files[file_name] if @files.include?(file_name)
|
194
|
+
@files[file_name] = ServiceInfo::Base.real_data_from_file(file_name)
|
195
|
+
end
|
196
|
+
|
197
|
+
class << self
|
198
|
+
def all
|
199
|
+
all_service_names.sort.map do |name|
|
200
|
+
ServiceInfo.klass.new(name)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def [](name)
|
205
|
+
all_service_names.include?(name) ? ServiceInfo.klass.new(name) : nil
|
206
|
+
end
|
207
|
+
|
208
|
+
def real_data_from_file(file_name)
|
209
|
+
return nil unless File.readable?(file_name)
|
210
|
+
if RUBY_VERSION >= '1.9'
|
211
|
+
data = IO.read(file_name, :external_encoding => 'ASCII-8BIT')
|
212
|
+
else
|
213
|
+
data = IO.read(file_name)
|
214
|
+
end
|
215
|
+
data.chomp! unless data.nil?
|
216
|
+
data.empty? ? nil : data
|
217
|
+
end
|
218
|
+
|
219
|
+
def itself_or_parent?(name)
|
220
|
+
name == '.' || name == '..'
|
221
|
+
end
|
222
|
+
|
223
|
+
private
|
224
|
+
def active_service_names
|
225
|
+
return [] unless File.directory?(RunitMan.active_services_directory)
|
226
|
+
Dir.entries(RunitMan.active_services_directory).reject do |name|
|
227
|
+
full_name = File.join(RunitMan.active_services_directory, name)
|
228
|
+
itself_or_parent?(name) || (!File.symlink?(full_name) && !File.directory?(full_name))
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def inactive_service_names
|
233
|
+
return [] unless File.directory?(RunitMan.all_services_directory)
|
234
|
+
actives = active_service_names
|
235
|
+
Dir.entries(RunitMan.all_services_directory).reject do |name|
|
236
|
+
full_name = File.join(RunitMan.all_services_directory, name)
|
237
|
+
itself_or_parent?(name) || !File.directory?(full_name) || actives.include?(name)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
def all_service_names
|
242
|
+
(active_service_names + inactive_service_names)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'runit-man/log_location_cache/logger'
|
2
|
+
|
3
|
+
class ServiceInfo::Logger < ServiceInfo::Base
|
4
|
+
|
5
|
+
def log_file_path(file_name)
|
6
|
+
dir_name = File.dirname(File.dirname(log_file_location))
|
7
|
+
loc = File.expand_path(File.join(file_name, "#{name}.log"), dir_name)
|
8
|
+
loc = "#{loc}.gz" unless File.exists?(loc)
|
9
|
+
loc = nil unless File.exists?(loc)
|
10
|
+
loc
|
11
|
+
end
|
12
|
+
|
13
|
+
def log_files
|
14
|
+
r = []
|
15
|
+
dir_name = File.dirname(File.dirname(log_file_location))
|
16
|
+
Dir.foreach(dir_name) do |name|
|
17
|
+
next if ServiceInfo.itself_or_parent?(name)
|
18
|
+
full_name = File.expand_path(name, dir_name)
|
19
|
+
next unless File.directory?(full_name)
|
20
|
+
file_name = File.join(full_name, "#{self.name}.log")
|
21
|
+
label = "#{Utils.host_name}-#{self.name}-#{name}.log"
|
22
|
+
unless File.exists?(file_name)
|
23
|
+
file_name = "#{file_name}.gz"
|
24
|
+
label = "#{label}.gz"
|
25
|
+
end
|
26
|
+
stats = File.stat(file_name)
|
27
|
+
stat_times = [stats.ctime.utc, stats.atime.utc, stats.mtime.utc]
|
28
|
+
min_time, max_time = stat_times.min, stat_times.max
|
29
|
+
|
30
|
+
r << {
|
31
|
+
:name => name,
|
32
|
+
:label => label,
|
33
|
+
:size => stats.size,
|
34
|
+
:created => min_time,
|
35
|
+
:modified => max_time
|
36
|
+
}
|
37
|
+
end
|
38
|
+
sorted_log_files(r)
|
39
|
+
end
|
40
|
+
|
41
|
+
class << self
|
42
|
+
def log_location_cache
|
43
|
+
@log_location_cache ||= LogLocationCache::Logger.new(RunitMan.runit_logger)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'runit-man/log_location_cache/svlogd'
|
2
|
+
|
3
|
+
class ServiceInfo::Svlogd < ServiceInfo::Base
|
4
|
+
SPECIAL_LOG_FILES = %w(lock config state newstate).freeze
|
5
|
+
|
6
|
+
def log_file_path(file_name)
|
7
|
+
dir_name = File.dirname(log_file_location)
|
8
|
+
File.expand_path(file_name, dir_name)
|
9
|
+
end
|
10
|
+
|
11
|
+
def log_files
|
12
|
+
r = []
|
13
|
+
dir_name = File.dirname(log_file_location)
|
14
|
+
Dir.foreach(dir_name) do |name|
|
15
|
+
next if ServiceInfo.itself_or_parent?(name)
|
16
|
+
next if SPECIAL_LOG_FILES.include?(name)
|
17
|
+
full_name = File.expand_path(name, dir_name)
|
18
|
+
stats = File.stat(full_name)
|
19
|
+
stat_times = [stats.ctime.utc, stats.atime.utc, stats.mtime.utc]
|
20
|
+
min_time, max_time = stat_times.min, stat_times.max
|
21
|
+
|
22
|
+
label = "#{Utils.host_name}-#{self.name}-#{I18n.l(min_time)}-#{I18n.l(max_time)}.log"
|
23
|
+
label = label.gsub(/[\:\s\,]/, '-').gsub(/[\\\/]/, '.')
|
24
|
+
r << {
|
25
|
+
:name => name,
|
26
|
+
:label => label,
|
27
|
+
:size => stats.size,
|
28
|
+
:created => min_time,
|
29
|
+
:modified => max_time
|
30
|
+
}
|
31
|
+
end
|
32
|
+
sorted_log_files(r)
|
33
|
+
end
|
34
|
+
|
35
|
+
class << self
|
36
|
+
|
37
|
+
def log_location_cache
|
38
|
+
@log_location_cache ||= LogLocationCache::Svlogd.new
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
end
|
45
|
+
|
data/lib/runit-man/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: runit-man
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.16
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yajl-ruby
|
16
|
-
requirement: &
|
16
|
+
requirement: &2157490420 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2157490420
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: haml
|
27
|
-
requirement: &
|
27
|
+
requirement: &2157489300 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '3.0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2157489300
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sinatra
|
38
|
-
requirement: &
|
38
|
+
requirement: &2157488520 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '1.3'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2157488520
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sinatra-content-for2
|
49
|
-
requirement: &
|
49
|
+
requirement: &2157487020 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.2.4
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2157487020
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: i18n
|
60
|
-
requirement: &
|
60
|
+
requirement: &2157485720 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0.5'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2157485720
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: file-tail
|
71
|
-
requirement: &
|
71
|
+
requirement: &2157485060 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 1.0.7
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2157485060
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rake
|
82
|
-
requirement: &
|
82
|
+
requirement: &2157484260 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -90,10 +90,10 @@ dependencies:
|
|
90
90
|
version: 0.9.0
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
|
-
version_requirements: *
|
93
|
+
version_requirements: *2157484260
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
95
|
name: rspec-core
|
96
|
-
requirement: &
|
96
|
+
requirement: &2157470300 !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
98
98
|
requirements:
|
99
99
|
- - ! '>='
|
@@ -101,10 +101,10 @@ dependencies:
|
|
101
101
|
version: '0'
|
102
102
|
type: :development
|
103
103
|
prerelease: false
|
104
|
-
version_requirements: *
|
104
|
+
version_requirements: *2157470300
|
105
105
|
- !ruby/object:Gem::Dependency
|
106
106
|
name: rspec-expectations
|
107
|
-
requirement: &
|
107
|
+
requirement: &2157468360 !ruby/object:Gem::Requirement
|
108
108
|
none: false
|
109
109
|
requirements:
|
110
110
|
- - ! '>='
|
@@ -112,10 +112,10 @@ dependencies:
|
|
112
112
|
version: '0'
|
113
113
|
type: :development
|
114
114
|
prerelease: false
|
115
|
-
version_requirements: *
|
115
|
+
version_requirements: *2157468360
|
116
116
|
- !ruby/object:Gem::Dependency
|
117
117
|
name: rr
|
118
|
-
requirement: &
|
118
|
+
requirement: &2157467760 !ruby/object:Gem::Requirement
|
119
119
|
none: false
|
120
120
|
requirements:
|
121
121
|
- - ! '>='
|
@@ -123,10 +123,10 @@ dependencies:
|
|
123
123
|
version: '0'
|
124
124
|
type: :development
|
125
125
|
prerelease: false
|
126
|
-
version_requirements: *
|
126
|
+
version_requirements: *2157467760
|
127
127
|
- !ruby/object:Gem::Dependency
|
128
128
|
name: rack-test
|
129
|
-
requirement: &
|
129
|
+
requirement: &2157467120 !ruby/object:Gem::Requirement
|
130
130
|
none: false
|
131
131
|
requirements:
|
132
132
|
- - ! '>='
|
@@ -134,10 +134,10 @@ dependencies:
|
|
134
134
|
version: '0'
|
135
135
|
type: :development
|
136
136
|
prerelease: false
|
137
|
-
version_requirements: *
|
137
|
+
version_requirements: *2157467120
|
138
138
|
- !ruby/object:Gem::Dependency
|
139
139
|
name: bundler
|
140
|
-
requirement: &
|
140
|
+
requirement: &2157466320 !ruby/object:Gem::Requirement
|
141
141
|
none: false
|
142
142
|
requirements:
|
143
143
|
- - ~>
|
@@ -145,7 +145,7 @@ dependencies:
|
|
145
145
|
version: 1.0.10
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
|
-
version_requirements: *
|
148
|
+
version_requirements: *2157466320
|
149
149
|
description: ! 'Simple runit (http://smarden.org/runit/) web management tool with
|
150
150
|
i18n.
|
151
151
|
|
@@ -185,6 +185,9 @@ files:
|
|
185
185
|
- lib/runit-man/rainbows.conf
|
186
186
|
- lib/runit-man/runner.rb
|
187
187
|
- lib/runit-man/service_info.rb
|
188
|
+
- lib/runit-man/service_info/base.rb
|
189
|
+
- lib/runit-man/service_info/logger.rb
|
190
|
+
- lib/runit-man/service_info/svlogd.rb
|
188
191
|
- lib/runit-man/service_status.rb
|
189
192
|
- lib/runit-man/utils.rb
|
190
193
|
- lib/runit-man/version.rb
|
@@ -226,7 +229,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
226
229
|
version: '0'
|
227
230
|
segments:
|
228
231
|
- 0
|
229
|
-
hash:
|
232
|
+
hash: -118617106794587710
|
230
233
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
231
234
|
none: false
|
232
235
|
requirements:
|
@@ -235,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
235
238
|
version: '0'
|
236
239
|
segments:
|
237
240
|
- 0
|
238
|
-
hash:
|
241
|
+
hash: -118617106794587710
|
239
242
|
requirements:
|
240
243
|
- none
|
241
244
|
rubyforge_project:
|