Class: Freyr::ServiceInfo
- Inherits:
-
Object
- Object
- Freyr::ServiceInfo
- Includes:
- Base
- Defined in:
- lib/freyr/service_info.rb
Defined Under Namespace
Modules: Base
Constant Summary collapse
- ROOT_PIDS =
'/var/run/freyr'.freeze
- USER_PIDS =
File.('.freyr', '~').freeze
- ROOT_LOGS =
'/var/log/freyr'.freeze
- USER_LOGS =
USER_PIDS
- MODIFIERS =
Hash.new {|h,k| h[k] = []}
- ATTRS =
[]
- SUDO_MATCHER =
/^sudo\s+/
Instance Attribute Summary collapse
-
#defined_in ⇒ Object
readonly
Returns the value of attribute defined_in.
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
Class Method Summary collapse
Instance Method Summary collapse
- #also_as(*val) ⇒ Object
- #dir(val = nil) ⇒ Object
- #env(val = nil) ⇒ Object
- #group(*val) ⇒ Object
-
#initialize(name = nil, args = {}, &block) ⇒ ServiceInfo
constructor
A new instance of ServiceInfo.
- #log(val = nil) ⇒ Object
- #log_file ⇒ Object
- #pid_file(val = nil) ⇒ Object
- #read_log(val = nil) ⇒ Object
- #requires(*val) ⇒ Object
- #use_sudo ⇒ Object
Methods included from Base
Constructor Details
#initialize(name = nil, args = {}, &block) ⇒ ServiceInfo
Returns a new instance of ServiceInfo.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/freyr/service_info.rb', line 69 def initialize(name=nil, args={}, &block) @groups = [] @also = [] @dependencies = [] @defined_in = [] if name.is_a?(Hash) @name = name.keys.first @groups << name[@name] else @name = name end @service = Service.new(self) instance_eval(&block) if block_given? end |
Instance Attribute Details
#defined_in ⇒ Object (readonly)
Returns the value of attribute defined_in.
63 64 65 |
# File 'lib/freyr/service_info.rb', line 63 def defined_in @defined_in end |
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
3 4 5 |
# File 'lib/freyr/service_info.rb', line 3 def groups @groups end |
Class Method Details
.from_file(file) ⇒ Object
183 184 185 186 187 188 189 190 191 192 |
# File 'lib/freyr/service_info.rb', line 183 def from_file file @file_path = file file = File.(file) Freyr.logger.debug("adding file") {file} return [] unless File.exist?(file) @added_services = [] @namespace = nil instance_eval(File.open(file).read,file,0) @added_services end |
.method_missing(name, *args, &blk) ⇒ Object
194 195 196 |
# File 'lib/freyr/service_info.rb', line 194 def method_missing name, *args, &blk STDERR.puts "Freyr doesn't support #{name} as used in #{@file_path}" end |
Instance Method Details
#also_as(*val) ⇒ Object
158 159 160 161 162 163 164 |
# File 'lib/freyr/service_info.rb', line 158 def also_as(*val) val.each do |aliaz| Service.by_selector[aliaz] = Service.by_selector[name] Service.by_name[aliaz] = Service.by_name[name] end @also |= val end |
#dir(val = nil) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/freyr/service_info.rb', line 134 def dir val=nil if val val.sub! /(.)\/$/, '\1' # remove tailing slash Service.by_dir[val] = @service end if val = super val else '/' end end |
#env(val = nil) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/freyr/service_info.rb', line 90 def env val=nil raise TypeError, 'environment must be a hash' unless val.is_a?(Hash) || val.nil? if val = super val else {} end end |
#group(*val) ⇒ Object
147 148 149 150 151 152 |
# File 'lib/freyr/service_info.rb', line 147 def group(*val) val.each do |group| Service.by_selector[group] << @service end @groups |= val end |
#log(val = nil) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/freyr/service_info.rb', line 116 def log val=nil val = if val = super val else if @read_log @read_log else if @sudo File.join(ROOT_LOGS,"#{@name}.log") else File.join(USER_LOGS,"#{@name}.log") end end end val =~ /^\// ? val : File.join(dir,val) end |
#log_file ⇒ Object
68 |
# File 'lib/freyr/service_info.rb', line 68 alias log_file log |
#pid_file(val = nil) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/freyr/service_info.rb', line 99 def pid_file val=nil if val = super val else if @sudo File.join(ROOT_PIDS,"#{@name}.pid") else File.join(USER_PIDS,"#{@name}.pid") end end end |
#read_log(val = nil) ⇒ Object
111 112 113 114 |
# File 'lib/freyr/service_info.rb', line 111 def read_log val=nil @dont_write_log = true super end |
#requires(*val) ⇒ Object
154 155 156 |
# File 'lib/freyr/service_info.rb', line 154 def requires *val @dependencies |= val end |
#use_sudo ⇒ Object
86 87 88 |
# File 'lib/freyr/service_info.rb', line 86 def use_sudo @sudo = true end |