linuxserver / docker-unifi-network-application

GNU General Public License v3.0
553 stars 41 forks source link

[BUG] MONGO_PORT not being used #16

Closed JonathanTroyer closed 9 months ago

JonathanTroyer commented 9 months ago

Is there an existing issue for this?

Current Behavior

server.log shows

[2023-09-22 01:46:57,724] <launcher> ERROR db     - Got error while connecting to db: Cannot invoke "com.mongodb.client.MongoClient.getDatabase(String)" because the return value of "com.ubnt.service.system.z.ÖØ0000()" is null
[2023-09-22 01:46:58,224] <launcher> INFO  db     - Connecting to mongodb://unifi:redacted@localhost:/unifi
[2023-09-22 01:46:58,224] <launcher> ERROR db     - Error creating mongo client... 

echo $MONGO_PORT gives 27017

Expected Behavior

The port should be configured correctly when sed'd

Steps To Reproduce

Followed the compose instructions in the README. Of note, I am using podman on Nomad, rather than Docker directly

Environment

- OS: Debian 12
- Podman: 4.3.1

CPU architecture

x86-64

Docker creation

This is my nomad job, with extraneous stuff like volume and port mappings stripped for brevity.

job "unifi-network-application" {
  datacenters = ["home"]
  type        = "service"

  group "unifi-network-application" {
    count = 1
    service {
      name = "unifi"
    }
    task "network-application" {
      template {
        destination = "${NOMAD_SECRETS_DIR}/env.vars"
        env         = true
        change_mode = "restart"
        data        = <<EOH
{{- with nomadVar "nomad/jobs/unifi-network-application" -}}
MONGO_PASS = {{.db_password}}
{{- end -}}
        EOH
      }
      env {
        MONGO_USER   = "unifi"
        MONGO_DBNAME = "unifi"
        MONGO_HOST   = "localhost"
        MONGO_PORT   = 27017
      }
      driver = "podman"
      volume_mount {
        volume      = "unifi"
        destination = "/config"
        read_only   = false
      }
      config {
        image = "lscr.io/linuxserver/unifi-network-application:latest"
        ports = ["https", "STUN", "discovery", "comms"]
      }
    }
    task "mongodb" {
      lifecycle {
        hook    = "prestart"
        sidecar = true
      }
      template {
        data        = <<EOH
{{- with nomadVar "nomad/jobs/unifi-network-application" -}}
db.getSiblingDB("unifi").createUser({user: "unifi", pwd: "{{.db_password}}", roles: [{role: "readWrite", db: "unifi"}]});
db.getSiblingDB("unifi_stat").createUser({user: "unifi", pwd: "{{.db_password}}", roles: [{role: "readWrite", db: "unifi_stat"}]});
{{- end -}}
EOH
        destination = "init-mongo.js"
      }
      driver = "podman"
      volume_mount {
        volume      = "unifi-db"
        destination = "/data"
        read_only   = false
      }
      config {
        image   = "docker.io/mongo:4.4"
        volumes = ["init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js"]
      }
    }
  }
}

Container logs

2023-09-21T20:40:39.398423744-05:00 stdout F [migrations] started
2023-09-21T20:40:39.398573863-05:00 stdout F [migrations] no migrations found
2023-09-21T20:40:39.515639836-05:00 stdout F usermod: no changes
2023-09-21T20:40:39.516639854-05:00 stdout F ───────────────────────────────────────
2023-09-21T20:40:39.516639854-05:00 stdout F 
2023-09-21T20:40:39.516639854-05:00 stdout F       ██╗     ███████╗██╗ ██████╗ 
2023-09-21T20:40:39.516639854-05:00 stdout F       ██║     ██╔════╝██║██╔═══██╗
2023-09-21T20:40:39.516639854-05:00 stdout F       ██║     ███████╗██║██║   ██║
2023-09-21T20:40:39.516639854-05:00 stdout F       ██║     ╚════██║██║██║   ██║
2023-09-21T20:40:39.516639854-05:00 stdout F       ███████╗███████║██║╚██████╔╝
2023-09-21T20:40:39.516639854-05:00 stdout F       ╚══════╝╚══════╝╚═╝ ╚═════╝ 
2023-09-21T20:40:39.516639854-05:00 stdout F 
2023-09-21T20:40:39.516639854-05:00 stdout F    Brought to you by linuxserver.io
2023-09-21T20:40:39.516639854-05:00 stdout F ───────────────────────────────────────
2023-09-21T20:40:39.516936997-05:00 stdout F 
2023-09-21T20:40:39.516936997-05:00 stdout F To support LSIO projects visit:
2023-09-21T20:40:39.516936997-05:00 stdout F https://www.linuxserver.io/donate/
2023-09-21T20:40:39.516936997-05:00 stdout F 
2023-09-21T20:40:39.516936997-05:00 stdout F ───────────────────────────────────────
2023-09-21T20:40:39.516936997-05:00 stdout F GID/UID
2023-09-21T20:40:39.516936997-05:00 stdout F ───────────────────────────────────────
2023-09-21T20:40:39.519690950-05:00 stdout F 
2023-09-21T20:40:39.519690950-05:00 stdout F User UID:    911
2023-09-21T20:40:39.519690950-05:00 stdout F User GID:    911
2023-09-21T20:40:39.519690950-05:00 stdout F ───────────────────────────────────────
2023-09-21T20:40:39.519690950-05:00 stdout F 
2023-09-21T20:40:39.575631198-05:00 stdout F [custom-init] No custom files found, skipping...
2023-09-21T20:40:41.171211003-05:00 stdout F 01:40:41,156 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Could NOT configuration file [/usr/lib/unifi/logback-access.xml] using property "catalina.base"
2023-09-21T20:40:41.171242721-05:00 stdout F 01:40:41,156 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Could NOT configuration file [/usr/lib/unifi/logback-access.xml] using property "catalina.home"
2023-09-21T20:40:41.171263262-05:00 stdout F 01:40:41,156 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Found [logback-access.xml] as a resource.
2023-09-21T20:40:41.171319836-05:00 stdout F 01:40:41,157 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@38b5f25 - URL [jar:file:/usr/lib/unifi/lib/ace.jar!/logback-access.xml] is not of type file
2023-09-21T20:40:41.171373421-05:00 stdout F 01:40:41,165 |-INFO in ch.qos.logback.access.joran.action.ConfigurationAction - debug attribute not set
2023-09-21T20:40:41.171394082-05:00 stdout F 01:40:41,165 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
2023-09-21T20:40:41.171417477-05:00 stdout F 01:40:41,165 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [access_log]
2023-09-21T20:40:41.171467153-05:00 stdout F 01:40:41,166 |-INFO in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@327ed9f5 - No compression will be used
2023-09-21T20:40:41.171488099-05:00 stdout F 01:40:41,166 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.access.PatternLayoutEncoder] for [encoder] property
2023-09-21T20:40:41.171544182-05:00 stdout F 01:40:41,170 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[access_log] - Active log file name: logs/access.log
2023-09-21T20:40:41.171565685-05:00 stdout F 01:40:41,170 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[access_log] - File property is set to [logs/access.log]
2023-09-21T20:40:41.171585252-05:00 stdout F 01:40:41,170 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [access_log] to ch.qos.logback.access.tomcat.LogbackValve[null]
2023-09-21T20:40:41.171603517-05:00 stdout F 01:40:41,170 |-INFO in ch.qos.logback.access.joran.action.ConfigurationAction - End of configuration.
2023-09-21T20:40:41.171625552-05:00 stdout F 01:40:41,170 |-INFO in ch.qos.logback.access.joran.JoranConfigurator@67594471 - Registering current configuration as safe fallback point
2023-09-21T20:40:41.171647072-05:00 stdout F 01:40:41,170 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Done configuring
github-actions[bot] commented 9 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 9 months ago

On a standard setup, it is used properly. My /config/data/system.properties file has it in there.

2 things you can try:

JonathanTroyer commented 9 months ago

Looks like recreating the folder was the ticket. Having an environment variable work only on first run is a bit odd, but it's working for me now.