linuxserver / docker-unifi-network-application

GNU General Public License v3.0
723 stars 54 forks source link

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

Closed metron2 closed 5 months ago

metron2 commented 5 months ago

Is there an existing issue for this?

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
github-actions[bot] commented 5 months ago

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

aptalca commented 5 months ago

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

exodious commented 5 months ago

@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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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.