| Class | Dsadmin::Admind::ApacheInstance |
| In: |
lib/dsadmin/admind/apache_instance.rb
|
| Parent: | Object |
Abstraction for one apache instance.
See resources/apache/ in the configfile.
| apacheid | [R] | |
| dnstarget | [R] | |
| on_hosts | [R] | |
| vhost_cfgfiles | [R] |
Get the Apache instance with key config_key .
Previously accessed instance objects are cached.
| Throws: | ArgumentError if the specified apache instance does not exist |
| Throws: | Dsadmin::BadConfigurationError if the configfile for the apache instance contains errors |
# File lib/dsadmin/admind/apache_instance.rb, line 87
87: def self.[](config_key)
88: key = config_key.to_s # convenience alias
89:
90: unless(@@instances.has_key?(key))
91: begin
92: @@instances[key] = ApacheInstance.new(key)
93: rescue ArgumentError => xcept
94: Dsadmin::Logger.instance.error(xcept)
95: raise
96: end
97: end
98:
99: return @@instances[key]
100: end
# File lib/dsadmin/admind/apache_instance.rb, line 106
106: def initialize(config_key)
107: @apacheid = config_key
108:
109: @csect = cfg.get("resources/apache[#{@apacheid}]", Dsadmin::ConfigSection, false)
110: checkNotNil(@csect, "Apache instance '#{@apacheid}' does not exist in the configfile")
111: @on_hosts = @csect.get('on_hosts', String).split(/\s*,\s*/)
112:
113: dnstarget_name = @csect.get("dnstarget", String)
114: @dnstarget = DnsTarget.find_by_name(dnstarget_name) or raise Dsadmin::BadConfigurationError.new("DNS target '#{dnstarget_name}' (used by apache instance '#{@apacheid}') does not exist")
115:
116: @reload_command = Dsadmin::SystemCommand.new(@csect.get("reload_command"))
117: @vhost_cfgfiles = Dsadmin::SystemPath.new(@csect.get("vhost_cfgfiles"))
118:
119: @reload_mutex = Mutex.new
120: @queued_reload_mutex = Mutex.new
121:
122: rescue ::Test::Unit::AssertionFailedError => xcept # FIXME: Needed at all?
123: log.bug(xcept)
124: xcept2 = ArgumentError.new(xcept.message)
125: xcept2.set_backtrace(xcept.backtrace)
126: raise xcept2
127: end
Get the IP the instance is (officially) listening on. For VHost config building etc.
# File lib/dsadmin/admind/apache_instance.rb, line 48
48: def ip
49: dnstarget.ipv4
50: end
Reload the apache instance.
Threadsafe. Waits for the reload command to finish before returning.
| Returns: | true/false indicating whether the reload was successful |
# File lib/dsadmin/admind/apache_instance.rb, line 58
58: def reload
59: # We use @queued_reload_mutex to allow at most one more reload to
60: # be queued once a reload is underway. This allows for safe yet
61: # more or less efficient handling of cases where the apache
62: # configuration is changed by another thread while a reload triggered
63: # by a previous change is already underway.
64: @queued_reload_mutex.try_lock or return true
65:
66: @reload_mutex.synchronize {
67: @queued_reload_mutex.unlock
68:
69: res = @reload_command.exec1
70: unless(res.success?)
71: log.error("Reloading of apache instance '#{apacheid}' failed")
72: return false
73: end
74: }
75:
76: return true
77: end