WebThingsIO / gateway

WebThings Gateway - a self-hosted web application for monitoring and controlling a building over the web
http://webthings.io/gateway
Mozilla Public License 2.0
2.61k stars 339 forks source link

Gateway 1.1 docker image does not work for fresh installs #3043

Open werto165 opened 1 year ago

werto165 commented 1 year ago

I am trying to run the follow image: webthingsio/gateway:1.1.0-alpha.1 on bullseye

+ WEBTHINGS_HOME=/home/node/.webthings
+ args=
+ start_task=run-only
+ is_container
+ '[' -f /.dockerenv ']'
+ return 0
++ node --version
++ egrep -o '[0-9]+'
++ head -n1
+ _node_version=12
+ [[ ! -f /home/node/.webthings/.node_version ]]
+ cd /home/node/webthings/gateway
+ mkdir -p /home/node/.webthings/config
+ ./tools/update-addons.sh
Creating database: /home/node/.webthings/config/db.sqlite3
/home/node/webthings/gateway/build/models/things.js:377
addon_manager_1.default.on(Constants.THING_ADDED, (thing) => {
                        ^

TypeError: Cannot read property 'on' of undefined
    at Object.<anonymous> (/home/node/webthings/gateway/build/models/things.js:377:25)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/node/webthings/gateway/build/models/actions.js:40:34)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
Process 10 died: No such process; trying to remove PID file. (/run/avahi-daemon//pid)
+ WEBTHINGS_HOME=/home/node/.webthings
+ args=
+ start_task=run-only
+ is_container
+ '[' -f /.dockerenv ']'
+ return 0
++ node --version
++ egrep -o '[0-9]+'
++ head -n1
+ _node_version=12
+ [[ ! -f /home/node/.webthings/.node_version ]]
+ cd /home/node/webthings/gateway
+ mkdir -p /home/node/.webthings/config
+ ./tools/update-addons.sh
Opening database: /home/node/.webthings/config/db.sqlite3
/home/node/webthings/gateway/build/models/things.js:377
addon_manager_1.default.on(Constants.THING_ADDED, (thing) => {
                        ^

TypeError: Cannot read property 'on' of undefined
    at Object.<anonymous> (/home/node/webthings/gateway/build/models/things.js:377:25)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/node/webthings/gateway/build/models/actions.js:40:34)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)

seems like addon_manager_1.default is not being created therefore its null. any help would be appreciated

benfrancis commented 1 year ago

@werto165 Thanks for the bug report.

Can you please test 1.1.0-beta.2 and let me know whether you're still seeing this issue? https://hub.docker.com/layers/webthingsio/gateway/1.1.0-beta.2/images/sha256-db33eda9461c15f08fce3118cdef3d2a08b6155721564293d97c9386e426deaf?context=explore

MichaelKohler commented 1 year ago

I'm running 1.1.0-beta.2 on bullseye (Raspbian, Pi 4 Model B) without any issue:

 ❯ docker ps -a
CONTAINER ID   IMAGE                              COMMAND                  CREATED         STATUS       PORTS                                                                                                                             NAMES
f8071075060f   webthingsio/gateway:1.1.0-beta.2   "/init.sh"               10 days ago     Up 10 days                                                                                                                                     webthings
ianlockhead commented 1 year ago

Hi, I have same issue with docker on Ubuntu. Was this fixed in stable release 1.1?

benfrancis commented 1 year ago

See also: https://discourse.mozilla.org/t/issue-starting-docker-image/109712/2 for someone else experiencing this issue.

ianlockhead commented 1 year ago

@benfrancis OK so after few attempts I find out where the problem was. An incorrect config in the portainer stack with timezone settings. Image with Gateway 1.1.0 is fully working now! The correct config for portainer stack or docker-compose is:

version: '4'
services:
  webthings:
    container_name: webthings
    image: "webthingsio/gateway"
    volumes:
      - /home/dell/docker/webthings/:/home/node/.webthings
    network_mode: host
    environment:
      - "TZ=Europe/Prague"
    restart: always
    logging:

      options:
        max-size: "1m"
        max-file: "10"
benfrancis commented 1 year ago

See also: #3065, in which the same error is produced on a Raspberry Pi 3.

benfrancis commented 1 year ago

https://github.com/WebThingsIO/gateway/issues/3065#issuecomment-1396054320 suggests that the 1.1 docker image only works when upgrading a 1.0 image and the 1.1 image doesn't work when installed from fresh. Possibly because the SQLite database doesn't get created properly on first start.

It would be good if someone could test that and report back if they can reproduce it.

Edit: It appears just copying an SQLite database from a 1.0 installation doesn't fix the problem, files generated by the 1.0 installation are needed https://github.com/WebThingsIO/gateway/issues/3065#issuecomment-1399559803

benfrancis commented 1 year ago

https://github.com/WebThingsIO/gateway/issues/3066#issue-1551494583 offers a workaround "putting a text file in the /home/node/.webthings folder named .node_version and ensure it's content is 12 will result in the image starting properly"

benfrancis commented 1 year ago

Thanks for the workaround, @kcusoundman.

It would be great if we could turn that into a patch so we can release a working 1.1.1 release of the docker image.

As far as I can tell, the .node_version file is meant to be created by run-app.sh if the gateway is running inside a container and the file does not already exist. See lines 48-62 https://github.com/WebThingsIO/gateway/blob/v1.1.X/run-app.sh#L48

At a guess one of the lines between line 56 and 59 is failing to execute and causing the startup script to crash. If the file already exists and its contents matches the node version running inside the container then those lines are skipped.

Is anyone able to debug this inside a docker container and come up with a proposed fix?

benfrancis commented 1 year ago

See also #3109