Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to connect to any database #94

Closed
codefriar opened this issue May 7, 2020 · 5 comments
Closed

Unable to connect to any database #94

codefriar opened this issue May 7, 2020 · 5 comments

Comments

@codefriar
Copy link

Team,

I'm attempting to add CodiMD to HomelabOS, and when I spin up the containers the app is never able to access the database.

I've tried Postgres and Mariadb, both with configs copy/pasted from: https://github.com/codimd/container/blob/master/docker-compose.yml

The following details reflect my latest testing, with Mariadb. The same issue happened with Postgres. Here's the Docker-compose yml

---
version: '3'

networks:
  traefik_network:
    external:
      name: homelabos_traefik

services:
  database:
    networks:
      - traefik_network
    image: mariadb:10
    environment:
      - MYSQL_USER=hackmd
      - MYSQL_PASSWORD=hackmdpass
      - MYSQL_DATABASE=hackmd
      - MYSQL_ALLOW_EMPTY_PASSWORD=true
    volumes:
      - "/var/homelabos/codimd/mariadb:/var/lib/mysql"
      - ./resources/utf8.cnf:/etc/mysql/conf.d/utf8.cnf
    restart: unless-stopped
  app:
    # REQUIRED
    image: quay.io/codimd/server:1.6.0
    restart: unless-stopped
    networks:
      - traefik_network
    environment:
      - CMD_DB_URL=mariadb://hackmd:hackmdpass@database:3306/hackmd
      - CMD_SESSION_SECRET=REDACTED
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=homelabos_traefik"
      - "traefik.http.services.codimd.loadbalancer.server.scheme=http"
      - "traefik.http.services.codimd.loadbalancer.server.port=3000"
      - "traefik.http.routers.codimd-http.rule=Host(`codimd.pinguinshow.com`)"
      - "traefik.http.routers.codimd-http.entrypoints=http"
      - "traefik.http.routers.codimd-http.middlewares=customFrameHomelab@file"
      - "traefik.http.routers.codimd.rule=Host(`codimd.pinguinshow.com`)"
      - "traefik.http.routers.codimd.entrypoints=https"
      - "traefik.http.routers.codimd.middlewares=customFrameHomelab@file"
      - "traefik.http.routers.codimd.tls=true"
      - "traefik.http.routers.codimd.tls.certresolver=dns"
      - "traefik.http.routers.codimd.tls.domains[0].main=pinguinshow.com"
      - "traefik.http.routers.codimd.tls.domains[0].sans=*.pinguinshow.com"
    depends_on:
      - database

On startup, the database container shows:

2020-05-07 03:29:37+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.4.12+maria~bionic started.,
2020-05-07 03:29:38+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql',
2020-05-07 03:29:38+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.4.12+maria~bionic started.,
2020-05-07  3:29:38 0 [Note] mysqld (mysqld 10.4.12-MariaDB-1:10.4.12+maria~bionic) starting as process 1 ...,
2020-05-07  3:29:38 0 [Note] InnoDB: Using Linux native AIO,
2020-05-07  3:29:38 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins,
2020-05-07  3:29:38 0 [Note] InnoDB: Uses event mutexes,
2020-05-07  3:29:38 0 [Note] InnoDB: Compressed tables use zlib 1.2.11,
2020-05-07  3:29:38 0 [Note] InnoDB: Number of pools: 1,
2020-05-07  3:29:38 0 [Note] InnoDB: Using SSE2 crc32 instructions,
2020-05-07  3:29:38 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts),
2020-05-07  3:29:38 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M,
2020-05-07  3:29:39 0 [Note] InnoDB: Completed initialization of buffer pool,
2020-05-07  3:29:39 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().,
2020-05-07  3:29:39 0 [Note] InnoDB: 128 out of 128 rollback segments are active.,
2020-05-07  3:29:39 0 [Note] InnoDB: Creating shared tablespace for temporary tables,
2020-05-07  3:29:39 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...,
2020-05-07  3:29:39 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.,
2020-05-07  3:29:39 0 [Note] InnoDB: 10.4.12 started; log sequence number 60990; transaction id 21,
2020-05-07  3:29:39 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool,
2020-05-07  3:29:39 0 [Note] Plugin 'FEEDBACK' is disabled.,
2020-05-07  3:29:39 0 [Note] Server socket created on IP: '::'.,
2020-05-07  3:29:39 0 [Warning] 'proxies_priv' entry '@% root@5ff5d1b80589' ignored in --skip-name-resolve mode.,
2020-05-07  3:29:39 0 [Note] Reading of all Master_info entries succeeded,
2020-05-07  3:29:39 0 [Note] Added new Master_info '' to hash table,
2020-05-07  3:29:39 0 [Note] mysqld: ready for connections.,
Version: '10.4.12-MariaDB-1:10.4.12+maria~bionic'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution,
2020-05-07  3:29:39 0 [Note] InnoDB: Buffer pool(s) load completed at 200507  3:29:39,
2020-05-07  3:29:39 8 [Warning] Aborted connection 8 to db: 'unconnected' user: 'unauthenticated' host: '172.18.0.42' (This connection closed normally without authentication),

And the App reports

app_1       | 2020/05/07 03:43:40 Waiting for: tcp://database:3306
app_1       | 2020/05/07 03:43:40 Problem with dial: dial tcp 172.18.0.8:3306: connect: connection refused. Sleeping 1s
app_1       | 2020/05/07 03:43:41 Connected to tcp://database:3306
app_1       |
app_1       | Sequelize CLI [Node: 12.16.2, CLI: 5.5.1, ORM: 5.21.4]
app_1       |
app_1       | Parsed url mariadb://hackmd:*****@database:3306/hackmd
app_1       | warning: please use IANA standard timezone format ('Etc/GMT0')
app_1       |
app_1       | ERROR: connect ECONNREFUSED 172.18.0.8:3306
app_1       |
app_1       | 2020-05-07T03:43:46.107Z warn: 	Neither 'domain' nor 'CMD_DOMAIN' is configured. This can cause issues with various components.
app_1       | Hint: Make sure 'protocolUseSSL' and 'urlAddPort' or 'CMD_PROTOCOL_USESSL' and 'CMD_URL_ADDPORT' are configured properly.
app_1       | 2020-05-07T03:43:46.111Z warn: 	PDF export was disabled for this release to mitigate a critical security issue. This feature will hopefully become available again in future releases.
app_1       | Thu, 07 May 2020 03:43:46 GMT hsts deprecated The "includeSubdomains" parameter is deprecated. Use "includeSubDomains" (with a capital D) instead. at app.js:85:18
app_1       | warning: please use IANA standard timezone format ('Etc/GMT0')
app_1       | warning: please use IANA standard timezone format ('Etc/GMT0')
app_1       | 2020-05-07T03:43:47.366Z info: 	HTTP Server listening at 0.0.0.0:3000

I'm scratching my head here, but it feels like there's something wrong at the sequelize level?

@SISheogorath
Copy link
Contributor

Looking at the timestamps, is it possible that your network already contains another container called database? Can you check that if you replace your traefik_network with an docker-compose internal one, as in the example, that things start working? In this case you probably need to rename the database container to codimd-database or alike.

@codefriar
Copy link
Author

@SISheogorath - First, thanks for the response.

I can't drop from the traefik network all together, as homelab fronts that database with a domain, so it's available outside the machine.

That said, I did rename the database service name to codiMdDatabase, and modified the database connection string apropriately. Here's the final docker compose:

---
version: '3'

# This networks section required for the pacakge to be visible to Traefik.
# DO NOT Remove
networks:
  traefik_network:
    external:
      name: homelabos_traefik

services:
  codiMdDatabase:
    networks:
      - traefik_network
    image: postgres:9.6-alpine
    environment:
      # MYSQL_PASSWORD=lookup('password', './settings/passwords/package_name_db_password chars=digits')
      - POSTGRES_USER=hackmd
      - POSTGRES_PASSWORD=hackmdpass
      - POSTGRES_DB=hackmd
    volumes:
      - "/var/homelabos/codimd/postgresql/data:/var/lib/postgresql/data"
    restart: unless-stopped
  codiMdApp:
    # REQUIRED
    image: quay.io/codimd/server:latest
    restart: unless-stopped
    networks:
      - traefik_network
    environment:
      - CMD_DB_URL=postgres://hackmd:hackmdpass@codiMdDatabase:5432/hackmd
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=homelabos_traefik"
      - "traefik.http.services.codimd.loadbalancer.server.scheme=http"
      - "traefik.http.services.codimd.loadbalancer.server.port=3000"
      - "traefik.http.routers.codimd-http.rule=Host(`codimd.pinguinshow.com`)"
      - "traefik.http.routers.codimd-http.entrypoints=http"
      - "traefik.http.routers.codimd-http.middlewares=customFrameHomelab@file"
      - "traefik.http.routers.codimd.rule=Host(`codimd.pinguinshow.com`)"
      - "traefik.http.routers.codimd.entrypoints=https"
      - "traefik.http.routers.codimd.middlewares=customFrameHomelab@file"
      - "traefik.http.routers.codimd.tls=true"
      - "traefik.http.routers.codimd.tls.certresolver=dns"
      - "traefik.http.routers.codimd.tls.domains[0].main=pinguinshow.com"
      - "traefik.http.routers.codimd.tls.domains[0].sans=*.pinguinshow.com"
    depends_on:
      - codiMdDatabase

However, when I bring this up, I still see failures, and codimd doesn't start. Logs:

Creating codimd_codiMdDatabase_1 ... done
Creating codimd_codiMdApp_1      ... done
Attaching to codimd_codiMdDatabase_1, codimd_codiMdApp_1
codiMdDatabase_1  |
codiMdDatabase_1  | PostgreSQL Database directory appears to contain a database; Skipping initialization
codiMdDatabase_1  |
codiMdDatabase_1  | LOG:  database system was shut down at 2020-05-07 14:20:11 UTC
codiMdDatabase_1  | LOG:  MultiXact member wraparound protections are now enabled
codiMdDatabase_1  | LOG:  database system is ready to accept connections
codiMdDatabase_1  | LOG:  autovacuum launcher started
codiMdApp_1       | 2020/05/07 14:20:25 Waiting for: tcp://codiMdDatabase:5432
codiMdApp_1       | 2020/05/07 14:20:25 Connected to tcp://codiMdDatabase:5432
codiMdDatabase_1  | LOG:  incomplete startup packet
codiMdApp_1       |
codiMdApp_1       | Sequelize CLI [Node: 12.16.2, CLI: 5.5.1, ORM: 5.21.4]
codiMdApp_1       |
codiMdApp_1       | Parsed url postgres://hackmd:*****@codiMdDatabase:5432/hackmd
codiMdDatabase_1  | FATAL:  password authentication failed for user "hackmd"
codiMdDatabase_1  | DETAIL:  Role "hackmd" does not exist.
codiMdDatabase_1  | 	Connection matched pg_hba.conf line 95: "host all all all md5"
codiMdApp_1       |
codiMdApp_1       | ERROR: password authentication failed for user "hackmd"
codiMdApp_1       |
codiMdApp_1       | 2020-05-07T14:20:29.411Z warn: 	Neither 'domain' nor 'CMD_DOMAIN' is configured. This can cause issues with various components.
codiMdApp_1       | Hint: Make sure 'protocolUseSSL' and 'urlAddPort' or 'CMD_PROTOCOL_USESSL' and 'CMD_URL_ADDPORT' are configured properly.
codiMdApp_1       | 2020-05-07T14:20:29.415Z warn: 	Session secret not set. Using random generated one. Please set `sessionSecret` in your config.js file. All users will be logged out.
codiMdApp_1       | 2020-05-07T14:20:29.415Z warn: 	PDF export was disabled for this release to mitigate a critical security issue. This feature will hopefully become available again in future releases.
codiMdApp_1       | Thu, 07 May 2020 14:20:29 GMT hsts deprecated The "includeSubdomains" parameter is deprecated. Use "includeSubDomains" (with a capital D) instead. at app.js:85:18
codiMdDatabase_1  | FATAL:  password authentication failed for user "hackmd"
codiMdDatabase_1  | DETAIL:  Role "hackmd" does not exist.
codiMdDatabase_1  | 	Connection matched pg_hba.conf line 95: "host all all all md5"
codiMdApp_1       | Unhandled rejection SequelizeConnectionError: password authentication failed for user "hackmd"
codiMdApp_1       |     at /codimd/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:182:24
codiMdApp_1       |     at Connection.connectingErrorHandler (/codimd/node_modules/pg/lib/client.js:194:14)
codiMdApp_1       |     at Connection.emit (events.js:310:20)
codiMdApp_1       |     at Socket.<anonymous> (/codimd/node_modules/pg/lib/connection.js:134:12)
codiMdApp_1       |     at Socket.emit (events.js:310:20)
codiMdApp_1       |     at addChunk (_stream_readable.js:286:12)
codiMdApp_1       |     at readableAddChunk (_stream_readable.js:268:9)
codiMdApp_1       |     at Socket.Readable.push (_stream_readable.js:209:10)
codiMdApp_1       |     at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
codiMdDatabase_1  | FATAL:  password authentication failed for user "hackmd"
codiMdDatabase_1  | DETAIL:  Role "hackmd" does not exist.
codiMdDatabase_1  | 	Connection matched pg_hba.conf line 95: "host all all all md5"
codiMdApp_1       | 2020-05-07T14:25:29.894Z error: 	revision saver failed: SequelizeConnectionError: password authentication failed for user "hackmd"
codiMdDatabase_1  | FATAL:  password authentication failed for user "hackmd"
codiMdDatabase_1  | DETAIL:  Role "hackmd" does not exist.
codiMdDatabase_1  | 	Connection matched pg_hba.conf line 95: "host all all all md5"
codiMdApp_1       | 2020-05-07T14:30:29.881Z error: 	revision saver failed: SequelizeConnectionError: password authentication failed for user "hackmd"

@codefriar
Copy link
Author

@SISheogorath - Important Update.

Renaming the database service, coupled with using Mariadb works.

@SISheogorath
Copy link
Contributor

Maybe you have to reset the database volumes in order to make everything work as expected, but that sounds like it goes in the right direction :)

If you want to do me a personal favor, you also change the name of database and user, as well as the password, after resetting your db storage 😉

@codefriar
Copy link
Author

That did the trick. And yeah, I changed the name of the user and database as well as the password! Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants