Added pgsql support for matrix.
authorLuke Hoersten <luke@hoersten.org>
Tue, 09 Jun 2020 19:14:49 -0500
changeset 39 90b1b7c4be70
parent 38 b4e705f4cda4
child 40 b42b417751e5
Added pgsql support for matrix.
matrix-synapse/defaults/main.yaml
matrix-synapse/tasks/main.yaml
matrix-synapse/templates/homeserver.yaml.j2
matrix-synapse/templates/log.yaml.j2
matrix-synapse/templates/setup_db.psql.j2
--- a/matrix-synapse/defaults/main.yaml	Tue Jun 09 14:39:54 2020 -0500
+++ b/matrix-synapse/defaults/main.yaml	Tue Jun 09 19:14:49 2020 -0500
@@ -1,5 +1,8 @@
 ---
 
 matrix_synapse_enable_registrations: "false"
-matrix_synapse_db: "/var/lib/matrix-synapse/homeserver.db"
+matrix_synapse_sqlite_db: "/var/lib/matrix-synapse/homeserver.db"
 matrix_synapse_media_store: "/var/lib/matrix-synapse/media"
+matrix_synapse_pgsql_user: "synapse"
+matrix_synapse_pgsql_db: "synapse"
+matrix_synapse_pgsql_host: "localhost"
--- a/matrix-synapse/tasks/main.yaml	Tue Jun 09 14:39:54 2020 -0500
+++ b/matrix-synapse/tasks/main.yaml	Tue Jun 09 19:14:49 2020 -0500
@@ -3,7 +3,7 @@
 - name: add debian backports keys
   become: yes
   apt_key:
-    keyserver: "keyserver.ubuntu.com "
+    keyserver: "keyserver.ubuntu.com"
     id: "{{item}}"
   loop:
     - "04EE7237B7D453EC"
@@ -24,16 +24,29 @@
 - name: configure matrix synapse
   become: yes
   template:
-    src: "homeserver.yaml.j2"
-    dest: "/etc/matrix-synapse/homeserver.yaml"
+    src: "{{item.src}}"
+    dest: "{{item.dest}}"
   notify: restart matrix synapse service
+  loop:
+    - { src: "homeserver.yaml.j2", dest: "/etc/matrix-synapse/homeserver.yaml" }
+    - { src: "log.yaml.j2", dest: "/etc/matrix-synapse/log.yaml" }
+    - { src: "server_name.yaml.j2", dest: "/etc/matrix-synapse/conf.d/server_name.yaml" }
 
-- name: configure matrix synapse server name
+- name: install db schema file
   become: yes
   template:
-    src: "server_name.yaml.j2"
-    dest: "/etc/matrix-synapse/conf.d/server_name.yaml"
-  notify: restart matrix synapse service
+    src: "setup_db.psql.j2"
+    dest: "/tmp/setup_db_{{matrix_synapse_pgsql_db}}.psql"
+    owner: "postgres"
+    group: "postgres"
+    mode: "0600"
+  changed_when: false
+
+- name: install psql
+  become: yes
+  become_user: "postgres"
+  command: "psql -f /tmp/setup_db_{{matrix_synapse_pgsql_db}}.psql"
+  changed_when: false
 
 - name: ensure matrix synapse is started
   become: yes
--- a/matrix-synapse/templates/homeserver.yaml.j2	Tue Jun 09 14:39:54 2020 -0500
+++ b/matrix-synapse/templates/homeserver.yaml.j2	Tue Jun 09 19:14:49 2020 -0500
@@ -13,7 +13,7 @@
 # e.g. matrix.org, localhost:8080, etc.
 # This is also the last part of your UserID.
 #
-server_name: "{{nginx_server_name}}"
+server_name: "{{matrix_synapse_server_name}}"
 
 # When running as a daemon, the file to store the pid in
 #
@@ -437,11 +437,11 @@
 # instance, if using certbot, use `fullchain.pem` as your certificate,
 # not `cert.pem`).
 #
-#tls_certificate_path: "/home/lhoersten/nth.io.tls.crt"
+#tls_certificate_path: "path/to/homeserver.tls.crt"
 
 # PEM-encoded private key for TLS
 #
-#tls_private_key_path: "/home/lhoersten/nth.io.tls.key"
+#tls_private_key_path: "path/to/homeserver.tls.key"
 
 # Whether to verify TLS server certificates for outbound federation requests.
 #
@@ -558,7 +558,7 @@
     #
     # If unspecified, we will use CONFDIR/client.key.
     #
-    account_key_file: /home/lhoersten/acme_account.key
+    account_key_file: path/to/homeserver/acme_account.key
 
 # List of allowed TLS fingerprints for this server to publish along
 # with the signing keys for this server. Other matrix servers that
@@ -627,10 +627,20 @@
 #
 # For more information on using Synapse with Postgres, see `docs/postgres.md`.
 #
+# database:
+#   name: sqlite3
+#   args:
+#     database: "{{matrix_synapse_sqlite_db}}"
+
 database:
-  name: sqlite3
-  args:
-    database: "{{matrix_synapse_db}}"
+ name: psycopg2
+ args:
+   user: "{{matrix_synapse_pgsql_user}}"
+   password: "{{matrix_synapse_pgsql_pass}}"
+   database: "{{matrix_synapse_pgsql_db}}"
+   host: "{{matrix_synapse_pgsql_host}}"
+   cp_min: 5
+   cp_max: 10
 
 # Number of events to cache in memory.
 #
@@ -1377,7 +1387,7 @@
   # Instead of putting the config inline as above, you can specify a
   # separate pysaml2 configuration file:
   #
-  #config_path: "/home/lhoersten/sp_conf.py"
+  #config_path: "path/to/homeserver/sp_conf.py"
 
   # The lifetime of a SAML session. This defines how long a user has to
   # complete the authentication process, if allow_unsolicited is unset.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/matrix-synapse/templates/log.yaml.j2	Tue Jun 09 19:14:49 2020 -0500
@@ -0,0 +1,56 @@
+
+version: 1
+
+formatters:
+  precise:
+   format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s- %(message)s'
+  journal_fmt:
+   format: '%(name)s: [%(request)s] %(message)s'
+
+filters:
+  context:
+    (): synapse.util.logcontext.LoggingContextFilter
+    request: ""
+
+handlers:
+  file:
+    class: logging.handlers.WatchedFileHandler
+    formatter: precise
+    filename: /var/log/matrix-synapse/homeserver.log
+    filters: [context]
+    level: ERROR
+    encoding: utf8
+  console:
+    class: logging.StreamHandler
+    formatter: precise
+    level: ERROR
+  journal:
+    class: systemd.journal.JournalHandler
+    formatter: journal_fmt
+    filters: [context]
+    SYSLOG_IDENTIFIER: synapse
+
+loggers:
+    twisted:
+        level: ERROR
+
+    synapse:
+        level: ERROR
+
+    # the following levels are more verbose than most users want
+    # set them to INFO if you need more logging
+    synapse.metrics:
+        level: ERROR
+
+    synapse.http.federation.well_known_resolver:
+        level: ERROR
+
+    synapse.storage.TIME:
+        level: ERROR
+
+    synapse.http.matrixfederationclient:
+        level: ERROR
+
+root:
+    level: ERROR
+    handlers: [journal]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/matrix-synapse/templates/setup_db.psql.j2	Tue Jun 09 19:14:49 2020 -0500
@@ -0,0 +1,2 @@
+CREATE USER {{matrix_synapse_pgsql_user}} WITH ENCRYPTED PASSWORD '{{matrix_synapse_pgsql_pass}}';
+CREATE DATABASE {{matrix_synapse_pgsql_db}} ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 WITH OWNER {{matrix_synapse_pgsql_user}};