neilenns / node-deepstackai-trigger

Detects motion using Deepstack AI and calls registered triggers based on trigger rules.
MIT License
165 stars 28 forks source link

Latest release fails to start #394

Closed neilenns closed 3 years ago

neilenns commented 3 years ago

Describe the bug Latest release with the new secrets stuff fails to start up

Log entries

This is what I get on my actual deployed instance:

2020-11-06T07:27:26-08:00 [Main] ****************************************

2020-11-06T07:27:26-08:00 [Main] Starting up version 5.5.0

2020-11-06T07:27:26-08:00 [Main] Timezone offset is 480

2020-11-06T07:27:26-08:00 [Main] Current time is Fri Nov 06 2020 07:27:26 GMT-0800 (Pacific Standard Time)

2020-11-06T07:27:26-08:00 [Settings] Unable to read the settings file: ENOENT: no such file or directory, open '/run/secrets/settings'.

2020-11-06T07:27:26-08:00 [Main] [Settings] Unable to load file /run/secrets/settings.

And this is what I get in the main branch trying to debug this:

2020-11-06T07:33:51-08:00 [Main] ****************************************
src/Log.ts:36
2020-11-06T07:33:51-08:00 [Main] Starting up version 5.5.0
src/Log.ts:36
2020-11-06T07:33:51-08:00 [Main] Timezone offset is 480
src/Log.ts:36
2020-11-06T07:33:51-08:00 [Main] Current time is Fri Nov 06 2020 07:33:51 GMT-0800 (Pacific Standard Time)
src/Log.ts:36
2020-11-06T07:33:51-08:00 [Settings] Unable to read the secrets file: ENOENT: no such file or directory, open '/run/secrets/secrets'.
src/Log.ts:45
2020-11-06T07:33:51-08:00 [Settings] Loaded settings from /run/secrets/settings
src/Log.ts:36
2020-11-06T07:33:51-08:00 [MQTT] Connected to MQTT server mqtt://mqtt:1883
src/Log.ts:36
2020-11-06T07:33:51-08:00 [Local storage] Creating local storage folders in /node-deepstackai-trigger.
src/Log.ts:36
2020-11-06T07:33:51-08:00 [Local storage] Enabling background purge every 60 minutes for files older than 30 minutes.
src/Log.ts:36
2020-11-06T07:33:51-08:00 [Local storage] Running purge
src/Log.ts:36
2020-11-06T07:33:51-08:00 [Main] Web server enabled.
src/Log.ts:36
2020-11-06T07:33:51-08:00 [Triggers] Unable to read the secrets file: ENOENT: no such file or directory, open '/run/secrets/secrets'.
src/Log.ts:45
neilenns commented 3 years ago

@TonyBrobston I'm digging into this but if you have a few minutes and can look at it too it would be appreciated. Looks like we missed something during the code reviews and a straight upgrade to the new release breaks existing installs.

neilenns commented 3 years ago

This looks like it's two separate problems. The one I'm seeing in local development is because replaceSecrets doesn't check for a null secrets before attempting to do a replacement.

Adding this to the function resolves that problem in the local dev environment:

  // If no secrets were provided don't attempt to do a replacement
  if (!secrets) return;

That gets me past the issue to the same one that I see in my deployed instance. Looking into that now.

neilenns commented 3 years ago

Ok I think I figured this out. This happens when:

  1. You don't have a secrets file
  2. You use existing mustache templates in the settings or triggers file

The above code really needs to be:

  // If no secrets were provided don't attempt to do a replacement
  if (!secrets) return settings;
neilenns commented 3 years ago

Ok this still isn't fully fixed. Looks like there is an issue where if it fails to load from /run/secrets/settings it never attempts to load from /config/settings.json.

neilenns commented 3 years ago

Looks like the remaining issue is in readSettings() which was throwing an exception instead of just logging and returning null, which prevented the .some() from proceeding to try and load from the alternate locations.

neilenns commented 3 years ago

Confirmed this now works on my real deployment. Just waiting for the latest build to pass with updated unit tests then I'll release this.

TonyBrobston commented 3 years ago

@danecreekphotography I'm just now seeing this thread.

Sounds good.

davkav commented 3 years ago

FIXED: secrets.json needs to be created in the secrets folder along with settings.json and triggers.json.

Setting this up for the first time.

Configured my docker-compose file as follows, and I am seeing the error reported for this issue i.e. "[Settings] Unable to read the secrets file: ENOENT: no such file or directory, open '/run/secrets/secrets'."



  deepstack-ai:
    container_name: deepstack-ai
    image: deepquestai/deepstack:latest
    restart: always
    volumes:
      - /mnt/storage/deepstack:/datastore
    environment:
      - VISION-DETECTION=True

  trigger:
    container_name: trigger
    volumes:
      - //192.168.0.88//aiinput:/aiinput
    environment:
      - PUID=$PUID
      - PGID=$PGID
      - TZ=$TZ
    ports:
      - "4242:4242"
    secrets:
      - triggers
      - settings
    image: danecreekphotography/node-deepstackai-trigger:latest
    restart: always
    depends_on:
      - deepstack-ai```