summary refs log tree commit diff
path: root/synapse/app
diff options
context:
space:
mode:
authorMark Haines <mjark@negativecurvature.net>2015-04-29 13:04:22 +0100
committerMark Haines <mjark@negativecurvature.net>2015-04-29 13:04:22 +0100
commit19167fd21fb74c10c95f61808d2b3c453ea36e8d (patch)
treed29e65d35d444b6e1b426fe44547585a2af2afcf /synapse/app
parentminimal doc (diff)
parentMake postgres database error slightly more helpful (diff)
downloadsynapse-19167fd21fb74c10c95f61808d2b3c453ea36e8d.tar.xz
Merge pull request #135 from matrix-org/erikj/postgres_charset_check
Check that postgres database has correct charset set
Diffstat (limited to 'synapse/app')
-rwxr-xr-xsynapse/app/homeserver.py28
1 files changed, 20 insertions, 8 deletions
diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py
index 694a0125ad..29a1bf1d70 100755
--- a/synapse/app/homeserver.py
+++ b/synapse/app/homeserver.py
@@ -17,7 +17,7 @@
 import sys
 sys.dont_write_bytecode = True
 
-from synapse.storage.engines import create_engine
+from synapse.storage.engines import create_engine, IncorrectDatabaseSetup
 from synapse.storage import (
     are_all_users_on_domain, UpgradeDatabaseException,
 )
@@ -245,15 +245,27 @@ class SynapseHomeServer(HomeServer):
             db_conn.cursor(), database_engine, self.hostname
         )
         if not all_users_native:
-            sys.stderr.write(
-                "\n"
-                "******************************************************\n"
+            quit_with_error(
                 "Found users in database not native to %s!\n"
-                "You cannot changed a synapse server_name after it's been configured\n"
-                "******************************************************\n"
-                "\n" % (self.hostname,)
+                "You cannot changed a synapse server_name after it's been configured"
+                % (self.hostname,)
             )
-            sys.exit(1)
+
+        try:
+            database_engine.check_database(db_conn.cursor())
+        except IncorrectDatabaseSetup as e:
+            quit_with_error(e.message)
+
+
+def quit_with_error(error_string):
+    message_lines = error_string.split("\n")
+    line_length = max([len(l) for l in message_lines]) + 2
+    sys.stderr.write("*" * line_length + '\n')
+    for line in message_lines:
+        if line.strip():
+            sys.stderr.write(" %s\n" % (line.strip(),))
+    sys.stderr.write("*" * line_length + '\n')
+    sys.exit(1)
 
 
 def get_version_string():