runit-man 2.4.0a1 → 2.4.0a2

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,3 +17,6 @@ runit_service "runit-man"
17
17
  # logger installation
18
18
  runit_service "runit-man-logger"
19
19
 
20
+ # need vim for inplace actions
21
+ package "vim-nox"
22
+
@@ -153,30 +153,45 @@ class RunitMan::App < Sinatra::Base
153
153
  Yajl::Encoder.encode(service_infos)
154
154
  end
155
155
 
156
+ def log_of_service_n(filepath, count, no)
157
+ text = ''
158
+ if File.readable?(filepath)
159
+ File::Tail::Logfile.open(filepath, :backward => count, :return_if_eof => true) do |log|
160
+ log.tail do |line|
161
+ text += line
162
+ end
163
+ end
164
+ end
165
+
166
+ {
167
+ :location => filepath,
168
+ :text => text,
169
+ :id => no
170
+ }
171
+ end
172
+
156
173
  def log_of_service(name, count, no)
157
174
  count = count.to_i
158
- count = MIN_TAIL if count < MIN_TAIL
159
- count = MAX_TAIL if count > MAX_TAIL
175
+ count = MIN_TAIL if count < MIN_TAIL
176
+ count = MAX_TAIL if count > MAX_TAIL
160
177
  srv = ServiceInfo.klass[name]
161
178
  return nil if srv.nil? || !srv.logged?
162
179
 
163
- text = ''
164
- File::Tail::Logfile.open(srv.log_file_location, :backward => count, :return_if_eof => true) do |log|
165
- log.tail do |line|
166
- text += line
180
+ logs = []
181
+ if no.nil?
182
+ srv.log_file_locations.each_with_index do |filepath, no|
183
+ logs << log_of_service_n(filepath, count, no)
167
184
  end
185
+ else
186
+ filepath = srv.log_file_locations[no]
187
+ return nil if filepath.nil?
188
+ logs << log_of_service_n(filepath, count, no)
168
189
  end
169
190
 
170
191
  {
171
192
  :name => name,
172
193
  :count => count,
173
- :logs => [
174
- {
175
- :location => srv.log_file_location,
176
- :text => text,
177
- :id => 0
178
- }
179
- ]
194
+ :logs => logs
180
195
  }
181
196
  end
182
197
 
@@ -224,7 +239,7 @@ class RunitMan::App < Sinatra::Base
224
239
 
225
240
  haml :log_downloads, :locals => {
226
241
  :name => name,
227
- :files => srv.log_files
242
+ :files => srv.all_log_file_locations
228
243
  }
229
244
  end
230
245
 
@@ -232,10 +247,10 @@ class RunitMan::App < Sinatra::Base
232
247
  srv = ServiceInfo.klass[name]
233
248
  return not_found if srv.nil? || !srv.logged?
234
249
 
235
- f = srv.log_files.detect { |f| f[:name] == file_name }
250
+ f = srv.all_log_file_locations.detect { |f| f[:name] == file_name }
236
251
  return not_found unless f
237
252
 
238
- send_file(srv.log_file_path(file_name), :type => 'text/plain', :disposition => 'attachment', :filename => f[:label], :last_modified => f[:modified].httpdate)
253
+ send_file(f[:path], :type => 'text/plain', :disposition => 'attachment', :filename => f[:label], :last_modified => f[:modified].httpdate)
239
254
  end
240
255
 
241
256
  get '/view' do
@@ -244,7 +259,7 @@ class RunitMan::App < Sinatra::Base
244
259
 
245
260
  @title = t('runit.view_file.title', :file => data[:name], :host => host_name)
246
261
  content_type CONTENT_TYPES[:html], :charset => 'utf-8'
247
- haml :view_file, :locals => data
262
+ haml :view_file, :locals => data
248
263
  end
249
264
 
250
265
  get '/view.txt' do
@@ -1,3 +1,4 @@
1
+ # Namespace: Information about service
1
2
  module ServiceInfo
2
3
  class << self
3
4
  attr_accessor :klass
@@ -1,7 +1,7 @@
1
- require 'runit-man/log_location_cache/base'
2
1
  require 'runit-man/service_status'
3
2
  require 'runit-man/utils'
4
3
 
4
+ # Represents information about service on any host.
5
5
  class ServiceInfo::Base
6
6
 
7
7
  attr_reader :name
@@ -99,18 +99,13 @@ class ServiceInfo::Base
99
99
  @log_status.pid
100
100
  end
101
101
 
102
- def log_file_location
103
- rel_path = ServiceInfo.klass.log_location_cache[log_pid]
104
- return nil if rel_path.nil?
105
-
106
- File.expand_path(rel_path, log_run_folder)
107
- end
108
-
109
- def log_file_path(file_name)
110
- nil
102
+ # Current log file locations
103
+ def log_file_locations
104
+ []
111
105
  end
112
106
 
113
- def log_files
107
+ # All log file locations
108
+ def all_log_file_locations
114
109
  []
115
110
  end
116
111
 
@@ -200,10 +195,41 @@ protected
200
195
  @files[file_name] = ServiceInfo::Base.real_data_from_file(file_name)
201
196
  end
202
197
 
203
- def sorted_log_files(log_files)
204
- return log_files if log_files.length < 2
198
+ def sorted_file_locations(file_locations)
199
+ return file_locations if file_locations.length < 2
200
+
201
+ file_locations.sort { |a, b| a[:created] <=> b[:created] }
202
+ end
203
+
204
+ def logger_name
205
+ not_implemented
206
+ end
207
+
208
+ def log_command
209
+ return nil if log_pid.nil?
210
+
211
+ ps_output = `ps -o args -p #{log_pid} 2>&1`.split("\n")
212
+ return nil if ps_output.length < 2
213
+
214
+ cmd = ps_output[1].chomp
215
+ cmd != '' ? cmd : nil
216
+ end
217
+
218
+ def log_command_args
219
+ cmd = log_command
220
+ return nil if cmd.nil?
221
+
222
+ args = cmd.split(/\s+/).select { |arg| arg !~ /^\-/ }
223
+ return nil if args.shift !~ /#{Regexp.escape(logger_name)}/
224
+
225
+ args
226
+ end
227
+
228
+ def log_folder_base_name
229
+ args = log_command_args
230
+ return nil if args.nil?
205
231
 
206
- log_files.sort { |a, b| a[:created] <=> b[:created] }
232
+ args.first
207
233
  end
208
234
 
209
235
  class << self
@@ -1,23 +1,55 @@
1
- require 'runit-man/log_location_cache/logger'
2
-
1
+ # Represents information about service on logger-enabled host.
3
2
  class ServiceInfo::Logger < ServiceInfo::Base
4
3
 
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)
4
+ def logger_string
5
+ RunitMan::App.runit_logger
6
+ end
7
+
8
+ def logger_name
9
+ (logger_string =~ /^([^\:]+)\:/) ? $1 : logger_string
10
+ end
11
+
12
+ def log_base_folder
13
+ (logger_string =~ /^[^\:]+\:([^\:]+)/) ? $1 : nil
14
+ end
15
+
16
+ def log_folder
17
+ folder = log_folder_base_name
18
+ (log_base_folder.nil? || folder.nil?) ? folder : File.expand_path(File.join(log_base_folder, folder))
19
+ end
20
+
21
+ def log_folder_base_name
22
+ result = super
8
23
 
9
- loc = "#{loc}.gz" unless File.exists?(loc)
10
- loc = nil unless File.exists?(loc)
24
+ # we should remove : from the end of the line for logger installations.
25
+ result = $1 if result =~ /^(.+)\:$/
11
26
 
12
- loc
27
+ result
13
28
  end
14
29
 
15
- def log_files
16
- lfloc = log_file_location
17
- return [] if lfloc.nil?
30
+ # Current log file locations
31
+ def log_file_locations
32
+ folder = log_folder
33
+ return [] if folder.nil? || ! File.directory?(log_folder)
18
34
 
19
- dir_name = File.expand_path(File.dirname(File.dirname(lfloc)))
20
- return [] unless File.directory?(dir_name)
35
+ curdir = File.join(log_folder, Time.now.strftime('%Y-%m-%d'))
36
+ return [] unless File.directory?(curdir)
37
+ r = []
38
+ Dir.foreach(curdir) do |filename|
39
+ next if ServiceInfo::Base.itself_or_parent?(filename)
40
+ filepath = File.expand_path(filename, curdir)
41
+ next unless File.file?(filepath) && File.readable?(filepath)
42
+
43
+ r << filepath
44
+ end
45
+
46
+ r
47
+ end
48
+
49
+ # All log file locations
50
+ def all_log_file_locations
51
+ dir_name = log_folder
52
+ return [] if log_folder.nil? || ! File.directory?(dir_name)
21
53
 
22
54
  r = []
23
55
  Dir.foreach(dir_name) do |subdirname|
@@ -28,15 +60,17 @@ class ServiceInfo::Logger < ServiceInfo::Base
28
60
  Dir.foreach(subdirpath) do |filename|
29
61
  next if ServiceInfo::Base.itself_or_parent?(filename)
30
62
  filepath = File.expand_path(filename, subdirpath)
31
- label = "#{Utils.host_name}-#{filename}"
32
63
  next unless File.file?(filepath) && File.readable?(filepath)
33
64
 
34
- stats = File.stat(file_name)
65
+ label = "#{Utils.host_name}-#{subdirname}-#{filename}"
66
+
67
+ stats = File.stat(filepath)
35
68
  stat_times = [stats.ctime.utc, stats.atime.utc, stats.mtime.utc]
36
69
  min_time, max_time = stat_times.min, stat_times.max
37
70
 
38
71
  r << {
39
- :name => name,
72
+ :name => filename,
73
+ :path => filepath,
40
74
  :label => label,
41
75
  :size => stats.size,
42
76
  :created => min_time,
@@ -44,13 +78,8 @@ class ServiceInfo::Logger < ServiceInfo::Base
44
78
  }
45
79
  end
46
80
  end
47
- sorted_log_files(r)
48
- end
49
81
 
50
- class << self
51
- def log_location_cache
52
- @log_location_cache ||= LogLocationCache::Logger.new(RunitMan::App.runit_logger)
53
- end
82
+ sorted_file_locations(r)
54
83
  end
55
84
  end
56
85
 
@@ -1,22 +1,36 @@
1
- require 'runit-man/log_location_cache/svlogd'
2
-
1
+ # Represents information about service on svlogd-enabled host.
3
2
  class ServiceInfo::Svlogd < ServiceInfo::Base
4
3
  SPECIAL_LOG_FILES = %w(lock config state newstate).freeze
5
4
 
6
- def log_file_path(file_name)
7
- dir_name = File.dirname(log_file_location)
8
- File.expand_path(file_name, dir_name)
5
+ def logger_name
6
+ 'svlogd'
7
+ end
8
+
9
+ def log_folder
10
+ log_folder_base_name
11
+ end
12
+
13
+ # Current log file locations
14
+ def log_file_locations
15
+ folder = log_folder
16
+ return [] if folder.nil?
17
+
18
+ [ File.join(folder, 'current') ]
9
19
  end
10
20
 
11
- def log_files
21
+ # All log file locations
22
+ def all_log_file_locations
23
+ dir_name = log_folder
24
+ return [] if dir_name.nil? || ! File.directory?(dir_name)
12
25
  r = []
13
- dir_name = File.dirname(log_file_location)
14
26
  Dir.foreach(dir_name) do |name|
15
27
  next if ServiceInfo::Base.itself_or_parent?(name)
16
28
  next if SPECIAL_LOG_FILES.include?(name)
17
29
 
18
- full_name = File.expand_path(name, dir_name)
19
- stats = File.stat(full_name)
30
+ path = File.expand_path(name, dir_name)
31
+ next unless File.readable?(path)
32
+
33
+ stats = File.stat(path)
20
34
  stat_times = [stats.ctime.utc, stats.atime.utc, stats.mtime.utc]
21
35
  min_time, max_time = stat_times.min, stat_times.max
22
36
 
@@ -24,19 +38,14 @@ class ServiceInfo::Svlogd < ServiceInfo::Base
24
38
  label = label.gsub(/[\:\s\,]/, '-').gsub(/[\\\/]/, '.')
25
39
  r << {
26
40
  :name => name,
41
+ :path => path,
27
42
  :label => label,
28
43
  :size => stats.size,
29
44
  :created => min_time,
30
45
  :modified => max_time
31
46
  }
32
47
  end
33
- sorted_log_files(r)
34
- end
35
-
36
- class << self
37
- def log_location_cache
38
- @log_location_cache ||= LogLocationCache::Svlogd.new
39
- end
48
+ sorted_file_locations(r)
40
49
  end
41
50
  end
42
51
 
@@ -1,4 +1,4 @@
1
1
  module RunitMan
2
- VERSION = '2.4.0a1'.freeze
2
+ VERSION = '2.4.0a2'.freeze
3
3
  end
4
4
 
@@ -23,7 +23,7 @@
23
23
  = service_action service_info.name, :switch_up, t('runit.services.table.actions.switch_up')
24
24
  %td
25
25
  - if service_info.logged?
26
- = log_link(service_info.name, :hint => t('runit.services.table.values.log_hint', :name => service_info.name), :blank => true, :title => service_info.log_file_location)
26
+ = log_link(service_info.name, :hint => t('runit.services.table.values.log_hint', :name => service_info.name), :blank => true, :title => service_info.log_file_locations.join(', '))
27
27
  = log_downloads_link(service_info.name)
28
28
  - else
29
29
  = t('runit.services.table.values.log_absent')
metadata CHANGED
@@ -1,234 +1,171 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: runit-man
3
- version: !ruby/object:Gem::Version
4
- hash: -3194798914
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.4.0a2
5
5
  prerelease: 5
6
- segments:
7
- - 2
8
- - 4
9
- - 0
10
- - a
11
- - 1
12
- version: 2.4.0a1
13
6
  platform: ruby
14
- authors:
7
+ authors:
15
8
  - Akzhan Abdulin
16
9
  autorequire:
17
10
  bindir: bin
18
11
  cert_chain: []
19
-
20
- date: 2012-04-03 00:00:00 +04:00
21
- default_executable:
22
- dependencies:
23
- - !ruby/object:Gem::Dependency
24
- type: :runtime
25
- prerelease: false
26
- version_requirements: &id001 !ruby/object:Gem::Requirement
12
+ date: 2012-04-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: yajl-ruby
16
+ requirement: &2158419480 !ruby/object:Gem::Requirement
27
17
  none: false
28
- requirements:
18
+ requirements:
29
19
  - - ~>
30
- - !ruby/object:Gem::Version
31
- hash: 15
32
- segments:
33
- - 1
34
- - 0
35
- version: "1.0"
36
- name: yajl-ruby
37
- requirement: *id001
38
- - !ruby/object:Gem::Dependency
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
39
22
  type: :runtime
40
23
  prerelease: false
41
- version_requirements: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2158419480
25
+ - !ruby/object:Gem::Dependency
26
+ name: haml
27
+ requirement: &2158418760 !ruby/object:Gem::Requirement
42
28
  none: false
43
- requirements:
29
+ requirements:
44
30
  - - ~>
45
- - !ruby/object:Gem::Version
46
- hash: 7
47
- segments:
48
- - 3
49
- - 0
50
- version: "3.0"
51
- name: haml
52
- requirement: *id002
53
- - !ruby/object:Gem::Dependency
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
54
33
  type: :runtime
55
34
  prerelease: false
56
- version_requirements: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *2158418760
36
+ - !ruby/object:Gem::Dependency
37
+ name: sinatra
38
+ requirement: &2158418300 !ruby/object:Gem::Requirement
57
39
  none: false
58
- requirements:
40
+ requirements:
59
41
  - - ~>
60
- - !ruby/object:Gem::Version
61
- hash: 9
62
- segments:
63
- - 1
64
- - 3
65
- version: "1.3"
66
- name: sinatra
67
- requirement: *id003
68
- - !ruby/object:Gem::Dependency
42
+ - !ruby/object:Gem::Version
43
+ version: '1.3'
69
44
  type: :runtime
70
45
  prerelease: false
71
- version_requirements: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *2158418300
47
+ - !ruby/object:Gem::Dependency
48
+ name: sinatra-content-for2
49
+ requirement: &2158417420 !ruby/object:Gem::Requirement
72
50
  none: false
73
- requirements:
51
+ requirements:
74
52
  - - ~>
75
- - !ruby/object:Gem::Version
76
- hash: 31
77
- segments:
78
- - 0
79
- - 2
80
- - 4
53
+ - !ruby/object:Gem::Version
81
54
  version: 0.2.4
82
- name: sinatra-content-for2
83
- requirement: *id004
84
- - !ruby/object:Gem::Dependency
85
55
  type: :runtime
86
56
  prerelease: false
87
- version_requirements: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *2158417420
58
+ - !ruby/object:Gem::Dependency
59
+ name: i18n
60
+ requirement: &2158416360 !ruby/object:Gem::Requirement
88
61
  none: false
89
- requirements:
62
+ requirements:
90
63
  - - ~>
91
- - !ruby/object:Gem::Version
92
- hash: 1
93
- segments:
94
- - 0
95
- - 5
96
- version: "0.5"
97
- name: i18n
98
- requirement: *id005
99
- - !ruby/object:Gem::Dependency
64
+ - !ruby/object:Gem::Version
65
+ version: '0.5'
100
66
  type: :runtime
101
67
  prerelease: false
102
- version_requirements: &id006 !ruby/object:Gem::Requirement
68
+ version_requirements: *2158416360
69
+ - !ruby/object:Gem::Dependency
70
+ name: file-tail
71
+ requirement: &2158414440 !ruby/object:Gem::Requirement
103
72
  none: false
104
- requirements:
73
+ requirements:
105
74
  - - ~>
106
- - !ruby/object:Gem::Version
107
- hash: 25
108
- segments:
109
- - 1
110
- - 0
111
- - 7
75
+ - !ruby/object:Gem::Version
112
76
  version: 1.0.7
113
- name: file-tail
114
- requirement: *id006
115
- - !ruby/object:Gem::Dependency
116
- type: :development
77
+ type: :runtime
117
78
  prerelease: false
118
- version_requirements: &id007 !ruby/object:Gem::Requirement
79
+ version_requirements: *2158414440
80
+ - !ruby/object:Gem::Dependency
81
+ name: rake
82
+ requirement: &2158413020 !ruby/object:Gem::Requirement
119
83
  none: false
120
- requirements:
84
+ requirements:
121
85
  - - ~>
122
- - !ruby/object:Gem::Version
123
- hash: 27
124
- segments:
125
- - 0
126
- - 8
127
- version: "0.8"
128
- - - "!="
129
- - !ruby/object:Gem::Version
130
- hash: 59
131
- segments:
132
- - 0
133
- - 9
134
- - 0
86
+ - !ruby/object:Gem::Version
87
+ version: '0.8'
88
+ - - ! '!='
89
+ - !ruby/object:Gem::Version
135
90
  version: 0.9.0
136
- name: rake
137
- requirement: *id007
138
- - !ruby/object:Gem::Dependency
139
91
  type: :development
140
92
  prerelease: false
141
- version_requirements: &id008 !ruby/object:Gem::Requirement
142
- none: false
143
- requirements:
144
- - - ">="
145
- - !ruby/object:Gem::Version
146
- hash: 3
147
- segments:
148
- - 0
149
- version: "0"
93
+ version_requirements: *2158413020
94
+ - !ruby/object:Gem::Dependency
150
95
  name: rspec-core
151
- requirement: *id008
152
- - !ruby/object:Gem::Dependency
96
+ requirement: &2158412020 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
153
102
  type: :development
154
103
  prerelease: false
155
- version_requirements: &id009 !ruby/object:Gem::Requirement
156
- none: false
157
- requirements:
158
- - - ">="
159
- - !ruby/object:Gem::Version
160
- hash: 3
161
- segments:
162
- - 0
163
- version: "0"
104
+ version_requirements: *2158412020
105
+ - !ruby/object:Gem::Dependency
164
106
  name: rspec-expectations
165
- requirement: *id009
166
- - !ruby/object:Gem::Dependency
107
+ requirement: &2158410660 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
167
113
  type: :development
168
114
  prerelease: false
169
- version_requirements: &id010 !ruby/object:Gem::Requirement
170
- none: false
171
- requirements:
172
- - - ">="
173
- - !ruby/object:Gem::Version
174
- hash: 3
175
- segments:
176
- - 0
177
- version: "0"
115
+ version_requirements: *2158410660
116
+ - !ruby/object:Gem::Dependency
178
117
  name: rr
179
- requirement: *id010
180
- - !ruby/object:Gem::Dependency
118
+ requirement: &2158410240 !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
181
124
  type: :development
182
125
  prerelease: false
183
- version_requirements: &id011 !ruby/object:Gem::Requirement
184
- none: false
185
- requirements:
186
- - - ">="
187
- - !ruby/object:Gem::Version
188
- hash: 3
189
- segments:
190
- - 0
191
- version: "0"
126
+ version_requirements: *2158410240
127
+ - !ruby/object:Gem::Dependency
192
128
  name: rack-test
193
- requirement: *id011
194
- - !ruby/object:Gem::Dependency
129
+ requirement: &2158409720 !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
195
135
  type: :development
196
136
  prerelease: false
197
- version_requirements: &id012 !ruby/object:Gem::Requirement
137
+ version_requirements: *2158409720
138
+ - !ruby/object:Gem::Dependency
139
+ name: bundler
140
+ requirement: &2158408740 !ruby/object:Gem::Requirement
198
141
  none: false
199
- requirements:
142
+ requirements:
200
143
  - - ~>
201
- - !ruby/object:Gem::Version
202
- hash: 15
203
- segments:
204
- - 1
205
- - 0
206
- version: "1.0"
207
- - - ">"
208
- - !ruby/object:Gem::Version
209
- hash: 3
210
- segments:
211
- - 1
212
- - 0
213
- - 10
144
+ - !ruby/object:Gem::Version
145
+ version: '1.0'
146
+ - - ! '>'
147
+ - !ruby/object:Gem::Version
214
148
  version: 1.0.10
215
- name: bundler
216
- requirement: *id012
217
- description: |
218
- Simple runit (http://smarden.org/runit/) web management tool with i18n.
219
-
149
+ type: :development
150
+ prerelease: false
151
+ version_requirements: *2158408740
152
+ description: ! 'Simple runit (http://smarden.org/runit/) web management tool with
153
+ i18n.
154
+
155
+
220
156
  Server will run by runit-man script.
221
-
157
+
158
+
222
159
  More information available at https://github.com/Undev/runit-man
223
160
 
161
+ '
224
162
  email: akzhan.abdulin@gmail.com
225
- executables:
163
+ executables:
226
164
  - runit-man
227
165
  extensions: []
228
-
229
- extra_rdoc_files:
166
+ extra_rdoc_files:
230
167
  - README.markdown
231
- files:
168
+ files:
232
169
  - .gitignore
233
170
  - .gitmodules
234
171
  - CHANGELOG.markdown
@@ -255,9 +192,6 @@ files:
255
192
  - lib/runit-man/app.rb
256
193
  - lib/runit-man/config.ru
257
194
  - lib/runit-man/helpers.rb
258
- - lib/runit-man/log_location_cache/base.rb
259
- - lib/runit-man/log_location_cache/logger.rb
260
- - lib/runit-man/log_location_cache/svlogd.rb
261
195
  - lib/runit-man/partials.rb
262
196
  - lib/runit-man/rainbows.conf
263
197
  - lib/runit-man/runner.rb
@@ -292,42 +226,34 @@ files:
292
226
  - views/log.haml
293
227
  - views/log_downloads.haml
294
228
  - views/view_file.haml
295
- has_rdoc: true
296
229
  homepage: https://github.com/Undev/runit-man
297
230
  licenses: []
298
-
299
231
  post_install_message:
300
232
  rdoc_options: []
301
-
302
- require_paths:
233
+ require_paths:
303
234
  - lib
304
- required_ruby_version: !ruby/object:Gem::Requirement
235
+ required_ruby_version: !ruby/object:Gem::Requirement
305
236
  none: false
306
- requirements:
307
- - - ">="
308
- - !ruby/object:Gem::Version
309
- hash: 3
310
- segments:
237
+ requirements:
238
+ - - ! '>='
239
+ - !ruby/object:Gem::Version
240
+ version: '0'
241
+ segments:
311
242
  - 0
312
- version: "0"
313
- required_rubygems_version: !ruby/object:Gem::Requirement
243
+ hash: -1381096489065286937
244
+ required_rubygems_version: !ruby/object:Gem::Requirement
314
245
  none: false
315
- requirements:
316
- - - ">"
317
- - !ruby/object:Gem::Version
318
- hash: 25
319
- segments:
320
- - 1
321
- - 3
322
- - 1
246
+ requirements:
247
+ - - ! '>'
248
+ - !ruby/object:Gem::Version
323
249
  version: 1.3.1
324
- requirements:
250
+ requirements:
325
251
  - none
326
252
  rubyforge_project:
327
- rubygems_version: 1.5.3
253
+ rubygems_version: 1.8.15
328
254
  signing_key:
329
255
  specification_version: 3
330
256
  summary: Runit web management tool.
331
- test_files:
257
+ test_files:
332
258
  - spec/functional/runit-man_spec.rb
333
259
  - spec/spec_helper.rb
@@ -1,110 +0,0 @@
1
- require 'monitor'
2
-
3
- module LogLocationCache; end
4
-
5
- class LogLocationCache::Base
6
- TIME_LIMIT = 600
7
-
8
- def initialize
9
- @monitor = Monitor.new
10
- clear
11
- end
12
-
13
- def [](pid)
14
- pid = pid.to_i
15
- loc = nil
16
-
17
- unless pids.include?(pid)
18
- loc = get_pid_location(pid)
19
- set_pid_log_location(pid, loc)
20
- end
21
-
22
- return loc unless loc.nil?
23
- return nil unless pids.include?(pid)
24
-
25
- pids[pid][:value]
26
- end
27
-
28
- protected
29
- attr_accessor :query_counter
30
- attr_accessor :pids
31
- attr_reader :monitor
32
-
33
- def not_implemented
34
- raise NotImplementedError.new
35
- end
36
-
37
- def get_pid_location(lpid)
38
- not_implemented
39
- end
40
-
41
- def clear
42
- monitor.synchronize do
43
- self.query_counter = 0
44
- self.pids = {}
45
- end
46
-
47
- self
48
- end
49
-
50
- def remove_old_values
51
- monitor.synchronize do
52
- self.query_counter = query_counter + 1
53
- if query_counter < 10
54
- return
55
- end
56
-
57
- self.query_counter = 0
58
- limit = Time.now - TIME_LIMIT
59
-
60
- pids.keys.each do |pid|
61
- if pids[pid][:time] < limit
62
- pids.delete(pid)
63
- end
64
- end
65
- end
66
-
67
- self
68
- end
69
-
70
- def log_command(lpid)
71
- return nil if lpid.nil?
72
-
73
- ps_output = `ps -o args -p #{lpid} 2>&1`.split("\n")
74
- return nil if ps_output.length < 2
75
-
76
- cmd = ps_output[1].chomp
77
- cmd != '' ? cmd : nil
78
- end
79
-
80
- def logger_name
81
- not_implemented
82
- end
83
-
84
- def log_command_args(lpid)
85
- cmd = log_command(lpid)
86
- return nil if cmd.nil?
87
-
88
- args = cmd.split(/\s+/).select { |arg| arg !~ /^\-/ }
89
- return nil if args.shift !~ /#{Regexp.escape(logger_name)}/
90
-
91
- args
92
- end
93
-
94
- def log_folder_base_name(lpid)
95
- args = log_command_args(lpid)
96
- return nil if args.nil?
97
-
98
- result = args.first
99
- result
100
- end
101
-
102
- def log_folder(lpid)
103
- not_implemented
104
- end
105
-
106
- def set_pid_log_location(pid, log_location)
107
- not_implemented
108
- end
109
- end
110
-
@@ -1,56 +0,0 @@
1
- require 'monitor'
2
-
3
- class LogLocationCache::Logger < LogLocationCache::Base
4
- def initialize(logger)
5
- super()
6
- @logger = logger
7
- end
8
-
9
- protected
10
- attr_reader :logger
11
-
12
- def get_pid_location(lpid)
13
- folder = log_folder(lpid)
14
- return nil if folder.nil?
15
-
16
- loc = File.join(folder, Time.now.strftime('%Y-%m-%d'), "#{log_folder_base_name(lpid)}.log")
17
- unless File.exists?(loc)
18
- loc = "#{loc}.gz"
19
- loc = nil unless File.exists?(loc)
20
- end
21
-
22
- loc
23
- end
24
-
25
- def logger_name
26
- (logger =~ /^([^\:]+)\:/) ? $1 : logger
27
- end
28
-
29
- def log_base_folder
30
- (logger =~ /^[^\:]+\:([^\:]+)/) ? $1 : nil
31
- end
32
-
33
- def log_folder(lpid)
34
- folder = log_folder_base_name(lpid)
35
- (log_base_folder.nil? || folder.nil?) ? folder : File.join(log_base_folder, folder)
36
- end
37
-
38
- def log_priority(lpid)
39
- args = log_command_args(lpid)
40
- args.nil? ? logger_priority : args.last
41
- end
42
-
43
- def set_pid_log_location(pid, log_location)
44
- remove_old_values
45
- end
46
-
47
- def log_folder_base_name(lpid)
48
- result = super(lpid)
49
-
50
- # we should remove : from the end of the line for logger installations.
51
- result = $1 if result =~ /^(.+)\:$/
52
-
53
- result
54
- end
55
- end
56
-
@@ -1,34 +0,0 @@
1
- require 'monitor'
2
-
3
- class LogLocationCache::Svlogd < LogLocationCache::Base
4
-
5
- protected
6
- def get_pid_location(lpid)
7
- folder = log_folder(lpid)
8
- return nil if folder.nil?
9
-
10
- File.join(folder, 'current')
11
- end
12
-
13
- def logger_name
14
- 'svlogd'
15
- end
16
-
17
- def log_folder(lpid)
18
- log_folder_base_name(lpid)
19
- end
20
-
21
- def set_pid_log_location(pid, log_location)
22
- remove_old_values
23
-
24
- monitor.synchronize do
25
- pids[pid.to_i] = {
26
- :value => log_location,
27
- :time => Time.now
28
- }
29
- end
30
-
31
- self
32
- end
33
- end
34
-