Merge ~cjwatson/ols-charm-deps:wsgi-restart-on-version-info-change into ols-charm-deps:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 0dd1c199056a0d678a4dc99703c7d70dd00b1c53
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/ols-charm-deps:wsgi-restart-on-version-info-change
Merge into: ols-charm-deps:master
Diff against target: 65 lines (+12/-2)
4 files modified
layer/ols-wsgi/reactive/ols_wsgi.py (+2/-1)
layer/ols/lib/ols/base.py (+4/-0)
layer/ols/reactive/ols.py (+2/-1)
layer/ols/unit_tests/test_ols.py (+4/-0)
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Approve
Review via email: mp+381747@code.launchpad.net

Commit message

Restart gunicorn if version-info.txt changes

Description of the change

If we're in symlink-switch mode, then we need to restart gunicorn when a new payload has been deployed; but this may not correspond to any of the configuration changes that ols-wsgi detects. Since services generally want to ship a version-info.txt anyway, add that to the list of files that trigger a hard restart if they're changed.

To post a comment you must log in.
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

+1
nice way to handle it

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/layer/ols-wsgi/reactive/ols_wsgi.py b/layer/ols-wsgi/reactive/ols_wsgi.py
2index 7ca340b..123bff1 100644
3--- a/layer/ols-wsgi/reactive/ols_wsgi.py
4+++ b/layer/ols-wsgi/reactive/ols_wsgi.py
5@@ -37,7 +37,8 @@ def configure_gunicorn():
6 def needs_restart():
7
8 restart = None
9- if helpers.any_file_changed([wsgi.environment_file()]):
10+ if helpers.any_file_changed(
11+ [wsgi.environment_file(), base.version_info_path()]):
12 restart = 'hard'
13 elif helpers.any_file_changed(wsgi.config_files()):
14 restart = 'soft'
15diff --git a/layer/ols/lib/ols/base.py b/layer/ols/lib/ols/base.py
16index df9d984..d7955fd 100644
17--- a/layer/ols/lib/ols/base.py
18+++ b/layer/ols/lib/ols/base.py
19@@ -115,6 +115,10 @@ def payload_dir():
20 return os.path.join(hookenv.charm_dir(), 'files')
21
22
23+def version_info_path():
24+ return os.path.join(code_dir(), 'version-info.txt')
25+
26+
27 def logs():
28 return _layer_options().get('logs', {})
29
30diff --git a/layer/ols/reactive/ols.py b/layer/ols/reactive/ols.py
31index dcc9b01..b8f2735 100644
32--- a/layer/ols/reactive/ols.py
33+++ b/layer/ols/reactive/ols.py
34@@ -17,6 +17,7 @@ from ols.base import (
35 payload_name,
36 logs,
37 service_name,
38+ version_info_path,
39 )
40
41 from charmhelpers.core import hookenv
42@@ -32,7 +33,7 @@ def install_service():
43 install_payload(payload_name(), code_dir(), 'root')
44 hookenv.status_set('waiting',
45 'Service installed, but not configured.')
46- version_info = os.path.join(code_dir(), 'version-info.txt')
47+ version_info = version_info_path()
48 if os.path.exists(version_info):
49 with open(version_info) as version_file:
50 hookenv.application_version_set(version_file.read().strip())
51diff --git a/layer/ols/unit_tests/test_ols.py b/layer/ols/unit_tests/test_ols.py
52index adef577..0a9ec90 100644
53--- a/layer/ols/unit_tests/test_ols.py
54+++ b/layer/ols/unit_tests/test_ols.py
55@@ -122,6 +122,10 @@ class BaseTest(TestCase):
56 self.assertEqual(base.payload_dir(),
57 os.path.join(self.charm_dir, 'files'))
58
59+ def test_version_info_path(self):
60+ self.assertEqual(base.version_info_path(),
61+ '/srv/testservice/code/version-info.txt')
62+
63 def test_logs(self):
64 expected = {
65 '/var/log/celery.log': {'type': 'talisker'},

Subscribers

People subscribed via source and target branches