Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

kandra: Add a mirror of #signups to CZO.

Alex Vandiver456354575eaf
diff --git a/puppet/kandra/files/mirror_to_czo b/puppet/kandra/files/mirror_to_czo
new file mode 100755
index 00000000000..8705daadee6
--- /dev/null
+++ b/puppet/kandra/files/mirror_to_czo
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+
+import configparser
+import logging
+import time
+from contextlib import suppress
+from typing import Any
+
+import zulip
+
+config_file = configparser.RawConfigParser()
+config_file.read("/etc/zulip/zulip.conf")
+send_to_channel = config_file.get("mirror_to_czo", "send_to_channel")
+
+reading = zulip.Client(config_file="/etc/zulip/mirror_to_czo.zulipcore.zuliprc")
+sending = zulip.Client(config_file="/etc/zulip/mirror_to_czo.czo.zuliprc")
+
+logging.Formatter.converter = time.gmtime
+logging.basicConfig(format="%(asctime)s mirror_to_czo: %(message)s", level=logging.INFO)
+
+
+def send_mirror(msg: dict[str, Any]) -> None:
+ logging.info(msg["message"]["content"])
+ sending.send_message(
+ {
+ "type": "stream",
+ "to": send_to_channel,
+ "topic": msg["message"]["subject"],
+ "content": msg["message"]["content"],
+ }
+ )
+
+
+with suppress(KeyboardInterrupt):
+ reading.call_on_each_event(
+ send_mirror,
+ event_types=["message"],
+ narrow=[["stream", "signups"]],
+ )
diff --git a/puppet/kandra/manifests/mirror_to_czo.pp b/puppet/kandra/manifests/mirror_to_czo.pp
new file mode 100644
index 00000000000..d0af207e3c3
--- /dev/null
+++ b/puppet/kandra/manifests/mirror_to_czo.pp
@@ -0,0 +1,31 @@
+class kandra::mirror_to_czo {
+ include zulip::supervisor
+
+ # We embed the hash of the contents into the name of the process, so
+ # that `supervisorctl reread` knows that it has updated.
+ $full_script_hash = sha256(file('kandra/mirror_to_czo'))
+ $script_hash = $full_script_hash[0,8]
+
+ $bin = '/usr/local/bin/mirror_to_czo'
+ file { $bin:
+ ensure => file,
+ owner => 'root',
+ group => 'root',
+ mode => '0755',
+ source => 'puppet:///modules/kandra/mirror_to_czo',
+ }
+
+ file { "${zulip::common::supervisor_conf_dir}/mirror_to_czo.conf":
+ ensure => file,
+ require => [
+ User[zulip],
+ Package[supervisor],
+ File[$bin],
+ ],
+ owner => 'root',
+ group => 'root',
+ mode => '0644',
+ content => template('kandra/supervisor/conf.d/mirror_to_czo.conf.template.erb'),
+ notify => Service[supervisor],
+ }
+}
diff --git a/puppet/kandra/manifests/prod_app_frontend_once.pp b/puppet/kandra/manifests/prod_app_frontend_once.pp
index 778b35d8bc0..cfe528d4177 100644
--- a/puppet/kandra/manifests/prod_app_frontend_once.pp
+++ b/puppet/kandra/manifests/prod_app_frontend_once.pp
@@ -3,6 +3,7 @@ class kandra::prod_app_frontend_once {
include zulip::hooks::push_git_ref
include zulip::hooks::zulip_notify
include kandra::hooks::zulip_notify_schema_diff
+ include kandra::mirror_to_czo
zulip::cron { 'update-first-visible-message-id':
hour => '7',
diff --git a/puppet/kandra/templates/supervisor/conf.d/mirror_to_czo.conf.template.erb b/puppet/kandra/templates/supervisor/conf.d/mirror_to_czo.conf.template.erb
new file mode 100644
index 00000000000..755cb272f21
--- /dev/null
+++ b/puppet/kandra/templates/supervisor/conf.d/mirror_to_czo.conf.template.erb
@@ -0,0 +1,13 @@
+[program:mirror_to_czo]
+# We record the hash of the script so that we can update this file
+# with it, which will make `supervisorctl reread && supervisorctl
+# update` restart this job.
+command=uv run --no-sync /usr/local/bin/mirror_to_czo
+directory=/home/zulip/deployments/current/
+process_name=mirror_to_czo_<%= @script_hash %>
+priority=10
+autostart=true
+autorestart=true
+user=zulip
+redirect_stderr=true
+stdout_logfile=/var/log/zulip/mirror_to_czo.log