Repository: Mailu/Mailu

Issue:
master version postgresql database roundcube webmail 502 Bad Gateway
setup.mailu.io  Version master 

Both postgresql and mysql  are 502 Bad Gateway

sqllite can open roundcube webmail

Ranloop can work normally


Discussion:
I can confirm. The problem is here: https://github.com/Mailu/Mailu/blob/master/webmails/roundcube/start.py#L13-L28

We use the same `DB_HOST` and `DB_FLAVOR` as set by https://setup.mailu.io in `mailu.env` but don't also use `DB_USER`, `DB_PW` and `DB_NAME` …

---

We are very sorry for the inconvenience, and will implement a fix for this.
In the meantime as a workaround you can:

a) set `ROUNDCUBE_DB_USER`, `ROUNDCUBE_DB_PW` and `ROUNDCUBE_DB_NAME` in your `mailu.env` to the same as the corresponding variables without `ROUNDCUBE_` – roundcube will then use your external DB with the correct credentials

or

b) set `ROUNDCUBE_DB_FLAVOR=sqlite` – roundcube will then use a separate sqlite file in `$YOUR_MAILU_TOPDIR/webmail/roundcube.db`
Related issue: #1471
I have changed to sqlite, thanks
Hi,

I’m wondering what the right thing to do here is. Assuming the user has a external database, our docs instruct the user to create a `mailu` user and `mailu` database. Roundcube is currently geared to want its own database. So either, we leave the user with the duty to create another database, with permissions to the same `mailu` user, or we include the `ROUNDCUBE_DB_` variables in setup, expose and document them.

The third option is to let roundcubes database-init script shove its data into the `mailu` database … which would probably work, but is never guaranteed to not-clash some day in the future, so for me this is the least favorable option.

Is there another way I overlooked?

Also, while i recognize this is a problematic issue, given how much others are around, are we sure this is our last 1.8-rc blocker :sweat_smile: :sweat_drops:  or would we rather also postpone it, like so many other issues … I mean, at least there’s a workaround nicely described thanks to @HorayNarea? 

Resolving patch:
diff --git a/optional/postgresql/start.py b/optional/postgresql/start.py
--- a/optional/postgresql/start.py
+++ b/optional/postgresql/start.py
@@ -2,7 +2,6 @@
 
 import anosql
 import psycopg2
-import jinja2
 import glob
 import os
 import subprocess
@@ -38,7 +37,6 @@ def setup():
                 rec.write("restore_command = 'gunzip < /backup/wal_archive/%f > %p'\n")
                 rec.write("standby_mode = off\n")
             os.system("chown postgres:postgres /data/recovery.conf")
-            #os.system("sudo -u postgres pg_ctl start -D /data -o '-h \"''\" '")
     else:
         # Bootstrap the database
         os.system("sudo -u postgres initdb -D /data")
diff --git a/webmails/roundcube/start.py b/webmails/roundcube/start.py
--- a/webmails/roundcube/start.py
+++ b/webmails/roundcube/start.py
@@ -8,31 +8,29 @@
 
 log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", "WARNING"))
 
-os.environ["MAX_FILESIZE"] = str(int(int(os.environ.get("MESSAGE_SIZE_LIMIT"))*0.66/1048576))
+os.environ["MAX_FILESIZE"] = str(int(int(os.environ.get("MESSAGE_SIZE_LIMIT")) * 0.66 / 1048576))
 
-db_flavor=os.environ.get("ROUNDCUBE_DB_FLAVOR",os.environ.get("DB_FLAVOR","sqlite"))
-if db_flavor=="sqlite":
-    os.environ["DB_DSNW"]="sqlite:////data/roundcube.db"
-elif db_flavor=="mysql":
-    os.environ["DB_DSNW"]="mysql://%s:%s@%s/%s" % (
-        os.environ.get("ROUNDCUBE_DB_USER","roundcube"),
+db_flavor = os.environ.get("ROUNDCUBE_DB_FLAVOR", "sqlite")
+if db_flavor == "sqlite":
+    os.environ["DB_DSNW"] = "sqlite:////data/roundcube.db"
+elif db_flavor == "mysql":
+    os.environ["DB_DSNW"] = "mysql://%s:%s@%s/%s" % (
+        os.environ.get("ROUNDCUBE_DB_USER", "roundcube"),
         os.environ.get("ROUNDCUBE_DB_PW"),
-        os.environ.get("ROUNDCUBE_DB_HOST",os.environ.get("DB_HOST","database")),
-        os.environ.get("ROUNDCUBE_DB_NAME","roundcube")
-        )
-elif db_flavor=="postgresql":
-    os.environ["DB_DSNW"]="pgsql://%s:%s@%s/%s" % (
-        os.environ.get("ROUNDCUBE_DB_USER","roundcube"),
+        os.environ.get("ROUNDCUBE_DB_HOST", "database"),
+        os.environ.get("ROUNDCUBE_DB_NAME", "roundcube")
+    )
+elif db_flavor == "postgresql":
+    os.environ["DB_DSNW"] = "pgsql://%s:%s@%s/%s" % (
+        os.environ.get("ROUNDCUBE_DB_USER", "roundcube"),
         os.environ.get("ROUNDCUBE_DB_PW"),
-        os.environ.get("ROUNDCUBE_DB_HOST",os.environ.get("DB_HOST","database")),
-        os.environ.get("ROUNDCUBE_DB_NAME","roundcube")
-        )
+        os.environ.get("ROUNDCUBE_DB_HOST", "database"),
+        os.environ.get("ROUNDCUBE_DB_NAME", "roundcube")
+    )
 else:
-    print("Unknown ROUNDCUBE_DB_FLAVOR: %s",db_flavor)
+    print("Unknown ROUNDCUBE_DB_FLAVOR: %s", db_flavor)
     exit(1)
 
-
-
 conf.jinja("/php.ini", os.environ, "/usr/local/etc/php/conf.d/roundcube.ini")
 
 # Create dirs, setup permissions
@@ -42,7 +40,8 @@
 
 try:
     print("Initializing database")
-    result=subprocess.check_output(["/var/www/html/bin/initdb.sh","--dir","/var/www/html/SQL"],stderr=subprocess.STDOUT)
+    result = subprocess.check_output(["/var/www/html/bin/initdb.sh", "--dir", "/var/www/html/SQL"],
+                                     stderr=subprocess.STDOUT)
     print(result.decode())
 except subprocess.CalledProcessError as e:
     if "already exists" in e.stdout.decode():
@@ -53,7 +52,7 @@
 
 try:
     print("Upgrading database")
-    subprocess.check_call(["/var/www/html/bin/update.sh","--version=?","-y"],stderr=subprocess.STDOUT)
+    subprocess.check_call(["/var/www/html/bin/update.sh", "--version=?", "-y"], stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
     quit(1)
 
@@ -61,7 +60,7 @@
 os.system("chown -R www-data:www-data /data")
 
 # Tail roundcube logs
-subprocess.Popen(["tail","-f","-n","0","/var/www/html/logs/errors.log"])
+subprocess.Popen(["tail", "-f", "-n", "0", "/var/www/html/logs/errors.log"])
 
 # Run apache
 os.execv("/usr/local/bin/apache2-foreground", ["apache2-foreground"])


Test patch: