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

[BUG] README.md wrong for Mongo 7 #93

Closed
1 task done
metron2 opened this issue Jun 22, 2024 · 6 comments
Closed
1 task done

[BUG] README.md wrong for Mongo 7 #93

metron2 opened this issue Jun 22, 2024 · 6 comments

Comments

@metron2
Copy link

metron2 commented Jun 22, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

If you follow the current instructions, unifi can't connect to the unifi_stat database on startup. The correct init-db.js is:

db.getSiblingDB("unifi").createUser({user: "unifi", pwd: "password", roles: [{role: "dbOwner", db: "unifi"}, {role: "dbOwner", db: "unifi_stat"}]});

Expected Behavior

This should work

Steps To Reproduce

Follow the readme using mongo:7

Environment

- OS: OpenSuse tumbleweed

CPU architecture

x86-64

Docker creation

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert --volumes hostPath -f /home/derek/git/docker-compose/docker-compose.yml
    kompose.version: 1.31.2 (a92241f79)
  labels:
    io.kompose.service: unifi
  name: unifi
  namespace: default
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      io.kompose.service: unifi
  strategy:
    type: Recreate
  template:
    metadata:
      annotations:
        kompose.version: 1.31.2 (a92241f79)
        kubectl.kubernetes.io/restartedAt: "2024-02-21T23:36:16-05:00"
      labels:
        io.kompose.network/docker-compose-default: "true"
        io.kompose.service: unifi
    spec:
      containers:
      - env:
        - name: PGID
          value: "139"
        - name: PUID
          value: "137"
        - name: TZ
          value: "Etc/UTC"
        - name: MONGO_USER
          value: "unifi"
        - name: MONGO_PASS
          valueFrom:
            secretKeyRef:
              key: password
              name: mongo-password
        - name: MONGO_DBNAME
          value: "unifi"
        - name: MONGO_HOST
          value: "mongodb.home.mtr.red"
        - name: MONGO_PORT
          value: "27017"
        image: lscr.io/linuxserver/unifi-network-application:latest
        imagePullPolicy: Always
        name: unifi
        ports:
        - containerPort: 3478
          hostPort: 3478
          protocol: UDP
        - containerPort: 10001
          hostPort: 10001
          protocol: UDP
        - containerPort: 8080
          hostPort: 8080
          protocol: TCP
        - containerPort: 8443
          hostPort: 8443
          protocol: TCP
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /config
          name: unifi-config
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
      - hostPath:
          path: /storage/unifi/config
          type: ""
        name: unifi-config

Container logs

I didn't get the logs it's just a standard connection failed error for unifi_stat
Copy link

Thanks for opening your first issue here! Be sure to follow the relevant issue templates, or risk having this issue marked as invalid.

@aptalca
Copy link
Member

aptalca commented Jun 23, 2024

The readme is correct and it worked for a lot of people including several team members.

@aptalca aptalca closed this as not planned Won't fix, can't repro, duplicate, stale Jun 23, 2024
@exodious
Copy link

@metron2 were you perchance using the bitnami mongodb helm chart or image? I was having the same exact problem, even tried going back to a chart version that used a 6.x mongodb. Your suggestion resolved the issue for me.

@metron2
Copy link
Author

metron2 commented Jun 24, 2024

I'm using mongo:7 currently and this resolved my problems with it. I tried to use the bitnami/mongodb chart instead but it didn't work either because it initializes two separate users.

To be honest, I dislike that chart already and I don't want a replicaset. I just wrote a deployment yaml for the official image instead. It was easier to change the initialization javascript to grant the same unifi user permission both databases. I found this advice on this repo but for a different version of mongodb.

@metron2
Copy link
Author

metron2 commented Jun 24, 2024

Here's the deployment I'm using. I'm using fluxcd to automatically patch everything, but it's looking for mongo:7 tags.

apiVersion: v1
kind: ConfigMap
metadata:
  name: mongodb-config
data:
  init-db.js: |
    db.getSiblingDB("unifi").createUser({user: "unifi", pwd: "password", roles: [{role: "dbOwner", db: "unifi"}, {role: "dbOwner", db: "unifi_stat"}]});
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongodb-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongodb
  template:
    metadata:
      labels:
        app: mongodb
    spec:
      containers:
        - name: mongodb
          image: mongo:7.0.11 # {"$imagepolicy": "default:mongo" }
          env:
            - name: MONGO_INITDB_ROOT_USERNAME
              value: "root"
            - name: MONGO_INITDB_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: root
                  name: mongo-password
          ports:
            - containerPort: 27017
              protocol: TCP
          volumeMounts:
            - name: mongodb-data
              mountPath: /storage/mongodb # Host storage path
            - name: config-volume
              mountPath: /docker-entrypoint-initdb.d/
      volumes:
        - name: mongodb-data
          persistentVolumeClaim:
            claimName: mongodb-pvc
        - name: config-volume
          configMap:
            name: mongodb-config
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  namespace: default
  name: mongodb-pvc
spec:
  storageClassName: local-path
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 50Gi

@aptalca
Copy link
Member

aptalca commented Jun 24, 2024

Looks like you guys missed this part in the readme:

If you are using the init JS method do not also set MONGO_INITDB_ROOT_USERNAME, MONGO_INITDB_ROOT_PASSWORD, or any other "INITDB" values as they will cause conflicts. Setting these variables for the .sh file is necessary

Locking this thread so as not to confuse other users with conflicting info.

@linuxserver linuxserver locked as off-topic and limited conversation to collaborators Jun 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Development

No branches or pull requests

3 participants