Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(271)

Side by Side Diff: hooks/backend.py

Issue 8640044: Apache support
Patch Set: Created 11 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 ## These normally depend on python packages being installed 1 ## These normally depend on python packages being installed
2 ## from hooks/install. If we are unable to use external code 2 ## from hooks/install. If we are unable to use external code
3 ## due to some deployment restrictions these deps will already 3 ## due to some deployment restrictions these deps will already
4 ## have been installed or this code will fail. 4 ## have been installed or this code will fail.
5 from charmhelpers import ( 5 from charmhelpers import (
6 log, 6 log,
7 open_port, 7 open_port,
8 service_control, 8 service_control,
9 RESTART, 9 RESTART,
10 STOP, 10 STOP,
11 ) 11 )
12 from shelltoolbox import ( 12 from shelltoolbox import (
13 apt_get_install, 13 apt_get_install,
14 command, 14 command,
15 install_extra_repositories, 15 install_extra_repositories,
16 su, 16 su,
17 ) 17 )
18 18
19 from utils import ( 19 from utils import (
20 AGENT, 20 AGENT,
21 APACHE,
21 HAPROXY, 22 HAPROXY,
22 IMPROV, 23 IMPROV,
23 JUJU_DIR, 24 JUJU_DIR,
24 NGINX,
25 chain, 25 chain,
26 check_packages, 26 check_packages,
27 cmd_log, 27 cmd_log,
28 fetch_api, 28 fetch_api,
29 fetch_gui, 29 fetch_gui,
30 get_config, 30 get_config,
31 legacy_juju, 31 legacy_juju,
32 merge, 32 merge,
33 overrideable, 33 overrideable,
34 save_or_create_certificates, 34 save_or_create_certificates,
35 setup_gui, 35 setup_gui,
36 setup_nginx, 36 setup_apache,
37 start_agent, 37 start_agent,
38 start_gui, 38 start_gui,
39 start_improv, 39 start_improv,
40 ) 40 )
41 41
42 import os 42 import os
43 import shutil 43 import shutil
44 44
45 45
46 apt_get = command('apt-get') 46 apt_get = command('apt-get')
47 47
48 class InstallMixin(object): 48 class InstallMixin(object):
49 def install(self, backend): 49 def install(self, backend):
50 config = backend.config 50 config = backend.config
51 missing = backend.check_packages(*backend.debs) 51 missing = backend.check_packages(*backend.debs)
52 if missing: 52 if missing:
53 cmd_log(backend.install_extra_repositories(*backend.repositories)) 53 cmd_log(backend.install_extra_repositories(*backend.repositories))
54 cmd_log(apt_get_install(*backend.debs)) 54 cmd_log(apt_get_install(*backend.debs))
55 55
56 if backend.different('juju-gui-source'): 56 if backend.different('juju-gui-source'):
57 release_tarball = fetch_gui( 57 release_tarball = fetch_gui(
58 config['juju-gui-source'], config['command-log-file']) 58 config['juju-gui-source'], config['command-log-file'])
59 setup_gui(release_tarball) 59 setup_gui(release_tarball)
60 60
61 class UpstartMixin(object): 61 class UpstartMixin(object):
62 upstart_scripts = ('haproxy.conf', 'nginx.conf') 62 upstart_scripts = ('haproxy.conf', )
63 debs = ('curl', 'openssl', 'nginx', 'haproxy') 63 debs = ('curl', 'openssl', 'haproxy', 'apache2')
64 64
65 def install(self, backend): 65 def install(self, backend):
66 """Set up haproxy and nginx upstart configuration files.""" 66 """Set up haproxy and nginx upstart configuration files."""
67 setup_apache()
67 backend.log('Setting up haproxy and nginx start up scripts.') 68 backend.log('Setting up haproxy and nginx start up scripts.')
68 config = backend.config 69 config = backend.config
69 setup_nginx()
70 if backend.different('ssl-cert-path', 'ssl-cert-contents', 'ssl-key-cont ents'): 70 if backend.different('ssl-cert-path', 'ssl-cert-contents', 'ssl-key-cont ents'):
71 save_or_create_certificates( 71 save_or_create_certificates(
72 config['ssl-cert-path'], config.get('ssl-cert-contents'), 72 config['ssl-cert-path'], config.get('ssl-cert-contents'),
73 config.get('ssl-key-contents')) 73 config.get('ssl-key-contents'))
74 74
75 source_dir = os.path.join(os.path.dirname(__file__), '..', 'config') 75 source_dir = os.path.join(os.path.dirname(__file__), '..', 'config')
76 for config_file in backend.upstart_scripts: 76 for config_file in backend.upstart_scripts:
77 shutil.copy(os.path.join(source_dir, config_file), '/etc/init/') 77 shutil.copy(os.path.join(source_dir, config_file), '/etc/init/')
78 78
79 def start(self, backend): 79 def start(self, backend):
80 with su('root'): 80 with su('root'):
81 backend.service_control(NGINX, RESTART) 81 backend.service_control(APACHE, RESTART)
82 backend.service_control(HAPROXY, RESTART) 82 backend.service_control(HAPROXY, RESTART)
83 83
84 def stop(self, backend): 84 def stop(self, backend):
85 with su('root'): 85 with su('root'):
86 backend.service_control(HAPROXY, STOP) 86 backend.service_control(HAPROXY, STOP)
87 backend.service_control(NGINX, STOP) 87 backend.service_control(APACHE, STOP)
88 88
89 89
90 class GuiMixin(object): 90 class GuiMixin(object):
91 gui_properties = set([ 91 gui_properties = set([
92 'juju-gui-console-enabled', 'login-help', 'read-only', 92 'juju-gui-console-enabled', 'login-help', 'read-only',
93 'serve-tests', 'secure']) 93 'serve-tests', 'secure'])
94 94
95 repositories = ('ppa:juju-gui/ppa',) 95 repositories = ('ppa:juju-gui/ppa',)
96 96
97 def start(self, config): 97 def start(self, config):
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 to use together to implement the backend proper.""" 150 to use together to implement the backend proper."""
151 # Ingest the config and build out the ordered list of 151 # Ingest the config and build out the ordered list of
152 # backend elements to include 152 # backend elements to include
153 if config is None: 153 if config is None:
154 config = get_config() 154 config = get_config()
155 self.config = config 155 self.config = config
156 self.prev_config = prev_config 156 self.prev_config = prev_config
157 self.overrides = overrides 157 self.overrides = overrides
158 158
159 # We always use upstart. 159 # We always use upstart.
160 backends = [InstallMixin, UpstartMixin] 160 backends = [InstallMixin, ]
161 161
162 api = "python" if legacy_juju() else "go" 162 api = "python" if legacy_juju() else "go"
163 sandbox = config.get('sandbox', False) 163 sandbox = config.get('sandbox', False)
164 staging = config.get('staging', False) 164 staging = config.get('staging', False)
165 165
166 if api == 'python': 166 if api == 'python':
167 if staging: 167 if staging:
168 backends.append(ImprovBackend) 168 backends.append(ImprovBackend)
169 elif sandbox: 169 elif sandbox:
170 backends.append(SandboxBackend) 170 backends.append(SandboxBackend)
171 else: 171 else:
172 backends.append(PythonBackend) 172 backends.append(PythonBackend)
173 else: 173 else:
174 if staging: 174 if staging:
175 raise ValueError( 175 raise ValueError(
176 "Unable to use staging with {} backend".format(api)) 176 "Unable to use staging with {} backend".format(api))
177 if sandbox: 177 if sandbox:
178 raise ValueError( 178 raise ValueError(
179 "Unable to use sandbox with {} backend".format(api)) 179 "Unable to use sandbox with {} backend".format(api))
180 backends.append(GoBackend) 180 backends.append(GoBackend)
181 181
182 # All backends can manage the gui. 182 # All backends can manage the gui.
183 backends.append(GuiMixin) 183 backends.append(GuiMixin)
184 backends.append(UpstartMixin)
teknico 2013/04/23 16:41:50 So UpstartMixin needs to be last? Why?
benjamin.saller 2013/04/23 16:55:41 The order things start in. The last composed backe
184 185
185 # record our choice mapping classes to instances 186 # record our choice mapping classes to instances
186 for i, b in enumerate(backends): 187 for i, b in enumerate(backends):
187 if callable(b): 188 if callable(b):
188 backends[i] = b() 189 backends[i] = b()
189 self.backends = backends 190 self.backends = backends
190 191
191 def __getitem__(self, key): 192 def __getitem__(self, key):
192 try: 193 try:
193 return self.config[key] 194 return self.config[key]
(...skipping 21 matching lines...) Expand all
215 def log(self, msg, *args): 216 def log(self, msg, *args):
216 log(msg, *args) 217 log(msg, *args)
217 218
218 @overrideable 219 @overrideable
219 def install_extra_repositories(self, *packages): 220 def install_extra_repositories(self, *packages):
220 if self.config.get('allow-additional-deb-repositories', True): 221 if self.config.get('allow-additional-deb-repositories', True):
221 install_extra_repositories(*packages) 222 install_extra_repositories(*packages)
222 else: 223 else:
223 apt_get('update') 224 apt_get('update')
224 225
225
226 def different(self, *keys): 226 def different(self, *keys):
227 """Return a boolean indicating if the current config 227 """Return a boolean indicating if the current config
228 value differs from the config value passed in prev_config 228 value differs from the config value passed in prev_config
229 with respect to any of the passed in string keys. 229 with respect to any of the passed in string keys.
230 """ 230 """
231 if self.prev_config is None: 231 if self.prev_config is None:
232 return True 232 return True
233 233
234 for key in keys: 234 for key in keys:
235 current = self.config.get(key) 235 current = self.config.get(key)
(...skipping 12 matching lines...) Expand all
248 248
249 ## Merged Properties 249 ## Merged Properties
250 dependencies = merge('dependencies') 250 dependencies = merge('dependencies')
251 build_dependencies = merge('build_dependencies') 251 build_dependencies = merge('build_dependencies')
252 staging_dependencies = merge('staging_dependencies') 252 staging_dependencies = merge('staging_dependencies')
253 253
254 repositories = merge('repositories') 254 repositories = merge('repositories')
255 debs = merge('debs') 255 debs = merge('debs')
256 upstart_scripts = merge('upstart_scripts') 256 upstart_scripts = merge('upstart_scripts')
257 257
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b