unifi-docker icon indicating copy to clipboard operation
unifi-docker copied to clipboard

Single /unifi volume fails with external mongodb on first run

Open jtackaberry opened this issue 5 years ago • 9 comments

There is an issue with docker-entrypoint.sh that does not properly handle a single volume mapped to /unifi (i.e. not /unifi/data, /unifi/log etc. directly but using a single /unifi to cover them all) while also defining the env vars needed to specify an externally hosted mongodb instance (or, more incidentally, LOTSOFDEVICES)

The values in system.properties are not properly set at first run, which results in a container-local mongo instance being spun up and used instead. An unsuspecting user (like me) would then proceed to setup the Unifi instance, and then after reinstantiating the container (whereupon system.properties is configured properly this time to use the external instance), find none of the data is there.

The root cause is the log and data directories are created after system.properties is updated.

On first run (with a pristine /unifi volume being mounted), confSet fails because /unifi/data doesn't exist, resulting in a default system.properties. /unifi/data is then created and the controller started, but because we're using the defaults, the container-local mongodb instance is started and used. The next time the container is instantiated, /unifi/data exists so confSet succeeds, causing the controller to point to the external instance as previously expected.

jtackaberry avatar Jan 28 '20 03:01 jtackaberry

I've replicated this issue with the following compose file

version: "3.7"

    unifi-mongo:
        image: mongo:3.6
        container_name: unifi-mongo
        networks:
        - unifi
        restart: unless-stopped
        volumes:
        - /home/user/docker/volumes/unifi-mongo/db:/data/db
        - /home/user/docker/volumes/unifi-mongo/dbcfg:/data/configdb
  
    unifi:
        image: jacobalberty/unifi
        init: true
        container_name: unifi
        depends_on:
         - unifi-mongo
        networks:
         - unifi
        restart: unless-stopped
        volumes:
          - /home/user/docker/volumes/unifi:/unifi
        env_file:
          - env/unifi.env
        ports:
          - "3478:3478/udp"
          - "6789:6789/tcp"
          - "8880:8880/tcp"
          - "8843:8843/tcp"
          - "8080:8080/tcp"
          - "8443:8443/tcp"
          - "10001:10001/udp"
    
    networks:
      unifi:

simonmarty avatar Jul 16 '20 06:07 simonmarty

I think this is related to #165

darkpixel avatar Oct 20 '21 02:10 darkpixel

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Jan 13 '22 02:01 github-actions[bot]

Go away stalebot.

darkpixel avatar Jan 13 '22 03:01 darkpixel

Watching this I'll try to come take a closer look this weekend.

jacobalberty avatar Jan 13 '22 03:01 jacobalberty

No worries. I haven't had much time to dive into the details of why it isn't working exactly. On my kubernetes cluster I just deal with it by restoring a site backup whenever the controller restarts.

darkpixel avatar Jan 13 '22 03:01 darkpixel

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Feb 13 '22 02:02 github-actions[bot]

Go away stalebot.

darkpixel avatar Feb 14 '22 16:02 darkpixel

Was this fixed with PR #419 ?

maxirus avatar Jul 01 '22 18:07 maxirus