umami-software / umami

Umami is a simple, fast, privacy-focused alternative to Google Analytics.
https://umami.is
MIT License
21.56k stars 4.02k forks source link

`check-db.js` script should report the actual cause of a connection error #2837

Open dpk opened 1 month ago

dpk commented 1 month ago

Describe the feature or enhancement

While trying to install Umami I was stuck for quite a while at this stage:

✓ DATABASE_URL is defined.
✗ Unable to connect to the database.

The check-db.js script does not report what the actual exception raised by Prisma was. Credentials were correct, I was able to do a manual connection with psql with the given password etc., but this error persisted.

The problem turned out to be that Prisma was not finding the right version of the OpenSSL library*. But finding this out involved quite a bit of guesswork and wasted over an hour of my life.

The check-db.js script should actually show the exception that caused the connection to fail.

( Why on earth it needs this in order to connect to a local database without* SSL is anyone’s guess …)

mikecao commented 1 month ago

It should report it now in the latest version.

dpk commented 1 month ago

?

https://github.com/umami-software/umami/blob/b006747a457b8284b2679d6611ddd16378f7dfaa/scripts/check-db.js#L41-L49

This is the version of the script I was using, the latest commit, and it does not report the actual cause of the problem.

boly38 commented 1 month ago

Hi, I'm using provided docker compose and I'm having this issue too.

I would suggest getting more details about this error too (if possible). NB: if needed umami could add an optional ENV variable to switch at DEBUG or VERBOSE level if it helps to solve some configuration issues (without impacting the current legacy startup logs level/verbosity)


EDIT:

btw changing by this

  try {
    await prisma.$connect();

    success('Database connection successful.');
  } catch (e) {
    error(e.message);
    throw new Error('Unable to connect to the database.');
  }

dont add so much details

/app # node scripts/check-db.js
✓ DATABASE_URL is defined.
✗ Can't reach database server at `db:5432`

Please make sure your database server is running at `db:5432`.
✗ Unable to connect to the database.

there is a way to do some test using a given compose file (by hand) 1) change docker compose and for umami entry add the following entrypoint: entrypoint: ["tail", "-f", "/dev/null"] 2) then you could obtain root shell on it : docker exec --user root -it umami /bin/sh 3) you could use vi to patch js and re-run check db like previously or dig sockets like below

/app # nc -z db 5432
# wait ^^ 
/app # echo $?
1

here umami image cant reach the remote db port,


EDIT2 🚀 : On my side I was able found the root cause of my link issue, the OS update has changed some of the default ufw rules. (src) It seems that the default DEFAULT_FORWARD_POLICY is set on DROP (in /etc/default/ufw) so docker links was not possible. Here is the fix in my case

sudo vi /etc/default/ufw

change the default policy

# DEFAULT_FORWARD_POLICY="DROP"
DEFAULT_FORWARD_POLICY="ACCEPT"

and reload firewall

sudo ufw reload

hope this helps