← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/txpkgupload:charm-rsync-logs into txpkgupload:master

 

Colin Watson has proposed merging ~cjwatson/txpkgupload:charm-rsync-logs into txpkgupload:master.

Commit message:
charm: Allow rsyncing logs

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

This is copied from the `launchpad-base` layer.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/txpkgupload:charm-rsync-logs into txpkgupload:master.
diff --git a/charm/txpkgupload/config.yaml b/charm/txpkgupload/config.yaml
index a8ed4f6..4fa1ef3 100644
--- a/charm/txpkgupload/config.yaml
+++ b/charm/txpkgupload/config.yaml
@@ -21,6 +21,12 @@ options:
       - mode tcp
       - option tcplog
       - balance leastconn
+  log_hosts_allow:
+    type: string
+    description: >
+      Hosts that should be allowed to rsync logs.  Note that this relies on
+      the nrpe subordinate charm to set up /etc/rsyncd.conf properly.
+    default: ""
   oops_prefix:
     type: string
     default: local
diff --git a/charm/txpkgupload/reactive/txpkgupload.py b/charm/txpkgupload/reactive/txpkgupload.py
index 32b3320..3789135 100644
--- a/charm/txpkgupload/reactive/txpkgupload.py
+++ b/charm/txpkgupload/reactive/txpkgupload.py
@@ -30,6 +30,15 @@ def configure_logrotate(config):
     )
 
 
+def configure_rsync(config, template, name):
+    hookenv.log("Writing rsync configuration.")
+    rsync_path = os.path.join("/etc/rsync-juju.d", name)
+    if config["log_hosts_allow"]:
+        templating.render(template, rsync_path, config, perms=0o644)
+    elif os.path.exists(rsync_path):
+        os.unlink(rsync_path)
+
+
 def create_virtualenv(wheels_dir, codedir, python_exe):
     hookenv.log("Creating virtualenv for txpkgupload charm")
     subprocess.check_call(
@@ -143,6 +152,7 @@ def configure_txpkgupload(config: Dict):
         config,
     )
     configure_logrotate(config)
+    configure_rsync(config, "txpkgupload-rsync.conf", "010-txpkgupload.conf")
 
     hookenv.log("Starting txpkgupload")
     subprocess.check_call(["systemctl", "daemon-reload"])