8000 Can not connect to MongoDB? · Issue #1318 · overleaf/overleaf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Can not connect to MongoDB? #1318

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 stateme 8000 nt. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lizhi10 opened this issue Feb 27, 2025 · 3 comments
Open

Can not connect to MongoDB? #1318

lizhi10 opened this issue Feb 27, 2025 · 3 comments

Comments

@lizhi10
Copy link
lizhi10 commented Feb 27, 2025

Hi there!
I am trying to deploy Overleaf on my NAS which is running OpenWRT. Since my NAS uses a CPU which does not support AVX (required by MongoDB 5.0), I decide to deploy Overleaf 4.1.1.
However, it says

sharelatex | Cannot connect to mongodb sharelatex | MongooseServerSelectionError: connect ECONNREFUSED 172.26.0.1:27017 sharelatex | at Connection.openUri (/overleaf/services/web/node_modules/mongoose/lib/connection.js:825:32) sharelatex | at /overleaf/services/web/node_modules/mongoose/lib/index.js:414:10 sharelatex | at /overleaf/services/web/node_modules/mongoose/lib/helpers/promiseOrCallback.js:41:5 sharelatex | at new Promise (<anonymous>) sharelatex | at promiseOrCallback (/overleaf/services/web/node_modules/mongoose/lib/helpers/promiseOrCallback.js:40:10) sharelatex | at Mongoose._promiseOrCallback (/overleaf/services/web/node_modules/mongoose/lib/index.js:1288:10) sharelatex | at Mongoose.connect (/overleaf/services/web/node_modules/mongoose/lib/index.js:413:20) sharelatex | at Object.<anonymous> (/overleaf/services/web/app/src/infrastructure/Mongoose.js:19:36) sharelatex | at Module._compile (node:internal/modules/cjs/loader:1256:14) sharelatex | at Module._extensions..js (node:internal/modules/cjs/loader:1310:10) { sharelatex | reason: TopologyDescription { sharelatex | type: 'Unknown', sharelatex | servers: Map(1) { 'dockerhost:27017' => [ServerDescription] }, sharelatex | stale: false, sharelatex | compatible: true, sharelatex | heartbeatFrequencyMS: 10000, sharelatex | localThresholdMS: 15, sharelatex | setName: null, sharelatex | maxElectionId: null, sharelatex | maxSetVersion: null, sharelatex | commonWireVersion: 0, sharelatex | logicalSessionTimeoutMinutes: null sharelatex | }, sharelatex | code: undefined sharelatex | } sharelatex | *** /etc/my_init.d/98_check_db_access.sh failed with status 1 sharelatex | sharelatex | *** Killing all processes...

The .yml file I use is
`version: '2.2'
services:
sharelatex:
restart: always
# Server Pro users:
# image: quay.io/sharelatex/sharelatex-pro
image: sharelatex:4.1.1
container_name: sharelatex
depends_on:
mongo:
condition: service_healthy
redis:
condition: service_started
ports:
- 5555:80
stop_grace_period: 60s
volumes:
- ~/sharelatex_data:/var/lib/overleaf
########################################################################
#### Server Pro: Uncomment the following line to mount the docker ####
#### socket, required for Sibling Containers to work ####
########################################################################
# - /var/run/docker.sock:/var/run/docker.sock
environment:

        OVERLEAF_APP_NAME: Overleaf Community Edition

        OVERLEAF_MONGO_URL: mongodb://mongo/sharelatex

        # Same property, unfortunately with different names in
        # different locations
        OVERLEAF_REDIS_HOST: redis
        REDIS_HOST: redis

        ENABLED_LINKED_FILE_TYPES: 'project_file,project_output_file'

        # Enables Thumbnail generation using ImageMagick
        ENABLE_CONVERSIONS: 'true'

        # Disables email confirmation requirement
        EMAIL_CONFIRMATION_DISABLED: 'true'

        ## Set for SSL via nginx-proxy
        #VIRTUAL_HOST: 103.112.212.22

        # OVERLEAF_SITE_URL: http://overleaf.example.com
        # OVERLEAF_NAV_TITLE: Overleaf Community Edition
        # OVERLEAF_HEADER_IMAGE_URL: http://example.com/mylogo.png
        # OVERLEAF_ADMIN_EMAIL: support@it.com

        # OVERLEAF_LEFT_FOOTER: '[{"text": "Another page I want to link to can be found <a href=\"here\">here</a>"} ]'
        # OVERLEAF_RIGHT_FOOTER: '[{"text": "Hello I am on the Right"} ]'

        # OVERLEAF_EMAIL_FROM_ADDRESS: "hello@example.com"

        # OVERLEAF_EMAIL_AWS_SES_ACCESS_KEY_ID:
        # OVERLEAF_EMAIL_AWS_SES_SECRET_KEY:

        # OVERLEAF_EMAIL_SMTP_HOST: smtp.example.com
        # OVERLEAF_EMAIL_SMTP_PORT: 587
        # OVERLEAF_EMAIL_SMTP_SECURE: false
        # OVERLEAF_EMAIL_SMTP_USER:
        # OVERLEAF_EMAIL_SMTP_PASS:
        # OVERLEAF_EMAIL_SMTP_TLS_REJECT_UNAUTH: true
        # OVERLEAF_EMAIL_SMTP_IGNORE_TLS: false
        # OVERLEAF_EMAIL_SMTP_NAME: '127.0.0.1'
        # OVERLEAF_EMAIL_SMTP_LOGGER: true
        # OVERLEAF_CUSTOM_EMAIL_FOOTER: "This system is run by department x"

        # ENABLE_CRON_RESOURCE_DELETION: true

        ################
        ## Server Pro ##
        ################

        ## Sandboxed Compiles: https://github.com/overleaf/overleaf/wiki/Server-Pro:-Sandboxed-Compiles
        SANDBOXED_COMPILES: 'true'
        SANDBOXED_COMPILES_SIBLING_CONTAINERS: 'true'
        ### Bind-mount source for /var/lib/overleaf/data/compiles inside the container.
        SANDBOXED_COMPILES_HOST_DIR: '/home/user/sharelatex_data/data/compiles'

        ## Works with test LDAP server shown at bottom of docker compose
        # OVERLEAF_LDAP_URL: 'ldap://ldap:389'
        # OVERLEAF_LDAP_SEARCH_BASE: 'ou=people,dc=planetexpress,dc=com'
        # OVERLEAF_LDAP_SEARCH_FILTER: '(uid={{username}})'
        # OVERLEAF_LDAP_BIND_DN: 'cn=admin,dc=planetexpress,dc=com'
        # OVERLEAF_LDAP_BIND_CREDENTIALS: 'GoodNewsEveryone'
        # OVERLEAF_LDAP_EMAIL_ATT: 'mail'
        # OVERLEAF_LDAP_NAME_ATT: 'cn'
        # OVERLEAF_LDAP_LAST_NAME_ATT: 'sn'
        # OVERLEAF_LDAP_UPDATE_USER_DETAILS_ON_LOGIN: 'true'

        # OVERLEAF_TEMPLATES_USER_ID: "578773160210479700917ee5"
        # OVERLEAF_NEW_PROJECT_TEMPLATE_LINKS: '[ {"name":"All Templates","url":"/templates/all"}]'


        # OVERLEAF_PROXY_LEARN: "true"

mongo:
    restart: always
    image: mongo:4.4
    container_name: mongo
    command: "--replSet overleaf"
    expose:
      - 27017
    volumes:
      - ./mongo_data:/data/db
    healthcheck:
      test: echo 'db.stats().ok' | mongo localhost:27017/test --quiet
      interval: 10s
      timeout: 10s
      retries: 5
      
mongoinit:
    image: mongo:4.4
    # this container will exit after executing the command
    restart: "no"
    depends_on:
      mongo:
        condition: service_healthy
    entrypoint:
      [
        "mongo",
        "--host",
        "mongo:27017",
        "--eval",
        'rs.initiate({ _id: "overleaf", members: [ { _id: 0, host: "mongo:27017" } ] })',
      ]          
#mongo:
    #restart: always
    #image: mongo:6.0
    #container_name: mongo
    #command: '--replSet overleaf'
    #volumes:
    #    - ~/mongo_data:/data/db
    #    - ./server-ce/mongodb-init-replica-set.js:/docker-entrypoint-initdb.d/mongodb-init-replica-set.js
    #environment:
    #  MONGO_INITDB_DATABASE: sharelatex
    #extra_hosts:
      # Required when using the automatic database setup for initializing the replica set.
      # This override is not needed when running the setup after starting up mongo.
      #- mongo:127.0.0.1
    #healthcheck:
    #    test: echo 'db.stats().ok' | mongo localhost:27017/test --quiet
    #    interval: 10s
    #    timeout: 10s
    #    retries: 5

redis:
    restart: always
    image: redis:6.2
    container_name: redis
    volumes:
        - ~/redis_data:/data

# ldap:
#    restart: always
#    image: rroemhild/test-openldap
#    container_name: ldap

# See https://github.com/jwilder/nginx-proxy for documentation on how to configure the nginx-proxy container,
# and https://github.com/overleaf/overleaf/wiki/HTTPS-reverse-proxy-using-Nginx for an example of some recommended
# settings. We recommend using a properly managed nginx instance outside of the Overleaf Server Pro setup,
# but the example here can be used if you'd prefer to run everything with docker-compose

# nginx-proxy:
#     image: jwilder/nginx-proxy
#     container_name: nginx-proxy
#     ports:
#       - "80:80"
#       - "443:443"
#     volumes:
#       - /var/run/docker.sock:/tmp/docker.sock:ro
#       - /home/overleaf/tmp:/etc/nginx/certs

`

Thank you in advance!

@phamduchongan93
Copy link

same thing happen to my deployment.
`anpham@anpham-Latitude-5490:/tmp/k8s$ kubectl logs pods/overleaf-c45fdc669-zgpk8
*** Running /etc/my_init.d/000_check_for_old_bind_mounts_5.sh...
*** Running /etc/my_init.d/000_check_for_old_env_vars_5.sh...
*** Running /etc/my_init.d/00_regen_ssh_host_keys.sh...
*** Running /etc/my_init.d/100_generate_secrets.sh...
generating random secrets
*** Running /etc/my_init.d/100_make_overleaf_data_dirs.sh...
*** Running /etc/my_init.d/100_restore_site_status.sh...
*** Running /etc/my_init.d/100_set_docker_host_ipaddress.sh...
*** Running /etc/my_init.d/10_syslog-ng.init...
Mar 18 07:41:39 overleaf-c45fdc669-zgpk8 syslog-ng[87]: syslog-ng starting up; version='4.3.1'
*** Running /etc/my_init.d/200_nginx_config_template.sh...
Nginx: generating config file from template
Checking Nginx config
nginx: the configuration file /etc/nginx/nginx.conf syntax i 8000 s ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Nginx: reloading config

  • Reloading nginx configuration nginx
    ...done.
    *** Running /etc/my_init.d/300_delete_old_logs.sh...
    *** Running /etc/my_init.d/500_check_db_access.sh...
    Checking can connect to mongo and redis
    Using default settings from /overleaf/services/web/config/settings.defaults.js
    Using settings from /etc/overleaf/settings.js
    Set UV_THREADPOOL_SIZE=16
    {"name":"default","hostname":"overleaf-c45fdc669-zgpk8","pid":116,"level":50,"error":{"message":"connect ECONNREFUSED 10.244.0.1:27017","name":"MongooseServerSelectionError","stack":"MongooseServerSelectionError: connect ECONNREFUSED 10.244.0.1:27017\n at _handleConnectionErrors (/overleaf/services/web/node_modules/mongoose/lib/connection.js:909:11)\n at NativeConnection.openUri (/overleaf/services/web/node_modules/mongoose/lib/connection.js:860:11)","info":{}},"msg":"Failed to connect to MongoDB - cannot set up monitoring","time":"2025-03-18T07:42:40.717Z","v":0}
    {"name":"default","hostname":"overleaf-c45fdc669-zgpk8","pid":116,"level":50,"err":{"message":"connect ECONNREFUSED 10.244.0.1:27017","name":"MongoServerSelectionError","stack":"MongoServerSelectionError: connect ECONNREFUSED 10.244.0.1:27017\n at Topology.selectServer (/overleaf/services/web/node_modules/mongodb/lib/sdam/topology.js:303:38)\n at async Topology._connect (/overleaf/services/web/node_modules/mongodb/lib/sdam/topology.js:196:28)\n at async Topology.connect (/overleaf/services/web/node_modules/mongodb/lib/sdam/topology.js:158:13)\n at async topologyConnect (/overleaf/services/web/node_modules/mongodb/lib/mongo_client.js:223:17)\n at async MongoClient._connect (/overleaf/services/web/node_modules/mongodb/lib/mongo_client.js:236:13)\n at async MongoClient.connect (/overleaf/services/web/node_modules/mongodb/lib/mongo_client.js:161:13)\n at async NativeConnection.createClient (/overleaf/services/web/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:320:3)\ncaused by:\n MongoNetworkError: connect ECONNREFUSED 10.244.0.1:27017\n at connectionFailureError (/overleaf/services/web/node_modules/mongodb/lib/cmap/connect.js:356:20)\n at Socket. (/overleaf/services/web/node_modules/mongodb/lib/cmap/connect.js:272:44)\n at Object.onceWrapper (node:events:633:26)\n at Socket.emit (node:events:518:28)\n at emitErrorNT (node:internal/streams/destroy:169:8)\n at emitErrorCloseNT (node:internal/streams/destroy:128:3)\n at process.processTicksAndRejections (node:internal/process/task_queues:82:21)\n caused by:\n Error: connect ECONNREFUSED 10.244.0.1:27017\n at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1611:16)","info":{}},"msg":"mongoose error on default connection","time":"2025-03-18T07:42:40.719Z","v":0}
    Cannot connect to mongodb
    MongoServerSelectionError: connect ECONNREFUSED 10.244.0.1:27017
    at Topology.selectServer (/overleaf/node_modules/mongodb/lib/sdam/topology.js:320:38)
    at async Topology._connect (/overleaf/node_modules/mongodb/lib/sdam/topology.js:204:28)
    at async Topology.connect (/overleaf/node_modules/mongodb/lib/sdam/topology.js:156:13)
    at async topologyConnect (/overleaf/node_modules/mongodb/lib/mongo_client.js:233:17)
    at async LegacyMongoClient._connect (/overleaf/node_modules/mongodb/lib/mongo_client.js:246:13)
    at async LegacyMongoClient.connect (/overleaf/node_modules/mongodb/lib/mongo_client.js:171:13)
    at async main (file:///overleaf/services/web/modules/server-ce-scripts/scripts/check-mongodb.mjs:14:19) {
    reason: TopologyDescription {
    type: 'Unknown',
    servers: Map(1) { 'dockerhost:27017' => [ServerDescription] },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: null,
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
    },
    code: undefined,
    [Symbol(errorLabels)]: Set(0) {},
    [cause]: MongoNetworkError: connect ECONNREFUSED 10.244.0.1:27017
    at Socket. (/overleaf/node_modules/mongodb/lib/cmap/connect.js:285:44)
    at Object.onceWrapper (node:events:633:26)
    at Socket.emit (node:events:518:28)
    at emitErrorNT (node:internal/streams/destroy:169:8)
    at emitErrorCloseNT (node:internal/streams/destroy:128:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
    [Symbol(errorLabels)]: Set(1) { 'ResetPool' },
    [cause]: Error: connect ECONNREFUSED 10.244.0.1:27017
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1611:16) {
    errno: -111,
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '10.244.0.1',
    port: 27017
    }
    }
    }
    *** /etc/my_init.d/500_check_db_access.sh failed with status 1

*** Killing all processes...
Mar 18 07:42:40 overleaf-c45fdc669-zgpk8 syslog-ng[87]: syslog-ng shutting down; version='4.3.1'
`

@blinkbear
Copy link

+1

@blinkbear
Copy link

It can be solved by executing:

docker exec -it mongo mongosh --eval "rs.initiate({
  _id: 'overleaf',
  members: [
    { _id: 0, host: 'mongo:27017' }
  ]
})"

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

No branches or pull requests

4 participants
0