Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Admin user fails in rocketchat

I have been running rocketchat on a cloud instance. I have used the parameters specified on the below document in rocketchat for creating admin user through docker-compose in yaml file.

https://docs.rocket.chat/guides/administrator-guides/create-the-first-admin

I am not able to create a admin user as my variables are correctly specified.

docker-compose.yaml

version: '3.8'

services:
  rocketchat:
    image: rocketchat/rocket.chat:latest
    container_name: $ROCKETCHAT_CONTAINER_NAME
    command: >
      bash -c
        "for i in `seq 1 30`; do
          node main.js &&
          s=$$? && break || s=$$?;
          echo \"Tried $$i times. Waiting 5 secs...\";
          sleep 5;
        done; (exit $$s)"
    restart: unless-stopped
    volumes:
      - ./uploads:/app/uploads
    depends_on:
      - mongo
    environment:
      - PORT=3000
      - ROOT_URL=http://xxxxxxxxx:3000
      - MONGO_URL=mongodb://mongo:27017/rocketchat
      - MONGO_OPLOG_URL=mongodb://mongo:27017/local
      - MAIL_URL=smtp://smtp.email
      - ADMIN_USERNAME=admin
      - ADMIN_PASS=password
      - [email protected]
    ports:
      - 3000:$ROCKETCHAT_PORT
    labels:
      - "traefik.backend=rocketchat"
      - "traefik.frontend.rule=Host: your.domain.tld"
    networks:
      - $ROCKETCHAT_NETWORK

  mongo:
    image: mongo:$MONGO_IMAGE_TAG
    container_name: $MONGO_CONTAINER_NAME
    restart: unless-stopped
    volumes:
     - ./data/db:/data/db
    command: mongod --smallfiles --oplogSize 128 --replSet rs0 --storageEngine=mmapv1
    env_file: .env
    labels:
      - "traefik.enable=false"
    networks:
      - $ROCKETCHAT_NETWORK

  mongo-init-replica:
    image: mongo:$MONGO_IMAGE_TAG
    container_name: $MONGO_REPLICA_CONTAINER_NAME
    command: >
      bash -c
        "for i in `seq 1 30`; do
          mongo mongo/rocketchat --eval \"
            rs.initiate({
              _id: 'rs0',
              members: [ { _id: 0, host: 'localhost:27017' } ]})\" &&
          s=$$? && break || s=$$?;
          echo \"Tried $$i times. Waiting 5 secs...\";
          sleep 5;
        done; (exit $$s)"
    depends_on:
      - mongo
    env_file: .env
    networks:
      - $ROCKETCHAT_NETWORK

networks:
  rocketchat:
like image 410
klee Avatar asked Dec 09 '20 09:12

klee


People also ask

How do I change the channel owner on Rocketchat?

If you need to grant the ownership of your workspace to another person or to change the primary email of your workspace - submit a ticket here on our Helpdesk or drop us an email to [email protected] with the respective request.


1 Answers

I wasn't been able to reproduce the problem, although there is one common pitfall that you may have encountered. Tl;dr: if you run this several times on one machine in the same directory - it's most likely mongo's storage. After first setup it creates ./data directory where it keeps user accounts and everything else. If you created admin once, it won't go through this again.

Normally, if you run run rocket.chat without these variables, it allows you to create an admin account via the web interface. When you set environment variables it may get into this piece of code: programs/server/app/app.js:

...
    if (process.env.ADMIN_PASS) {
      if (_.isEmpty(getUsersInRole('admin').fetch())) {
...

But as you see there is a second check for any user in 'admin' role. In other words, environment variables are only used when there is no one in the role yet.

If it does use the variables, you will see something like this in the container logs:

Inserting admin user:
Name: Administrator
Email: [email protected]
Username: admin

If it does not, you'll see a line like this:

Users with admin role already exist; Ignoring environment variables ADMIN_PASS

The most obvious reason why this can happen is that you ran the compose file before with different set of credentials or registered an account via the web GUI. After that admin user was saved in the database, which (in your compose file) keeps its data outside the container, so it is persistent between restarts. If what I said about previous launch was true for you and you want to start from the beginning - remove ./data directory from where your compose file is. It is there mongo saves the data.

like image 150
anemyte Avatar answered Oct 22 '22 02:10

anemyte