Class: ServiceInfo::Base
- Inherits:
-
Object
- Object
- ServiceInfo::Base
- Defined in:
- lib/runit-man/service_info/base.rb
Overview
Represents information about service on any host.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .[](name) ⇒ Object
- .all ⇒ Object
- .itself_or_parent?(name) ⇒ Boolean
- .real_data_from_file(file_name) ⇒ Object
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#all_log_file_locations ⇒ Object
All log file locations.
- #allowed_signals ⇒ Object
- #down! ⇒ Object
- #down? ⇒ Boolean
- #files_to_view ⇒ Object
- #files_to_watch ⇒ Object
-
#initialize(a_name) ⇒ Base
constructor
A new instance of Base.
-
#log_file_locations ⇒ Object
Current log file locations.
- #log_pid ⇒ Object
- #logged? ⇒ Boolean
- #pid ⇒ Object
- #restart! ⇒ Object
- #run? ⇒ Boolean
- #send_signal(signal) ⇒ Object
- #started_at ⇒ Object
- #stat ⇒ Object
- #switch_down! ⇒ Object
- #switch_up! ⇒ Object
- #switchable? ⇒ Boolean
- #symlinks_to_file_paths(dir_path) ⇒ Object
- #to_hash ⇒ Object
- #to_json(*args) ⇒ Object
- #up! ⇒ Object
- #uptime ⇒ Object
- #urls_to_view ⇒ Object
- #watched_modified_files ⇒ Object
Constructor Details
#initialize(a_name) ⇒ Base
Returns a new instance of Base.
9 10 11 12 13 14 15 |
# File 'lib/runit-man/service_info/base.rb', line 9 def initialize(a_name) @name = a_name @files = {} @status = ServiceStatus.new(data_from_file(File.join(supervise_folder, 'status'))) @log_status = ServiceStatus.new(data_from_file(File.join(log_supervise_folder, 'status'))) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/runit-man/service_info/base.rb', line 7 def name @name end |
Class Method Details
.[](name) ⇒ Object
263 264 265 |
# File 'lib/runit-man/service_info/base.rb', line 263 def [](name) all_service_names.include?(name) ? ServiceInfo.klass.new(name) : nil end |
.all ⇒ Object
257 258 259 260 261 |
# File 'lib/runit-man/service_info/base.rb', line 257 def all all_service_names.sort.map do |name| ServiceInfo.klass.new(name) end end |
.itself_or_parent?(name) ⇒ Boolean
280 281 282 |
# File 'lib/runit-man/service_info/base.rb', line 280 def itself_or_parent?(name) name == '.' || name == '..' end |
.real_data_from_file(file_name) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/runit-man/service_info/base.rb', line 267 def real_data_from_file(file_name) return nil unless File.readable?(file_name) if RUBY_VERSION >= '1.9' data = IO.read(file_name, :external_encoding => 'ASCII-8BIT') else data = IO.read(file_name) end data.chomp! unless data.nil? data.empty? ? nil : data end |
Instance Method Details
#active? ⇒ Boolean
48 49 50 |
# File 'lib/runit-man/service_info/base.rb', line 48 def active? File.directory?(active_service_folder) || File.symlink?(active_service_folder) end |
#all_log_file_locations ⇒ Object
All log file locations
108 109 110 |
# File 'lib/runit-man/service_info/base.rb', line 108 def all_log_file_locations [] end |
#allowed_signals ⇒ Object
164 165 166 167 168 169 170 |
# File 'lib/runit-man/service_info/base.rb', line 164 def allowed_signals return [] unless File.directory?(allowed_signals_folder) Dir.entries(allowed_signals_folder).reject do |name| ServiceInfo::Base.itself_or_parent?(name) end end |
#down! ⇒ Object
68 69 70 |
# File 'lib/runit-man/service_info/base.rb', line 68 def down! send_signal :d end |
#down? ⇒ Boolean
56 57 58 |
# File 'lib/runit-man/service_info/base.rb', line 56 def down? @status.down? end |
#files_to_view ⇒ Object
144 145 146 |
# File 'lib/runit-man/service_info/base.rb', line 144 def files_to_view symlinks_to_file_paths(files_to_view_folder) end |
#files_to_watch ⇒ Object
148 149 150 |
# File 'lib/runit-man/service_info/base.rb', line 148 def files_to_watch symlinks_to_file_paths(files_to_watch_folder) end |
#log_file_locations ⇒ Object
Current log file locations
103 104 105 |
# File 'lib/runit-man/service_info/base.rb', line 103 def log_file_locations [] end |
#log_pid ⇒ Object
98 99 100 |
# File 'lib/runit-man/service_info/base.rb', line 98 def log_pid @log_status.pid end |
#logged? ⇒ Boolean
40 41 42 |
# File 'lib/runit-man/service_info/base.rb', line 40 def logged? File.directory?(log_supervise_folder) end |
#pid ⇒ Object
90 91 92 |
# File 'lib/runit-man/service_info/base.rb', line 90 def pid @status.pid end |
#restart! ⇒ Object
81 82 83 84 |
# File 'lib/runit-man/service_info/base.rb', line 81 def restart! down! up! end |
#run? ⇒ Boolean
60 61 62 |
# File 'lib/runit-man/service_info/base.rb', line 60 def run? @status.run? end |
#send_signal(signal) ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/runit-man/service_info/base.rb', line 121 def send_signal(signal) return unless supervise? File.open(File.join(supervise_folder, 'control'), 'w') do |f| f.print signal.to_s end end |
#started_at ⇒ Object
86 87 88 |
# File 'lib/runit-man/service_info/base.rb', line 86 def started_at @status.started_at end |
#stat ⇒ Object
44 45 46 |
# File 'lib/runit-man/service_info/base.rb', line 44 def stat @status.to_s end |
#switch_down! ⇒ Object
72 73 74 75 |
# File 'lib/runit-man/service_info/base.rb', line 72 def switch_down! down! File.unlink(active_service_folder) end |
#switch_up! ⇒ Object
77 78 79 |
# File 'lib/runit-man/service_info/base.rb', line 77 def switch_up! File.symlink(inactive_service_folder, active_service_folder) end |
#switchable? ⇒ Boolean
52 53 54 |
# File 'lib/runit-man/service_info/base.rb', line 52 def switchable? File.symlink?(active_service_folder) || File.directory?(inactive_service_folder) end |
#symlinks_to_file_paths(dir_path) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/runit-man/service_info/base.rb', line 129 def symlinks_to_file_paths(dir_path) return [] unless File.directory?(dir_path) Dir.entries(dir_path).select do |name| File.symlink?(File.join(dir_path, name)) end.map do |name| File.( File.readlink(File.join(dir_path, name)), dir_path ) end.select do |file_path| File.file?(file_path) end end |
#to_hash ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/runit-man/service_info/base.rb', line 17 def to_hash data = {} [ :name, :stat, :active?, :logged?, :switchable?, :log_file_locations, :log_pid, :watched_modified_files ].each do |sym| data[sym] = send(sym) end [ :run?, :pid, :finish?, :down?, :want_up?, :want_down?, :got_term?, :started_at, :uptime ].each do |sym| data[sym] = @status.send(sym) end data end |
#to_json(*args) ⇒ Object
36 37 38 |
# File 'lib/runit-man/service_info/base.rb', line 36 def to_json(*args) Yajl::Encoder.encode(to_hash, *args) end |
#up! ⇒ Object
64 65 66 |
# File 'lib/runit-man/service_info/base.rb', line 64 def up! send_signal :u end |
#uptime ⇒ Object
94 95 96 |
# File 'lib/runit-man/service_info/base.rb', line 94 def uptime @status.uptime end |
#urls_to_view ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/runit-man/service_info/base.rb', line 152 def urls_to_view return [] unless File.directory?(urls_to_view_folder) Dir.entries(urls_to_view_folder).select do |name| name =~ /\.url$/ && File.file?(File.join(urls_to_view_folder, name)) end.map do |name| data_from_file(File.join(urls_to_view_folder, name)) end.select do |url| !url.nil? end end |
#watched_modified_files ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/runit-man/service_info/base.rb', line 112 def watched_modified_files files_to_watch.map do |filepath| mtime = File.stat(filepath).mtime.utc { :path => filepath, :mtime => mtime } end.select do |rec| rec[:mtime] > @status.started_at end end |