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

[Request] for an example of Unifi-Network-Application from linuxserver.io #16

Closed
Ciberbago opened this issue Sep 11, 2023 · 16 comments
Closed

Comments

@Ciberbago
Copy link

What FOSS project is currently missing. Provide names and links.

Does an example docker-compose.yml exist?

  • [0] - Yes, managed by the FOSS maintainer. See links below.

It exists... but requires external mongodb and I don't have the required knowledge to do that. I would like a ready to use example please.

Here some links to pre-existing docker-compose examples:

  • <link1>
    It's only on the readme section of the repo.

Describe alternatives you've considered
I've searched for someone with an example but it's too new and there are none.

Additional context
I know it's not FOSS, but currently I'm using unifi-controller from linuxserver.io but they say, they are going to deprecate that image. I need to be ready when the time comes.

@Ciberbago Ciberbago changed the title Request for an example of Unifi-Network-Application from linuxserver.io [Request] for an example of Unifi-Network-Application from linuxserver.io Sep 11, 2023
@l4rm4nd
Copy link
Member

l4rm4nd commented Sep 25, 2023

Hi @Ciberbago,

thanks for reaching out.

The documentation provided by Linuxserver is quite good. However, I understand where you are coming from. Adjusting the docker-compose.yml with a proper mongo db service is not that straight forward.

Nonetheless, I've done some research and crafted a (hopefully) working compose file:

---
version: "2.1"
services:
  unifi-network-application:
    image: lscr.io/linuxserver/unifi-network-application:latest
    container_name: unifi-network-application
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC
      - MONGO_USER=unifi
      - MONGO_PASS=unifi
      - MONGO_HOST=unifi-db
      - MONGO_PORT=27017
      - MONGO_DBNAME=unifi-db
      - MEM_LIMIT=1024 #optional
      - MEM_STARTUP=1024 #optional
    volumes:
      - ${DOCKER_VOLUME_STORAGE:-/mnt/docker-volumes}/unifi-network-application/config:/config
    depends_on:
      - unifi-db
    ports:
      - 8443:8443
      - 3478:3478/udp
      - 10001:10001/udp
      - 8080:8080
      - 1900:1900/udp #optional
      - 8843:8843 #optional
      - 8880:8880 #optional
      - 6789:6789 #optional
      - 5514:5514/udp #optional
    restart: unless-stopped

  unifi-db:
    image: mongo:4.4
    container_name: unifi-network-application-mongodb
    restart: unless-stopped
    expose:
      - 27017
    environment:
      - MONGO_INITDB_DATABASE=unifi-db
    volumes:
      - ${DOCKER_VOLUME_STORAGE:-/mnt/docker-volumes}/unifi-network-application/mongodb_data:/data/db
      - ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro

Note that you are mounting a file named init-mongo.js into the mongo db container. This file is necessary to initialize the mongo database (see https://hub.docker.com/_/mongo/ at "Initializing a fresh instance"). It basically defines the database name and user credentials for the unifi-network-application container.

The file contains the following content:

db.getSiblingDB("unifi-db").createUser({user: "unifi", pwd: "unifi", roles: [{role: "readWrite", db: "unifi-db"}]});
db.getSiblingDB("unifi-db_stat").createUser({user: "unifi", pwd: "unifi", roles: [{role: "readWrite", db: "unifi-db_stat"}]});

These parameters are also referenced in the docker-compose.yml file above. So either leave as is or adjust everywhere accordingly. May have a try and give feedback whether my example works.

As long as the given example is unconfirmed, I will not include it to this repository.

@l4rm4nd l4rm4nd closed this as completed Sep 25, 2023
@Ciberbago
Copy link
Author

Hello! Thank you for all your work, I wanted to apologize, I've been busy and just had the time to check it out. I tried just like you said and it worked beautifully. I created the file with the config, then the docker compose mounting the config, db folders and the init file.

Using stacks on portainer I started the stack and everything just worked. I just had to backup my old unifi controller server and restore it in this new one.

So... I think you could include this one on your examples as a success :)

@l4rm4nd
Copy link
Member

l4rm4nd commented Oct 28, 2023

Hello! Thank you for all your work, I wanted to apologize, I've been busy and just had the time to check it out. I tried just like you said and it worked beautifully. I created the file with the config, then the docker compose mounting the config, db folders and the init file.

Using stacks on portainer I started the stack and everything just worked. I just had to backup my old unifi controller server and restore it in this new one.

So... I think you could include this one on your examples as a success :)

Thank you for the confirmation.

Added to the repo. See 910b53c

@rgars
Copy link

rgars commented Nov 21, 2023

Trying to use this, but wondering where the init-mongo.js file should be placed so that it is found by portainer when the initial deployment takes place?

@l4rm4nd
Copy link
Member

l4rm4nd commented Nov 21, 2023

Trying to use this, but wondering where the init-mongo.js file should be placed so that it is found by portainer when the initial deployment takes place?

You specify the path to the init file via the compose volume key. The init file basically is stored in the same directory where you put the compose file.

I personally do not like starting stacks within Portainer as it abstracts the file system. You would have to manually put the init file somewhere on your server where portainer can access it and then define the absolute path in the compose file.

@rgars
Copy link

rgars commented Nov 21, 2023

Thanks for the reply. I had put init-mongo.js in /home/pi, and put that path in the compose statements, but Mongo doesn't seem to have got the right connections. The container log has the following:-
t={"$date":"2023-11-21T17:07:31.694+00:00"} s=I c=ACCESS id=20249 ctx=conn10169 msg=Authentication failed attr={"mechanism":"SCRAM-SHA-256","speculative":true,"principalName":"unifi","authenticationDatabase":"unifi-db","remote":"172.18.0.3:37178","extraInfo":{},"error":"UserNotFound: Could not find user "unifi" for db "unifi-db""}

@l4rm4nd
Copy link
Member

l4rm4nd commented Nov 21, 2023

Thanks for the reply. I had put init-mongo.js in /home/pi, and put that path in the compose statements, but Mongo doesn't seem to have got the right connections. The container log has the following:-
t={"$date":"2023-11-21T17:07:31.694+00:00"} s=I c=ACCESS id=20249 ctx=conn10169 msg=Authentication failed attr={"mechanism":"SCRAM-SHA-256","speculative":true,"principalName":"unifi","authenticationDatabase":"unifi-db","remote":"172.18.0.3:37178","extraInfo":{},"error":"UserNotFound: Could not find user "unifi" for db "unifi-db""}

May remove all volume bind mounts and try again, if you have previously started the container stack. This removes the database and you can start freshly.

Ensure to only adjust the left side of the bind mount definition, which is your host's path. The right side stays the same; as it is the internal docker container path.

@rightsaidfred99
Copy link

rightsaidfred99 commented Dec 24, 2023

Anyone know how to get it to work on a pi? I've modified it

`---
version: "2.1"
services:
  unifi-network-application:
    image: lscr.io/linuxserver/unifi-network-application:arm64v8-latest
    container_name: unifi-network-application
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC
      - MONGO_USER=unifi
      - MONGO_PASS=unifi
      - MONGO_HOST=unifi-db
      - MONGO_PORT=27017
      - MONGO_DBNAME=unifi-db

    volumes:
      - /home/pi/docker/unifinetwork/app:/config
    depends_on:
      - unifi-db
    ports:
      - 8443:8443
      - 3478:3478/udp
      - 10001:10001/udp
      - 8080:8080
    restart: unless-stopped

  unifi-db:
    image: mongo:4.4
    platform: linux/arm64
    container_name: unifi-network-application-mongodb
    restart: unless-stopped
    expose:
      - 27017
    environment:
      - MONGO_INITDB_DATABASE=unifi-db
    volumes:
      - /home/pi/docker/unifinetwork/db/data:/data/db
      - /home/pi/docker/unifinetwork/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro`

it runs, but it restarts in docker without a log or error message. :(

@l4rm4nd
Copy link
Member

l4rm4nd commented Dec 24, 2023

Anyone know how to get it to work on a pi? I've modified it

`---
version: "2.1"
services:
  unifi-network-application:
    image: lscr.io/linuxserver/unifi-network-application:arm64v8-latest
    container_name: unifi-network-application
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC
      - MONGO_USER=unifi
      - MONGO_PASS=unifi
      - MONGO_HOST=unifi-db
      - MONGO_PORT=27017
      - MONGO_DBNAME=unifi-db

    volumes:
      - /home/pi/docker/unifinetwork/app:/config
    depends_on:
      - unifi-db
    ports:
      - 8443:8443
      - 3478:3478/udp
      - 10001:10001/udp
      - 8080:8080
    restart: unless-stopped

  unifi-db:
    image: mongo:4.4
    platform: linux/arm64
    container_name: unifi-network-application-mongodb
    restart: unless-stopped
    expose:
      - 27017
    environment:
      - MONGO_INITDB_DATABASE=unifi-db
    volumes:
      - /home/pi/docker/unifinetwork/db/data:/data/db
      - /home/pi/docker/unifinetwork/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro`

it runs, but it restarts in docker without a log or error message. :(

You'd have to use a proper ARM image of MongoDB, which seems to not exist anymore.

Maybe you can use the image webhippie/mongodb:latest-arm32v7.

https://forums.docker.com/t/mongo-db-raspberry-pi4/138908/2

Otherwise, ensure that you RPi runs an ARM64 or AARCH64 OS. Then the provided example should just work.

@JCM0610
Copy link

JCM0610 commented Feb 5, 2024

I was trying this on pi, except with mongo 3.6. I used @Ciberbago's compose file, only changing the mongo image and volume mappings and I'm getting this error:

[2024-02-05 16:11:52,061] <launcher> INFO db - db connection established... [2024-02-05 16:11:52,605] <launcher> ERROR db - Got error while connecting to db: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='unifi', source='unifi-db', password=<hidden>, mechanismProperties=<hidden>}

Anyone have any ideas to fix? I've tried other versions of a compose file with the linuxserver image but no matter what I've tried, I keep running into this same error. Banging my head against the wall here on why this doesn't just work. Hers's my docker-compose.yml:

---
version: "2.1"
services:
  unifi-network-application:
    image: lscr.io/linuxserver/unifi-network-application:latest
    container_name: unifi-network-application
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC
      - MONGO_USER=unifi
      - MONGO_PASS=unifi
      - MONGO_HOST=unifi-db
      - MONGO_PORT=27017
      - MONGO_DBNAME=unifi-db
      - MEM_LIMIT=1024 #optional
      - MEM_STARTUP=1024 #optional
    volumes:
      - /home/docker/unifi-network-application/:/config
    depends_on:
      - unifi-db
    ports:
      - 8443:8443
      - 3478:3478/udp
      - 10001:10001/udp
      - 8080:8080
      - 1900:1900/udp #optional
      - 8843:8843 #optional
      - 8880:8880 #optional
      - 6789:6789 #optional
      - 5514:5514/udp #optional
    restart: unless-stopped

  unifi-db:
    image: docker.io/mongo:3.6
    container_name: unifi-db
    restart: unless-stopped
    expose:
      - 27017
    environment:
      - MONGO_INITDB_DATABASE=unifi-db
    volumes:
      - /home/docker/unifi-db:/data/db
      - ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro

@l4rm4nd
Copy link
Member

l4rm4nd commented Feb 5, 2024

I was trying this on pi, except with mongo 3.6. I used @Ciberbago's compose file, only changing the mongo image and volume mappings and I'm getting this error:

[2024-02-05 16:11:57,343] <launcher> INFO db - db connection established... [2024-02-05 16:11:57,884] <launcher> ERROR db - Got error while connecting to db: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='unifi', source='unifi-db', password=<hidden>, mechanismProperties=<hidden>}
Anyone have any ideas to fix? I've tried other versions of a compose file with the linuxserver image but no matter what I've tried, I keep running into this same error. Banging my head against the wall here on why this doesn't just work. Hers's my docker-compose.yml:

'version: "2.1"
services:
unifi-network-application:
image: lscr.io/linuxserver/unifi-network-application:latest
container_name: unifi-network-application
environment:
- PUID=1000
- PGID=1000
- TZ=Etc/UTC
- MONGO_USER=unifi
- MONGO_PASS=unifi
- MONGO_HOST=unifi-db
- MONGO_PORT=27017
- MONGO_DBNAME=unifi-db
- MEM_LIMIT=1024 #optional
- MEM_STARTUP=1024 #optional
volumes:
- /home/docker/unifi-network-application/:/config
depends_on:
- unifi-db
ports:
- 8443:8443
- 3478:3478/udp
- 10001:10001/udp
- 8080:8080
- 1900:1900/udp #optional
- 8843:8843 #optional
- 8880:8880 #optional
- 6789:6789 #optional
- 5514:5514/udp #optional
restart: unless-stopped

unifi-db:
image: docker.io/mongo:3.6
container_name: unifi-db
restart: unless-stopped
expose:
- 27017
environment:
- MONGO_INITDB_DATABASE=unifi-db
volumes:
- /home/docker/unifi-db:/data/db
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro`

Maybe this helps:

https://discourse.linuxserver.io/t/cant-connect-to-mongodb-for-unifi-network-application/8166

Ensure that your password does not use escape sequences. Maybe start with a simple username and password. Remove the volumes and start freshly.

Otherwise, you may install an ARM64 or AARCH64 OS. Then the provided example should just work.

@JCM0610
Copy link

JCM0610 commented Feb 8, 2024

So I went back to scratch on this and discovered the quotes in my init-mongo.js file were being stripped out for some reason. After fixing this, I could see the db connect and all seems to be working. Do I need to comment out the following line after initial setup?
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro

@l4rm4nd
Copy link
Member

l4rm4nd commented Feb 8, 2024

So I went back to scratch on this and discovered the quotes in my init-mongo.js file were being stripped out for some reason. After fixing this, I could see the db connect and all seems to be working. Do I need to comment out the following line after initial setup?
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro

Perfect! Glad you got it working.

You can comment out the volume mapping. However, this is not mandatory. Once the db is set up, it won't initialize again.

@Azulath
Copy link

Azulath commented Apr 9, 2024

Edit: It turns out I messed up the permissions of the init-mongo.js file. Now that this is fixed, it works as expected. I leave the comment here though so that it might provide help to other people.

I tried getting it up and running on my portainer setup but unfortunately it fails:

version: "2.1"
services:
  unifi-network-application:
    image: lscr.io/linuxserver/unifi-network-application:latest
    container_name: unifi-network-application
    depends_on:
      - unifi-db
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC
      - MONGO_USER=unifi
      - MONGO_PASS=password
      - MONGO_HOST=unifi-db
      - MONGO_PORT=27017
      - MONGO_DBNAME=unifi-db
      - MEM_LIMIT=3072 #optional
      - MEM_STARTUP=3072 #optional
    volumes:
      - /mnt/tank/apps/unifi-network-application/config:/config
    ports:
      - 8443:8443
      - 3478:3478/udp
      - 10001:10001/udp
      - 8080:8080
      - 1900:1900/udp #optional
      - 8843:8843 #optional
      - 8880:8880 #optional
      - 6789:6789 #optional
      - 5514:5514/udp #optional
    networks:
     - unifi-bridge
    restart: unless-stopped

  unifi-db:
    image: mongo:4.4
    container_name: unifi-db
    expose:
      - 27017
    volumes:
      - /mnt/tank/apps/unifi-network-application/data:/data/db
      - /mnt/tank/apps/unifi-network-application/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
    networks:
     - unifi-bridge
    restart: unless-stopped

networks:
  unifi-bridge:
    driver: bridge
db.getSiblingDB("unifi-db").createUser({user: "unifi", pwd: "password", roles: [{role: "dbOwner", db: "unifi-db"}]});
db.getSiblingDB("unifi-db_stat").createUser({user: "unifi", pwd: "password", roles: [{role: "dbOwner", db: "unifi-db_stat"}]});

These would be the container's error logs:

Logs

*** Waiting for MONGO_HOST unifi-db to be reachable. ***

Generating 4,096 bit RSA key pair and self-signed certificate (SHA384withRSA) with a validity of 3,650 days
	for: CN=unifi
[custom-init] No custom files found, skipping...

Exception in thread "launcher" com.ubnt.net.new: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
	at com.ubnt.net.C.ÒÒ0000(Unknown Source)
	at com.ubnt.net.C.Stringnew(Unknown Source)
	at com.ubnt.service.C.OÔ0000(Unknown Source)
	at com.ubnt.ace.Launcher.Ô00000(Unknown Source)
	at com.ubnt.ace.Launcher.main(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
	at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:419)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:186)
	... 5 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoRuntimeService' defined in com.ubnt.service.db.CoreDatabaseSpringContext: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='unifi', source='unifi-db', password=<hidden>, mechanismProperties=<hidden>}
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1773)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:599)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:959)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624)
	at com.ubnt.service.class.Object(Unknown Source)
	at com.ubnt.service.C.intsuper(Unknown Source)
	at com.ubnt.net.SpringConfig.onStartup(Unknown Source)
	at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:171)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4866)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
	... 5 more

Caused by: com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='unifi', source='unifi-db', password=<hidden>, mechanismProperties=<hidden>}
	at com.mongodb.internal.connection.SaslAuthenticator.wrapException(SaslAuthenticator.java:270)
	at com.mongodb.internal.connection.SaslAuthenticator.getNextSaslResponse(SaslAuthenticator.java:133)
	at com.mongodb.internal.connection.SaslAuthenticator.lambda$authenticate$0(SaslAuthenticator.java:63)
	at com.mongodb.internal.connection.SaslAuthenticator.doAsSubject(SaslAuthenticator.java:277)
	at com.mongodb.internal.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:59)
	at com.mongodb.internal.connection.DefaultAuthenticator.authenticate(DefaultAuthenticator.java:57)
	at com.mongodb.internal.connection.InternalStreamConnectionInitializer.authenticate(InternalStreamConnectionInitializer.java:206)
	at com.mongodb.internal.connection.InternalStreamConnectionInitializer.finishHandshake(InternalStreamConnectionInitializer.java:86)
	at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:216)
	at com.mongodb.internal.connection.UsageTrackingInternalConnection.open(UsageTrackingInternalConnection.java:55)
	at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.open(DefaultConnectionPool.java:647)
	at com.mongodb.internal.connection.DefaultConnectionPool$OpenConcurrencyLimiter.openWithConcurrencyLimit(DefaultConnectionPool.java:993)
	at com.mongodb.internal.connection.DefaultConnectionPool$OpenConcurrencyLimiter.openOrGetAvailable(DefaultConnectionPool.java:934)
	at com.mongodb.internal.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:203)
	at com.mongodb.internal.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:192)
	at com.mongodb.internal.connection.DefaultServer.getConnection(DefaultServer.java:96)
	at com.mongodb.internal.binding.ClusterBinding$ClusterBindingConnectionSource.getConnection(ClusterBinding.java:186)
	at com.mongodb.client.internal.ClientSessionBinding$SessionBindingConnectionSource.getConnection(ClientSessionBinding.java:196)
	at com.mongodb.internal.operation.SyncOperationHelper.withSuppliedResource(SyncOperationHelper.java:144)
	at com.mongodb.internal.operation.SyncOperationHelper.lambda$withSourceAndConnection$1(SyncOperationHelper.java:126)
	at com.mongodb.internal.operation.SyncOperationHelper.withSuppliedResource(SyncOperationHelper.java:152)
	at com.mongodb.internal.operation.SyncOperationHelper.withSourceAndConnection(SyncOperationHelper.java:125)
	at com.mongodb.internal.operation.SyncOperationHelper.lambda$executeRetryableRead$4(SyncOperationHelper.java:189)
	at com.mongodb.internal.operation.SyncOperationHelper.lambda$decorateReadWithRetries$12(SyncOperationHelper.java:292)
	at com.mongodb.internal.async.function.RetryingSyncSupplier.get(RetryingSyncSupplier.java:67)
	at com.mongodb.internal.operation.SyncOperationHelper.executeRetryableRead(SyncOperationHelper.java:194)
	at com.mongodb.internal.operation.SyncOperationHelper.executeRetryableRead(SyncOperationHelper.java:176)
	at com.mongodb.internal.operation.CommandReadOperation.execute(CommandReadOperation.java:48)
	at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:153)
	at com.mongodb.client.internal.MongoDatabaseImpl.executeCommand(MongoDatabaseImpl.java:196)
	at com.mongodb.client.internal.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:165)
	at com.mongodb.client.internal.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:160)
	at com.mongodb.client.internal.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:150)
	at com.ubnt.service.db.oooO.Óo0000(Unknown Source)
	at com.ubnt.service.db.oooO.afterPropertiesSet(Unknown Source)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1820)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1769)


Caused by: com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server unifi-db:27017. The full response is {"ok": 0.0, "errmsg": "Authentication failed.", "code": 18, "codeName": "AuthenticationFailed"}
	at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:205)
	at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:454)
	at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:372)
	at com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:102)
	at com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:49)
	at com.mongodb.internal.connection.SaslAuthenticator.sendSaslStart(SaslAuthenticator.java:224)
	at com.mongodb.internal.connection.SaslAuthenticator.getNextSaslResponse(SaslAuthenticator.java:131)

At this point, I have a hard time understanding why the application is not able to log into the database...

@l4rm4nd
Copy link
Member

l4rm4nd commented Apr 10, 2024

Edit: It turns out I messed up the permissions of the init-mongo.js file. Now that this is fixed, it works as expected. I leave the comment here though so that it might provide help to other people.

I tried getting it up and running on my portainer setup but unfortunately it fails:

version: "2.1"
services:
  unifi-network-application:
    image: lscr.io/linuxserver/unifi-network-application:latest
    container_name: unifi-network-application
    depends_on:
      - unifi-db
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC
      - MONGO_USER=unifi
      - MONGO_PASS=password
      - MONGO_HOST=unifi-db
      - MONGO_PORT=27017
      - MONGO_DBNAME=unifi-db
      - MEM_LIMIT=3072 #optional
      - MEM_STARTUP=3072 #optional
    volumes:
      - /mnt/tank/apps/unifi-network-application/config:/config
    ports:
      - 8443:8443
      - 3478:3478/udp
      - 10001:10001/udp
      - 8080:8080
      - 1900:1900/udp #optional
      - 8843:8843 #optional
      - 8880:8880 #optional
      - 6789:6789 #optional
      - 5514:5514/udp #optional
    networks:
     - unifi-bridge
    restart: unless-stopped

  unifi-db:
    image: mongo:4.4
    container_name: unifi-db
    expose:
      - 27017
    volumes:
      - /mnt/tank/apps/unifi-network-application/data:/data/db
      - /mnt/tank/apps/unifi-network-application/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
    networks:
     - unifi-bridge
    restart: unless-stopped

networks:
  unifi-bridge:
    driver: bridge
db.getSiblingDB("unifi-db").createUser({user: "unifi", pwd: "password", roles: [{role: "dbOwner", db: "unifi-db"}]});
db.getSiblingDB("unifi-db_stat").createUser({user: "unifi", pwd: "password", roles: [{role: "dbOwner", db: "unifi-db_stat"}]});

These would be the container's error logs:

Logs


*** Waiting for MONGO_HOST unifi-db to be reachable. ***

Generating 4,096 bit RSA key pair and self-signed certificate (SHA384withRSA) with a validity of 3,650 days
	for: CN=unifi
[custom-init] No custom files found, skipping...

Exception in thread "launcher" com.ubnt.net.new: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
	at com.ubnt.net.C.ÒÒ0000(Unknown Source)
	at com.ubnt.net.C.Stringnew(Unknown Source)
	at com.ubnt.service.C.OÔ0000(Unknown Source)
	at com.ubnt.ace.Launcher.Ô00000(Unknown Source)
	at com.ubnt.ace.Launcher.main(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
	at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:419)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:186)
	... 5 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoRuntimeService' defined in com.ubnt.service.db.CoreDatabaseSpringContext: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='unifi', source='unifi-db', password=<hidden>, mechanismProperties=<hidden>}
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1773)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:599)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:959)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624)
	at com.ubnt.service.class.Object(Unknown Source)
	at com.ubnt.service.C.intsuper(Unknown Source)
	at com.ubnt.net.SpringConfig.onStartup(Unknown Source)
	at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:171)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4866)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
	... 5 more

Caused by: com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='unifi', source='unifi-db', password=<hidden>, mechanismProperties=<hidden>}
	at com.mongodb.internal.connection.SaslAuthenticator.wrapException(SaslAuthenticator.java:270)
	at com.mongodb.internal.connection.SaslAuthenticator.getNextSaslResponse(SaslAuthenticator.java:133)
	at com.mongodb.internal.connection.SaslAuthenticator.lambda$authenticate$0(SaslAuthenticator.java:63)
	at com.mongodb.internal.connection.SaslAuthenticator.doAsSubject(SaslAuthenticator.java:277)
	at com.mongodb.internal.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:59)
	at com.mongodb.internal.connection.DefaultAuthenticator.authenticate(DefaultAuthenticator.java:57)
	at com.mongodb.internal.connection.InternalStreamConnectionInitializer.authenticate(InternalStreamConnectionInitializer.java:206)
	at com.mongodb.internal.connection.InternalStreamConnectionInitializer.finishHandshake(InternalStreamConnectionInitializer.java:86)
	at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:216)
	at com.mongodb.internal.connection.UsageTrackingInternalConnection.open(UsageTrackingInternalConnection.java:55)
	at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.open(DefaultConnectionPool.java:647)
	at com.mongodb.internal.connection.DefaultConnectionPool$OpenConcurrencyLimiter.openWithConcurrencyLimit(DefaultConnectionPool.java:993)
	at com.mongodb.internal.connection.DefaultConnectionPool$OpenConcurrencyLimiter.openOrGetAvailable(DefaultConnectionPool.java:934)
	at com.mongodb.internal.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:203)
	at com.mongodb.internal.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:192)
	at com.mongodb.internal.connection.DefaultServer.getConnection(DefaultServer.java:96)
	at com.mongodb.internal.binding.ClusterBinding$ClusterBindingConnectionSource.getConnection(ClusterBinding.java:186)
	at com.mongodb.client.internal.ClientSessionBinding$SessionBindingConnectionSource.getConnection(ClientSessionBinding.java:196)
	at com.mongodb.internal.operation.SyncOperationHelper.withSuppliedResource(SyncOperationHelper.java:144)
	at com.mongodb.internal.operation.SyncOperationHelper.lambda$withSourceAndConnection$1(SyncOperationHelper.java:126)
	at com.mongodb.internal.operation.SyncOperationHelper.withSuppliedResource(SyncOperationHelper.java:152)
	at com.mongodb.internal.operation.SyncOperationHelper.withSourceAndConnection(SyncOperationHelper.java:125)
	at com.mongodb.internal.operation.SyncOperationHelper.lambda$executeRetryableRead$4(SyncOperationHelper.java:189)
	at com.mongodb.internal.operation.SyncOperationHelper.lambda$decorateReadWithRetries$12(SyncOperationHelper.java:292)
	at com.mongodb.internal.async.function.RetryingSyncSupplier.get(RetryingSyncSupplier.java:67)
	at com.mongodb.internal.operation.SyncOperationHelper.executeRetryableRead(SyncOperationHelper.java:194)
	at com.mongodb.internal.operation.SyncOperationHelper.executeRetryableRead(SyncOperationHelper.java:176)
	at com.mongodb.internal.operation.CommandReadOperation.execute(CommandReadOperation.java:48)
	at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:153)
	at com.mongodb.client.internal.MongoDatabaseImpl.executeCommand(MongoDatabaseImpl.java:196)
	at com.mongodb.client.internal.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:165)
	at com.mongodb.client.internal.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:160)
	at com.mongodb.client.internal.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:150)
	at com.ubnt.service.db.oooO.Óo0000(Unknown Source)
	at com.ubnt.service.db.oooO.afterPropertiesSet(Unknown Source)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1820)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1769)


Caused by: com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server unifi-db:27017. The full response is {"ok": 0.0, "errmsg": "Authentication failed.", "code": 18, "codeName": "AuthenticationFailed"}
	at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:205)
	at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:454)
	at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:372)
	at com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:102)
	at com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:49)
	at com.mongodb.internal.connection.SaslAuthenticator.sendSaslStart(SaslAuthenticator.java:224)
	at com.mongodb.internal.connection.SaslAuthenticator.getNextSaslResponse(SaslAuthenticator.java:131)

At this point, I have a hard time understanding why the application is not able to log into the database...

Remove your existing mongo-db volumes and recreate the stack.

The database was likely provisioned with failures beforehand. Once the db exists, the init-mongo.js is ignored.

@dlong500
Copy link

Remove your existing mongo-db volumes and recreate the stack.

The database was likely provisioned with failures beforehand. Once the db exists, the init-mongo.js is ignored.

It's worth noting that if something gets messed up with the database initialization and you're trying to recreate the containers you must clear out BOTH the mongodb data AND the unifi config folders.

I initially didn't escape special characters in the password. I figured that part out pretty quickly and corrected it but only cleared out the mongodb data folder before recreating the containers thinking the unifi config would read an updated password specified in the compose file. That stymied me for a bit because the unifi app was still failing to authorize against the mongodb instance. I finally realized I should try clearing out everything before recreating the containers and that did the trick.

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

No branches or pull requests

7 participants