Skip to content
This repository has been archived by the owner on May 20, 2022. It is now read-only.

mattermost cli tries to connect to localhost:5432 #399

Closed
ccoenen opened this issue Jul 7, 2019 · 5 comments
Closed

mattermost cli tries to connect to localhost:5432 #399

ccoenen opened this issue Jul 7, 2019 · 5 comments

Comments

@ccoenen
Copy link

ccoenen commented Jul 7, 2019

When I try to use the mattermost cli from within my container, this happens:

# docker exec mattermostdocker_app_1 mattermost user create --email test@example.com --username test2
{"level":"error","ts":1562494056.6862624,"caller":"sqlstore/supplier.go:236","msg":"Failed to ping DB retrying in 10 seconds err=dial tcp 127.0.0.1:5432: connect: connection refused"}
{"level":"error","ts":1562494066.6901321,"caller":"sqlstore/supplier.go:236","msg":"Failed to ping DB retrying in 10 seconds err=dial tcp 127.0.0.1:5432: connect: connection refused"}
{"level":"error","ts":1562494076.6942267,"caller":"sqlstore/supplier.go:236","msg":"Failed to ping DB retrying in 10 seconds err=dial tcp 127.0.0.1:5432: connect: connection refused"}
{"level":"error","ts":1562494086.6983554,"caller":"sqlstore/supplier.go:236","msg":"Failed to ping DB retrying in 10 seconds err=dial tcp 127.0.0.1:5432: connect: connection refused"}
...

for some reason it does not pick up the database configuration from the config.json and tries to connect to localhost instad. This also happens if I explicitly load my config with --config /mattermost/config/config.json. The server itself is running fine, it's just the CLI that does not work for me.

@ccoenen
Copy link
Author

ccoenen commented Jul 7, 2019

I found out that I need to manually set SqlSettings.DataSource, I set mine to the output that the app entrypoint would generate here:

export MM_SQLSETTINGS_DATASOURCE="postgres://$MM_USERNAME:$ENCODED_PASSWORD@$DB_HOST:$DB_PORT_NUMBER/$MM_DBNAME?sslmode=disable&connect_timeout=10"

(with the exception of ENCODED_PASSWORD, which did not work for me, i put my plaintext default postgres docker container password in there).

@ccoenen ccoenen closed this as completed Jul 7, 2019
@Klagio
Copy link

Klagio commented Jun 5, 2020

SqlSettings.DataSource

I have the same error, but I do not understand what to put in Datasource (can you tell me hopw/where to launch export ....) sorry do not understand much

@mahenzon
Copy link

I have the same issue when deploying to AWS Beanstalk
I tried to configure DB conn via MM_SQLSETTINGS_DATASOURCE, I tried to go with default settings - no matter, it didn't help. Why does it even trying to ping 127.0.0.1?

{"level":"info","ts":1611717090.639141,"caller":"app/server.go:225","msg":"Server is initializing..."}
{"level":"info","ts":1611717090.643723,"caller":"app/web_hub.go:83","msg":"Starting websocket hubs","number_of_hubs":2}
{"level":"info","ts":1611717090.6494966,"caller":"utils/i18n.go:90","msg":"Loaded system translations","for locale":"en","from locale":"/mattermost/i18n/en.json"}
{"level":"debug","ts":1611717090.6509674,"caller":"utils/html.go:30","msg":"Parsing server templates","templates_directory":"/mattermost/templates"}
{"level":"debug","ts":1611717090.654551,"caller":"app/web_hub.go:413","msg":"Hub is starting","index":0}
{"level":"debug","ts":1611717090.6554153,"caller":"app/web_hub.go:413","msg":"Hub is starting","index":1}
{"level":"info","ts":1611717090.6726096,"caller":"sqlstore/supplier.go:246","msg":"Pinging SQL","database":"master"}
{"level":"error","ts":1611717090.679074,"caller":"sqlstore/supplier.go:258","msg":"Failed to ping DB","error":"dial tcp 127.0.0.1:5432: connect: connection refused","retrying in seconds":10}
{"level":"info","ts":1611717100.6793468,"caller":"sqlstore/supplier.go:246","msg":"Pinging SQL","database":"master"}
{"level":"error","ts":1611717100.681144,"caller":"sqlstore/supplier.go:258","msg":"Failed to ping DB","error":"dial tcp 127.0.0.1:5432: connect: connection refused","retrying in seconds":10}

@mahenzon
Copy link

ok, I changed EBS config to be able to enter EC2 instance using SSH
I checked configs. And you know what? it uses this conn string postgres://mmuser:mostest@postgres/mattermost_test?sslmode=disable\u0026connect_timeout=10
no matter I tried to set up MM_SQLSETTINGS_DATASOURCE or all the MM_USERNAME, MM_PASSWORD, DB_HOST, DB_PORT_NUMBER, MM_DBNAME

Screenshot 2021-01-28 at 01 09 10

I manually edited config file and finally app is up and running.

I'm sure you need to update images and docs, because this needs to be fixed

I already patched app's Dockerfile and entrypoint.sh, so it grants privileges on start (#407)
https://github.com/mahenzon/mattermost-docker/blob/master/app/ (build is available at https://hub.docker.com/r/mahenzon/mattermost-enterprise now). Without this patch the app could not even create the config file

@mahenzon
Copy link

I spent some time configuring server, but got in a situation a couple of times when config gets reseted to defaults. That's very strange. What can trigger such behaviour?

Also, could not create a team, getting the error like here https://forum.mattermost.org/t/problem-with-installation/5347/8 (Team creation failed: Team.IsValid: This URL is unavailable. Please try another)
but when I created a team with a long custom name, it was created successfully, and then I edited the name in db and it's working fine. Strange.

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

No branches or pull requests

3 participants