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
Instance Method Summary collapse
- #active? ⇒ Boolean
- #down! ⇒ 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 ⇒ Object
- #up! ⇒ Object
Constructor Details
#initialize(a_name) ⇒ ServiceInfo
Returns a new instance of ServiceInfo.
6 7 8 |
# File 'lib/runit-man/service_info.rb', line 6 def initialize(a_name) @name = a_name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/runit-man/service_info.rb', line 4 def name @name end |
Class Method Details
.[](name) ⇒ Object
119 120 121 |
# File 'lib/runit-man/service_info.rb', line 119 def [](name) all_service_names.include?(name) ? ServiceInfo.new(name) : nil end |
.all ⇒ Object
113 114 115 116 117 |
# File 'lib/runit-man/service_info.rb', line 113 def all all_service_names.sort.map do |name| ServiceInfo.new(name) end end |
.log_location_cache ⇒ Object
123 124 125 126 127 128 |
# File 'lib/runit-man/service_info.rb', line 123 def log_location_cache unless @log_location_cache @log_location_cache = LogLocationCache.new end @log_location_cache end |
Instance Method Details
#active? ⇒ Boolean
27 28 29 |
# File 'lib/runit-man/service_info.rb', line 27 def active? File.directory?(active_service_folder) || File.symlink?(active_service_folder) end |
#down! ⇒ Object
43 44 45 |
# File 'lib/runit-man/service_info.rb', line 43 def down! send_signal :d end |
#log_file_location ⇒ Object
69 70 71 72 73 |
# File 'lib/runit-man/service_info.rb', line 69 def log_file_location rel_path = self.class.log_location_cache[log_pid] return nil if rel_path.nil? File.(rel_path, log_run_folder) end |
#log_pid ⇒ Object
65 66 67 |
# File 'lib/runit-man/service_info.rb', line 65 def log_pid data_from_file(File.join(log_supervise_folder, 'pid')) end |
#logged? ⇒ Boolean
18 19 20 |
# File 'lib/runit-man/service_info.rb', line 18 def logged? File.directory?(log_supervise_folder) end |
#pid ⇒ Object
61 62 63 |
# File 'lib/runit-man/service_info.rb', line 61 def pid data_from_file(File.join(supervise_folder, 'pid')) end |
#restart! ⇒ Object
56 57 58 59 |
# File 'lib/runit-man/service_info.rb', line 56 def restart! down! up! end |
#run? ⇒ Boolean
35 36 37 |
# File 'lib/runit-man/service_info.rb', line 35 def run? !!(stat =~ /\brun\b/) end |
#send_signal(signal) ⇒ Object
75 76 77 78 |
# File 'lib/runit-man/service_info.rb', line 75 def send_signal(signal) return unless supervise? File.open(File.join(supervise_folder, 'control'), 'w') { |f| f.print signal.to_s } end |
#stat ⇒ Object
22 23 24 25 |
# File 'lib/runit-man/service_info.rb', line 22 def stat r = data_from_file(File.join(supervise_folder, 'stat')) r ? r : 'inactive' end |
#switch_down! ⇒ Object
47 48 49 50 |
# File 'lib/runit-man/service_info.rb', line 47 def switch_down! down! File.unlink(active_service_folder) end |
#switch_up! ⇒ Object
52 53 54 |
# File 'lib/runit-man/service_info.rb', line 52 def switch_up! File.symlink(inactive_service_folder, active_service_folder) end |
#switchable? ⇒ Boolean
31 32 33 |
# File 'lib/runit-man/service_info.rb', line 31 def switchable? File.symlink?(active_service_folder) || File.directory?(inactive_service_folder) end |
#to_json ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/runit-man/service_info.rb', line 10 def to_json data = {} [ :name, :stat, :active?, :logged?, :switchable?, :run?, :pid, :log_pid, :log_file_location ].each do |sym| data[sym] = send(sym) end data.to_json end |
#up! ⇒ Object
39 40 41 |
# File 'lib/runit-man/service_info.rb', line 39 def up! send_signal :u end |