Problem with addon I made (can not start js file MODULE_NOT_FOUND)?

When I run image manualy using this command, works without problem:
run --rm -it --device /dev/video0 -p 8554:8554 --entrypoint /init image_name

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
2022/03/30 13:35:58 Starting Rpos
cat: /proc/device-tree/model: No such file or directory
Read IP address 172.17.0.3 from eth0
Manufacturer : Raspberry Pi
Model : 2 B
HardwareId : 
SerialNumber : 00000000d83271ec
FirmwareVersion : 2.1.0
Starting camera settings webserver on http://172.17.0.3:8081/
v4l2ctl.json does not exist yet or invalid.
Binding DeviceService to http://172.17.0.3:8081/onvif/device_service
Binding MediaService to http://172.17.0.3:8081/onvif/media_service
Binding PTZService to http://172.17.0.3:8081/onvif/ptz_service
Binding ImagingService to http://172.17.0.3:8081/onvif/imaging_service
discovery_service started
imaging_service started
ptz_service started
device_service started
Starting Live555 rtsp server
media_service started

When I build addon and start I get error:

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
2022/03/30 15:03:15 Starting Rpos
node:internal/modules/cjs/loader:936
  throw err;
  ^
Error: Cannot find module '/data/rpos/rpos.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
Node.js v17.8.0
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.

Dockerfile

FROM ghcr.io/home-assistant/armhf-base-raspbian:bullseye

# Install requirements for add-on
RUN apt-get update && apt-get install -y \
    nodejs \
    npm \
    liblivemedia-dev \
    liblivemedia-dev \
    liblog4cpp5-dev \
    cmake \
    libasound2-dev \
    v4l-utils
    
# So let's set it to our add-on persistent data directory.
WORKDIR /data

# install onvif server
# install npm and node.js (latest 17 in 26.3.22)
RUN npm install -g n \
    && n install 17
RUN git clone https://github.com/BreeeZe/rpos.git \
    && cd rpos \
    && npm install
    
# So let's set it to our add-on persistent data/rpos directory.
WORKDIR /data/rpos 

RUN npx gulp
    
# instal v4l2rtspserver
RUN git clone https://github.com/mpromonet/v4l2rtspserver.git \
    && cd v4l2rtspserver/ \
    && cmake . \
    && make \
    && make install

COPY rposConfig.json /data/rpos/
COPY run /etc/services.d/rpos/run
COPY finish /etc/services.d/rpos/finish

ENTRYPOINT ["/init"]

config.yaml

name: "Raspberry camera ONVIF server add-on"
description: "ONVIF server from raspberry pi camera"
version: "0.0.1a"
slug: "rpi-camera-rtsp-server-onvif"
arch:
  - armhf
  - armv7
ports:
  8554/tcp: 8554
ports_description:
  8554/tcp: Web interface (Not required for Ingress)
video: true

run

#!/usr/bin/with-contenv bashio
echo "$( date +'%Y/%m/%d %H:%M:%S' ) Starting Rpos"
cd /data/rpos
exec  /usr/local/bin/node /data/rpos/rpos.js

finish

#!/usr/bin/execlineb -S1
if { s6-test ${1} -ne 0 }
if { s6-test ${1} -ne 256 }
s6-svscanctl -t /var/run/s6/services

Did you sort this out?
looks like it might be path issue… to my limited knowledge.
my only suggestion is to rename the finish file to something like

skip_no_finish

I’d then use portainer/exec console or ssh to poke around inside the container and see if things are where they should be.

Thx for replay.

Path is correct, problem is probably some setting in config.yaml, but everything I tried not working.

I already try to add in config.yaml:

init: false
full_access: true

My knowledge is also limited and I don’t know where is difference if I run image manually or starting addon.

Some things get shifted around in an addon abit, and data doesn’t exist until the container is started. So I think your /data is getting overwritten because data is on the host. The s6 stuff moves things to run/s6/etc or similar.

GitHub - habuild/hassio-addons: Home Assistant addon using SBFspot Bluetooth SMA inverters have a poke round there if you want to look at my poor quality examples.

Lint and builder might help you too in the github work flows.

I will try with different folder.

Thx @HasQT , folder was the problem :slight_smile:

1 Like

Hi,

I found this thread, I was looking for an onvif server… Can I also use your addon to convert an rtsp camera to onvif ?

I have found this one on your GitHub, found rpos before…

Can I use that one to convert an rtsp camera to make it onvif compatible?