Merge ~lgp171188/launchpad:charm-bzrsyncd-tie-celery-services-to-active-flag into launchpad:master

Proposed by Guruprasad
Status: Merged
Approved by: Guruprasad
Approved revision: 2202db5c8b4abffda52b1d5ab6a126b5d90566c9
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~lgp171188/launchpad:charm-bzrsyncd-tie-celery-services-to-active-flag
Merge into: launchpad:master
Diff against target: 105 lines (+52/-11)
1 file modified
charm/launchpad-scripts-bzrsyncd/reactive/launchpad-scripts-bzrsyncd.py (+52/-11)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+448137@code.launchpad.net

Commit message

charm/launchpad-scripts-bzrsyncd: Control celery services using juju

... configuration parameter `active`.

To post a comment you must log in.
Revision history for this message
Guruprasad (lgp171188) wrote :

This is a port of the similar fix that I landed in https://code.launchpad.net/~lgp171188/launchpad/+git/launchpad/+merge/447924

Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/charm/launchpad-scripts-bzrsyncd/reactive/launchpad-scripts-bzrsyncd.py b/charm/launchpad-scripts-bzrsyncd/reactive/launchpad-scripts-bzrsyncd.py
2index 6dd81a1..3212fff 100644
3--- a/charm/launchpad-scripts-bzrsyncd/reactive/launchpad-scripts-bzrsyncd.py
4+++ b/charm/launchpad-scripts-bzrsyncd/reactive/launchpad-scripts-bzrsyncd.py
5@@ -5,15 +5,28 @@ import subprocess
6
7 from charmhelpers.core import hookenv, host, templating
8 from charms.launchpad.base import configure_email, get_service_config
9-from charms.launchpad.payload import configure_cron, configure_lazr
10+from charms.launchpad.db import lazr_config_files
11+from charms.launchpad.payload import (
12+ config_file_path,
13+ configure_cron,
14+ configure_lazr,
15+)
16 from charms.reactive import (
17 endpoint_from_flag,
18+ helpers,
19 remove_state,
20 set_state,
21 when,
22 when_not,
23 when_not_all,
24 )
25+from ols import base
26+
27+CHARM_CELERY_SERVICES = [
28+ "celerybeat-bzrsyncd",
29+ "celeryd_bzrsyncd_job",
30+ "celeryd_bzrsyncd_job_slow",
31+]
32
33
34 def configure_logrotate(config):
35@@ -26,6 +39,20 @@ def configure_logrotate(config):
36 )
37
38
39+def config_files():
40+ files = []
41+ files.extend(lazr_config_files())
42+ files.append(
43+ config_file_path("launchpad-scripts-bzrsyncd/launchpad-lazr.conf")
44+ )
45+ files.append(
46+ config_file_path(
47+ "launchpad-scripts-bzrsyncd-secrets-lazr.conf", secret=True
48+ )
49+ )
50+ return files
51+
52+
53 @host.restart_on_change(
54 {
55 "/lib/systemd/system/celerybeat-bzrsyncd.service": [
56@@ -42,20 +69,18 @@ def configure_logrotate(config):
57 def configure_celery(config):
58 hookenv.log("Writing celery systemd service files.")
59 destination_dir = "/lib/systemd/system"
60- service_files = (
61- "celerybeat_bzrsyncd.service",
62- "celeryd_bzrsyncd_job.service",
63- "celeryd_bzrsyncd_job_slow.service",
64- )
65- for service_file in service_files:
66+ for service in CHARM_CELERY_SERVICES:
67 templating.render(
68- f"{service_file}.j2",
69- f"{destination_dir}/{service_file}",
70+ f"{service}.service.j2",
71+ f"{destination_dir}/{service}.service",
72 config,
73 )
74 subprocess.check_call(["systemctl", "daemon-reload"])
75- for service_file in service_files:
76- subprocess.check_call(["systemctl", "enable", service_file])
77+
78+
79+def perform_action_on_services(services, action):
80+ for service in services:
81+ action(service)
82
83
84 @when(
85@@ -81,6 +106,22 @@ def configure():
86 configure_logrotate(config)
87 configure_cron(config, "crontab.j2")
88 configure_celery(config)
89+
90+ if config["active"]:
91+ if helpers.any_file_changed(
92+ [
93+ base.version_info_path(),
94+ ]
95+ + config_files()
96+ ):
97+ hookenv.log("Config files or payload changed; restarting services")
98+ perform_action_on_services(
99+ CHARM_CELERY_SERVICES, host.service_restart
100+ )
101+ perform_action_on_services(CHARM_CELERY_SERVICES, host.service_resume)
102+ else:
103+ perform_action_on_services(CHARM_CELERY_SERVICES, host.service_pause)
104+
105 set_state("service.configured")
106
107

Subscribers

People subscribed via source and target branches

to status/vote changes: