← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:charm-frontend-extras-librarian-rsync into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:charm-frontend-extras-librarian-rsync into launchpad:master.

Commit message:
charm: Add librarian-logs rsync module to librarian frontend

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/450385

The `launchpad-scripts` charm needs to be able to rsync librarian logs from the appropriate frontends so that it can parse them and update download counts.  On the legacy frontends this is configured manually; on charmed frontends we need to configure it in code somewhere.

To avoid having to fork the `apache2` charm, we add a custom `librarian-logs` subordinate to `launchpad-frontend-extras`.  This can be related to the librarian frontend application to configure an rsync module there.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:charm-frontend-extras-librarian-rsync into launchpad:master.
diff --git a/charm/launchpad-frontend-extras/README.md b/charm/launchpad-frontend-extras/README.md
index 06636de..9ef4805 100644
--- a/charm/launchpad-frontend-extras/README.md
+++ b/charm/launchpad-frontend-extras/README.md
@@ -5,8 +5,14 @@ fit in anywhere else.
 
 Assuming that the `haproxy` charm has been deployed as the `services-lb`
 application and that the `apache2` charm has been deployed as the
-`main-frontend` application, as in lp:launchpad-mojo-specs, the following
+`frontend-main` application, as in lp:launchpad-mojo-specs, the following
 relations are useful:
 
     juju relate launchpad-frontend-extras:juju-info services-lb:juju-info
-    juju relate launchpad-frontend-extras:apache-website main-frontend:apache-website
+    juju relate launchpad-frontend-extras:apache-website frontend-main:apache-website
+
+This charm can also be related to the `frontend-librarian` application
+(presumed to be an instance of the `apache2` charm) to publish librarian
+logs over rsync for use by the `launchpad-scripts` charm:
+
+    juju relate launchpad-frontend-extras:librarian-logs frontend-librarian:juju-info
diff --git a/charm/launchpad-frontend-extras/config.yaml b/charm/launchpad-frontend-extras/config.yaml
index 648af60..cbe841d 100644
--- a/charm/launchpad-frontend-extras/config.yaml
+++ b/charm/launchpad-frontend-extras/config.yaml
@@ -11,6 +11,12 @@ options:
     type: boolean
     description: Whether to enable the "media" domain.
     default: false
+  librarian_log_hosts_allow:
+    type: string
+    description: >
+      Space-separated list of hosts that should be allowed to rsync
+      librarian logs.
+    default: ""
   offline_mode:
     type: string
     description: >
diff --git a/charm/launchpad-frontend-extras/layer.yaml b/charm/launchpad-frontend-extras/layer.yaml
index e3f44d9..56f9014 100644
--- a/charm/launchpad-frontend-extras/layer.yaml
+++ b/charm/launchpad-frontend-extras/layer.yaml
@@ -1,4 +1,5 @@
 includes:
   - layer:basic
   - interface:apache-website
+  - interface:juju-info
 repo: https://git.launchpad.net/launchpad
diff --git a/charm/launchpad-frontend-extras/metadata.yaml b/charm/launchpad-frontend-extras/metadata.yaml
index f77ae61..daeda2d 100644
--- a/charm/launchpad-frontend-extras/metadata.yaml
+++ b/charm/launchpad-frontend-extras/metadata.yaml
@@ -21,3 +21,6 @@ requires:
   juju-info:
     interface: juju-info
     scope: container
+  librarian-logs:
+    interface: juju-info
+    scope: container
diff --git a/charm/launchpad-frontend-extras/reactive/launchpad-frontend-extras.py b/charm/launchpad-frontend-extras/reactive/launchpad-frontend-extras.py
index 2d69b31..2d4e312 100644
--- a/charm/launchpad-frontend-extras/reactive/launchpad-frontend-extras.py
+++ b/charm/launchpad-frontend-extras/reactive/launchpad-frontend-extras.py
@@ -132,3 +132,28 @@ def configure_apache_website():
 @when_not_all("apache-website.available", "service.configured")
 def deconfigure_apache_website():
     clear_flag("service.apache-website.configured")
+
+
+_rsync_path = "/etc/rsync-juju.d/020-librarian-logs.conf"
+
+
+@when("librarian-logs.connected", "service.configured")
+@when_not("service.librarian-logs.configured")
+def configure_librarian_logs():
+    config = dict(hookenv.config())
+    if config["librarian_log_hosts_allow"]:
+        hookenv.log("Writing librarian-logs rsync configuration.")
+        templating.render(
+            "librarian-logs-rsync.conf.j2", _rsync_path, config, perms=0o644
+        )
+    elif os.path.exists(_rsync_path):
+        os.unlink(_rsync_path)
+    set_flag("service.librarian-logs.configured")
+
+
+@when("service.librarian-logs.configured")
+@when_not_all("librarian-logs.connected", "service.configured")
+def deconfigure_librarian_logs():
+    if os.path.exists(_rsync_path):
+        os.unlink(_rsync_path)
+    clear_flag("service.librarian-logs.configured")
diff --git a/charm/launchpad-frontend-extras/templates/librarian-logs-rsync.conf.j2 b/charm/launchpad-frontend-extras/templates/librarian-logs-rsync.conf.j2
new file mode 100644
index 0000000..54090f2
--- /dev/null
+++ b/charm/launchpad-frontend-extras/templates/librarian-logs-rsync.conf.j2
@@ -0,0 +1,14 @@
+
+[librarian-logs]
+  # /var/log/apache2/ is root:adm 0640, so we can't drop privileges to read
+  # it.
+  uid = root
+  gid = *
+  path = /var/log/apache2/
+  comment = LP Librarian Logs
+  list = false
+  read only = true
+  hosts allow = {{ librarian_log_hosts_allow }}
+  exclude = *
+  include = {{ domain_librarian }}-access*
+