Class: ServiceInfo
- Inherits:
-
Object
- Object
- ServiceInfo
- Defined in:
- lib/runit-man/service_info.rb
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
- .log_location_cache ⇒ Object
- .real_data_from_file(file_name) ⇒ Object
Instance Method Summary collapse
- #active? ⇒ Boolean
- #allowed_signals ⇒ Object
- #down! ⇒ Object
- #down? ⇒ Boolean
- #files_to_view ⇒ Object
-
#initialize(a_name) ⇒ ServiceInfo
constructor
A new instance of ServiceInfo.
- #log_file_location ⇒ Object
- #log_pid ⇒ Object
- #logged? ⇒ Boolean
- #pid ⇒ Object
- #restart! ⇒ Object
- #run? ⇒ Boolean
- #send_signal(signal) ⇒ Object
- #stat ⇒ Object
- #switch_down! ⇒ Object
- #switch_up! ⇒ Object
- #switchable? ⇒ Boolean
- #to_json(*a) ⇒ Object
- #up! ⇒ Object
- #uptime ⇒ Object
- #urls_to_view ⇒ Object
Constructor Details
#initialize(a_name) ⇒ ServiceInfo
Returns a new instance of ServiceInfo.
7 8 9 10 11 12 13 |
# File 'lib/runit-man/service_info.rb', line 7 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.
5 6 7 |
# File 'lib/runit-man/service_info.rb', line 5 def name @name end |
Class Method Details
.[](name) ⇒ Object
186 187 188 |
# File 'lib/runit-man/service_info.rb', line 186 def [](name) all_service_names.include?(name) ? ServiceInfo.new(name) : nil end |
.all ⇒ Object
180 181 182 183 184 |
# File 'lib/runit-man/service_info.rb', line 180 def all all_service_names.sort.map do |name| ServiceInfo.new(name) end end |
.itself_or_parent?(name) ⇒ Boolean
204 205 206 |
# File 'lib/runit-man/service_info.rb', line 204 def itself_or_parent?(name) name == '.' || name == '..' end |
.log_location_cache ⇒ Object
190 191 192 193 194 195 |
# File 'lib/runit-man/service_info.rb', line 190 def log_location_cache unless @log_location_cache @log_location_cache = LogLocationCache.new end @log_location_cache end |
.real_data_from_file(file_name) ⇒ Object
197 198 199 200 201 202 |
# File 'lib/runit-man/service_info.rb', line 197 def real_data_from_file(file_name) return nil unless File.readable?(file_name) data = IO.read(file_name) data.chomp! unless data.nil? data.empty? ? nil : data end |
Instance Method Details
#active? ⇒ Boolean
42 43 44 |
# File 'lib/runit-man/service_info.rb', line 42 def active? File.directory?(active_service_folder) || File.symlink?(active_service_folder) end |
#allowed_signals ⇒ Object
130 131 132 133 134 135 |
# File 'lib/runit-man/service_info.rb', line 130 def allowed_signals return [] unless File.directory?(allowed_signals_folder) Dir.entries(allowed_signals_folder).reject do |name| ServiceInfo.itself_or_parent?(name) end end |
#down! ⇒ Object
62 63 64 |
# File 'lib/runit-man/service_info.rb', line 62 def down! send_signal :d end |
#down? ⇒ Boolean
50 51 52 |
# File 'lib/runit-man/service_info.rb', line 50 def down? @status.down? end |
#files_to_view ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/runit-man/service_info.rb', line 105 def files_to_view return [] unless File.directory?(files_to_view_folder) Dir.entries(files_to_view_folder).select do |name| File.symlink?(File.join(files_to_view_folder, name)) end.map do |name| File.( File.readlink(File.join(files_to_view_folder, name)), files_to_view_folder ) end.select do |file_path| File.file?(file_path) end end |
#log_file_location ⇒ Object
92 93 94 95 96 |
# File 'lib/runit-man/service_info.rb', line 92 def log_file_location rel_path = ServiceInfo.log_location_cache[log_pid] return nil if rel_path.nil? File.(rel_path, log_run_folder) end |
#log_pid ⇒ Object
88 89 90 |
# File 'lib/runit-man/service_info.rb', line 88 def log_pid @log_status.pid end |
#logged? ⇒ Boolean
34 35 36 |
# File 'lib/runit-man/service_info.rb', line 34 def logged? File.directory?(log_supervise_folder) end |
#pid ⇒ Object
80 81 82 |
# File 'lib/runit-man/service_info.rb', line 80 def pid @status.pid end |
#restart! ⇒ Object
75 76 77 78 |
# File 'lib/runit-man/service_info.rb', line 75 def restart! down! up! end |
#run? ⇒ Boolean
54 55 56 |
# File 'lib/runit-man/service_info.rb', line 54 def run? @status.run? end |
#send_signal(signal) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/runit-man/service_info.rb', line 98 def send_signal(signal) return unless supervise? File.open(File.join(supervise_folder, 'control'), 'w') do |f| f.print signal.to_s end end |
#stat ⇒ Object
38 39 40 |
# File 'lib/runit-man/service_info.rb', line 38 def stat @status.to_s end |
#switch_down! ⇒ Object
66 67 68 69 |
# File 'lib/runit-man/service_info.rb', line 66 def switch_down! down! File.unlink(active_service_folder) end |
#switch_up! ⇒ Object
71 72 73 |
# File 'lib/runit-man/service_info.rb', line 71 def switch_up! File.symlink(inactive_service_folder, active_service_folder) end |
#switchable? ⇒ Boolean
46 47 48 |
# File 'lib/runit-man/service_info.rb', line 46 def switchable? File.symlink?(active_service_folder) || File.directory?(inactive_service_folder) end |
#to_json(*a) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/runit-man/service_info.rb', line 15 def to_json(*a) data = {} [ :name, :stat, :active?, :logged?, :switchable?, :log_file_location, :log_pid ].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.to_json(*a) end |
#up! ⇒ Object
58 59 60 |
# File 'lib/runit-man/service_info.rb', line 58 def up! send_signal :u end |
#uptime ⇒ Object
84 85 86 |
# File 'lib/runit-man/service_info.rb', line 84 def uptime @status.uptime end |
#urls_to_view ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/runit-man/service_info.rb', line 119 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 |