linuxserver / docker-unifi-network-application

GNU General Public License v3.0
551 stars 40 forks source link

[BUG] Can't start application by following README.md precisely #84

Closed 1shindes closed 2 months ago

1shindes commented 2 months ago

/### Is there an existing issue for this?

Current Behavior

Trying to start me the docker-unifi-network-application following README.md precisely using docker-compose and the

following config: ```yaml --- services: unifi-db: hostname: unifi-db container_name: unifi-db image: 'mongo:7.0.5' volumes: - ./unifi-db/data:/data/db - ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro ports: - 27017:27017 restart: unless-stopped 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=inifipass - MONGO_HOST=unifi-db - MONGO_PORT=27017 - MONGO_DBNAME=unifi # - MEM_LIMIT=1024 #optional # - MEM_STARTUP=1024 #optional # - MONGO_TLS= #optional # - MONGO_AUTHSOURCE= #optional volumes: - ./unifi-network/data:/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 restart: unless-stopped depends_on: - unifi-db ```
Database wasn't initialized ``` root@unifi-db:/# mongosh Current Mongosh Log ID: 6616aab15abee8a0c8e10dd5 Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.1.4 Using MongoDB: 7.0.5 Using Mongosh: 2.1.4 For mongosh info see: https://docs.mongodb.com/mongodb-shell/ To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy). You can opt-out by running the disableTelemetry() command. ------ The server generated these startup warnings when booting 2024-04-10T15:03:17.974+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem 2024-04-10T15:03:19.924+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted 2024-04-10T15:03:19.925+00:00: vm.max_map_count is too low ------ test> show databases admin 100.00 KiB config 12.00 KiB local 72.00 KiB test> use admin switched to db admin admin> show users [] admin> quit ````

Hence the application doesn't start up properly.

I can create mongo-express container additionally, manually create unifi user, unifi/unifi_stat database etc., restart the application container only and then, if did it all right, succeed. But this means that the instructions from README are not correct for my system setup, at least, and maybe they have to be updated.

Is it even possible to, with proper yaml file, start up docker-unifi-network-application from scratch or it's just me doing all wrong?

Expected Behavior

App should be working

Steps To Reproduce

Environment

- OS: Ubuntu 22.04.4 LTS, clean install
- Docker Compose version v2.26.1
- Docker version 26.0.0, build 2ae903e

CPU architecture

x86-64

Docker creation

as per yaml config

Container logs

unifi-network-application  | Exception in thread "launcher" com.ubnt.net.new: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
unifi-network-application  |    at com.ubnt.net.C.ÒÒ0000(Unknown Source)
unifi-network-application  |    at com.ubnt.net.C.Stringnew(Unknown Source)
unifi-network-application  |    at com.ubnt.service.C.OÔ0000(Unknown Source)
unifi-network-application  |    at com.ubnt.ace.Launcher.Ô00000(Unknown Source)
unifi-network-application  |    at com.ubnt.ace.Launcher.main(Unknown Source)
unifi-network-application  | Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
unifi-network-application  |    at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:419)
unifi-network-application  |    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:186)
unifi-network-application  |    ... 5 more
unifi-network-application  | 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', password=<hidden>, mechanismProperties=<hidden>}
unifi-network-application  |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1773)
unifi-network-application  |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:599)
unifi-network-application  |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521)
unifi-network-application  |    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325)
unifi-network-application  |    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
unifi-network-application  |    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323)
unifi-network-application  |    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
unifi-network-application  |    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975)
unifi-network-application  |    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:959)
unifi-network-application  |    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624)
unifi-network-application  |    at com.ubnt.service.class.Object(Unknown Source)
unifi-network-application  |    at com.ubnt.service.C.intsuper(Unknown Source)
unifi-network-application  |    at com.ubnt.net.SpringConfig.onStartup(Unknown Source)
unifi-network-application  |    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:171)
unifi-network-application  |    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4866)
unifi-network-application  |    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
unifi-network-application  |    ... 5 more
unifi-network-application  | Caused by: com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='unifi', source='unifi', password=<hidden>, mechanismProperties=<hidden>}
unifi-network-application  |    at com.mongodb.internal.connection.SaslAuthenticator.wrapException(SaslAuthenticator.java:270)
unifi-network-application  |    at com.mongodb.internal.connection.SaslAuthenticator.getNextSaslResponse(SaslAuthenticator.java:133)
unifi-network-application  |    at com.mongodb.internal.connection.SaslAuthenticator.lambda$authenticate$0(SaslAuthenticator.java:63)
unifi-network-application  |    at com.mongodb.internal.connection.SaslAuthenticator.doAsSubject(SaslAuthenticator.java:277)
unifi-network-application  |    at com.mongodb.internal.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:59)
unifi-network-application  |    at com.mongodb.internal.connection.DefaultAuthenticator.authenticate(DefaultAuthenticator.java:57)
unifi-network-application  |    at com.mongodb.internal.connection.InternalStreamConnectionInitializer.authenticate(InternalStreamConnectionInitializer.java:206)
unifi-network-application  |    at com.mongodb.internal.connection.InternalStreamConnectionInitializer.finishHandshake(InternalStreamConnectionInitializer.java:86)
unifi-network-application  |    at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:216)
unifi-network-application  |    at com.mongodb.internal.connection.UsageTrackingInternalConnection.open(UsageTrackingInternalConnection.java:55)
unifi-network-application  |    at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.open(DefaultConnectionPool.java:647)
unifi-network-application  |    at com.mongodb.internal.connection.DefaultConnectionPool$OpenConcurrencyLimiter.openWithConcurrencyLimit(DefaultConnectionPool.java:993)
unifi-network-application  |    at com.mongodb.internal.connection.DefaultConnectionPool$OpenConcurrencyLimiter.openOrGetAvailable(DefaultConnectionPool.java:934)
unifi-network-application  |    at com.mongodb.internal.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:203)
unifi-network-application  |    at com.mongodb.internal.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:192)
unifi-network-application  |    at com.mongodb.internal.connection.DefaultServer.getConnection(DefaultServer.java:96)
unifi-network-application  |    at com.mongodb.internal.binding.ClusterBinding$ClusterBindingConnectionSource.getConnection(ClusterBinding.java:186)
unifi-network-application  |    at com.mongodb.client.internal.ClientSessionBinding$SessionBindingConnectionSource.getConnection(ClientSessionBinding.java:196)
unifi-network-application  |    at com.mongodb.internal.operation.SyncOperationHelper.withSuppliedResource(SyncOperationHelper.java:144)
unifi-network-application  |    at com.mongodb.internal.operation.SyncOperationHelper.lambda$withSourceAndConnection$1(SyncOperationHelper.java:126)
unifi-network-application  |    at com.mongodb.internal.operation.SyncOperationHelper.withSuppliedResource(SyncOperationHelper.java:152)
unifi-network-application  |    at com.mongodb.internal.operation.SyncOperationHelper.withSourceAndConnection(SyncOperationHelper.java:125)
unifi-network-application  |    at com.mongodb.internal.operation.SyncOperationHelper.lambda$executeRetryableRead$4(SyncOperationHelper.java:189)
unifi-network-application  |    at com.mongodb.internal.operation.SyncOperationHelper.lambda$decorateReadWithRetries$12(SyncOperationHelper.java:292)
unifi-network-application  |    at com.mongodb.internal.async.function.RetryingSyncSupplier.get(RetryingSyncSupplier.java:67)
unifi-network-application  |    at com.mongodb.internal.operation.SyncOperationHelper.executeRetryableRead(SyncOperationHelper.java:194)
unifi-network-application  |    at com.mongodb.internal.operation.SyncOperationHelper.executeRetryableRead(SyncOperationHelper.java:176)
unifi-network-application  |    at com.mongodb.internal.operation.CommandReadOperation.execute(CommandReadOperation.java:48)
unifi-network-application  |    at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:153)
unifi-network-application  |    at com.mongodb.client.internal.MongoDatabaseImpl.executeCommand(MongoDatabaseImpl.java:196)
unifi-network-application  |    at com.mongodb.client.internal.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:165)
unifi-network-application  |    at com.mongodb.client.internal.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:160)
unifi-network-application  |    at com.mongodb.client.internal.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:150)
unifi-network-application  |    at com.ubnt.service.db.oooO.Óo0000(Unknown Source)
unifi-network-application  |    at com.ubnt.service.db.oooO.afterPropertiesSet(Unknown Source)
unifi-network-application  |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1820)
unifi-network-application  |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1769)
unifi-network-application  |    ... 20 more
unifi-network-application  | 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"}
unifi-network-application  |    at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:205)
unifi-network-application  |    at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(Inte
github-actions[bot] commented 2 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 2 months ago

My guess is, either your init-mongo.js is incorrect, or your mongodb already had some data in there (or you included the user/db vars the first time).

Most of our team members use unifi. We all followed the readme and I assure you it works.

1shindes commented 2 months ago

@aptalca thanks for your reply! Mу whole init-mongo.js is just these 2 strings from Readme:

db.getSiblingDB("MONGO_DBNAME").createUser({user: "MONGO_USER", pwd: "MONGO_PASS", roles: [{role: "dbOwner", db: "MONGO_DBNAME"}]});
db.getSiblingDB("MONGO_DBNAME_stat").createUser({user: "MONGO_USER", pwd: "MONGO_PASS", roles: [{role: "dbOwner", db: "MONGO_DBNAME_stat"}]});

As I pointed out at issue description, I'm using clean Ubuntu install and building containers in a new directory from zero. If I make any changes to docker-compose config, I delete mapped volumes, execute docker container prune and only after that I build a new containers for app and mongo. By

or you included the user/db vars the first time

you mean what?

kylemello commented 2 months ago

@1shindes had this problem as well as I screwed it up the first time around. Make sure to change the values inside of the init-mongo.js file to the values you want for example:

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

Also if you did mess up the first time around I would prune any volumes that are not used with docker volumes prune

1shindes commented 2 months ago

@kylemello Thanks! By the time I received your reply I've found it myself. The problem is that I treat init-mongo.js literally, being confused with the MONGO_USER and MONGO_PASS, which I thought I can pass to init script as envs. So I use .env with a lot of variables - best practices and all that. This won't work in this setup! To be short, that's the correct set of config files. All you need is to docker-compose up -d

docker-compose.yml ```yaml --- services: unifi-db: hostname: unifi-db container_name: unifi-db image: 'mongo:7.0.5' volumes: - ./unifi-db/data:/data/db - ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro ports: - 27017:27017 restart: unless-stopped 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=unifipass - MONGO_HOST=unifi-db - MONGO_PORT=27017 - MONGO_DBNAME=unifi-db # - MEM_LIMIT=1024 #optional # - MEM_STARTUP=1024 #optional # - MONGO_TLS= #optional # - MONGO_AUTHSOURCE= #optional volumes: - ./unifi-network/data:/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 restart: unless-stopped depends_on: - unifi-db ```
init-mongo.js ```js db.getSiblingDB("unifi-db").createUser({user: "unifi", pwd: "unifipass", roles: [{role: "dbOwner", db: "unifi-db"}]}); db.getSiblingDB("unifi-db_stat").createUser({user: "unifi", pwd: "unifipass", roles: [{role: "dbOwner", db: "unifi-db_stat"}]}); ```

That's it! No Dockerfile, no .env. MONGO_USER and MONGO_PASS values must be hardcoded and if you change them in .yml file - you must change them in .js file correspondingly.

aptalca commented 2 months ago

So in other words, you did not follow the readme precisely as the readme states Being sure to replace the placeholders with the same values you supplied to the Unifi container.

Glad it's solved.

dlong500 commented 2 months ago

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.

Might be worth adding a small blurb to the README about making sure absolutely all the persistent volumes are cleared out if you are trying to start over after a failed initialization.

lblomenkemper commented 3 weeks ago

Maybe I just missed it in the docs, but I had the exact same issue because I used a password longer than 32 chars.