balena-labs-projects / balena-node-red

a node-red application with balena-supervisor support, can be managed remotely via balena publicURL
Apache License 2.0
60 stars 59 forks source link

Node-RED readonly #18

Open owarek opened 5 years ago

owarek commented 5 years ago

When I want to change backlight of RPi display, it trhrows: Error: EROFS: read-only file system, open '/sys/class/backlight/rpi_backlight/bl_power

Is there a way to do this on readonly FS or how do I change the FS to writable?

Thank you in advance.

imrehg commented 5 years ago

Hey @owarek, are you deploying this project as it is, or are you combining it with other containers in a multicontainer setup?

owarek commented 5 years ago

I have it as multicontainer setup. This is my compose file:

version: '2' volumes: node-red-data: services: wpe: restart: always build: ./wpe privileged: true scheduler: restart: always build: ./scheduler privileged: true mqtt: image: panuwitp/mosquitto-arm ports:

  • "1883:1883" node-red: build: ./node-red privileged: true
    volumes:
  • 'node-red-data:/data' ports:
  • "1880:1880" depends_on:
  • mqtt restart: always
imrehg commented 5 years ago

Hi, probably you need to paste that in not a ">" style of "quoting" but the code block as triple-backticks (`), see more in the help https://help.github.com/en/articles/creating-and-highlighting-code-blocks

And since you are using a completely different way of deploying the project, it's harder to answer what might be the issue. If you just deploy this particular project as it is in the repo, do you have the same error?

My guess would have been the privileged: true setting being required (that "read-only" warning being more a permission issue, than actual read only file system issue for /sys, as much as I know). Since it seems in your code you already use that, we will need to check further what other source of that error might be.

imrehg commented 5 years ago

Also, how are you changing the backlight of a display, and what display are you using? Do you have things shown on the display normally besides this issue? I'm guessing that the WPE service manages the display normally?

imrehg commented 5 years ago

I think you have the 7" Raspberry Pi display, right? Just tried that with this particular project, and use echo to write to that setting. The command returns an error, but the value is being set correctly. Here's the log from the node-red service's container (deployed as this project)

bash-4.4# echo 1 > /sys/class/backlight/rpi_backlight/bl_power
bash: echo: write error: Invalid argument
bash-4.4# cat /sys/class/backlight/rpi_backlight/bl_power
1
bash-4.4# echo 0 > /sys/class/backlight/rpi_backlight/bl_power
bash: echo: write error: Invalid argument
bash-4.4# cat /sys/class/backlight/rpi_backlight/bl_power
0

and looking at the screen, indeed it turns it off when 1 is sent, and turn it on when 0 is sent.

Thus it should work from the container, just have to find what setting is required. This does not seem to be the issue of this node-red project, however, regardless of the outcome.

owarek commented 5 years ago

Thank you for investigating this. Here is the compose file again:

volumes:
    node-red-data:
services:
  wpe:
    restart: always
    build: ./wpe
    privileged: true
  scheduler:
    restart: always
    build: ./scheduler
    privileged: true
  mqtt:
    image: panuwitp/mosquitto-arm
    ports:
      - "1883:1883"
  node-red:
    build: ./node-red
    privileged: true  
    volumes:
       - 'node-red-data:/data'
    ports:
       - "1880:1880"
    depends_on:
        - mqtt
    restart: always

and here is the dockerfile for node-red:


COPY ./settings.js /data/settings.js

USER root
RUN apt-get update && apt-get install nano
USER node-red

RUN npm install node-red-contrib-resinio
RUN npm install node-red-dashboard
RUN npm install node-red-contrib-credentials
RUN npm install node-red-admin
RUN npm install --save rpi-backlight

And yes I have the 7" RPi touch display. This is the output from terminal of node-red container:

node-red@cc2011243739:~$ echo 1 > /sys/class/backlight/rpi_backlight/bl_power
bash: /sys/class/backlight/rpi_backlight/bl_power: Permission denied
node-red@cc2011243739:~$ cat /sys/class/backlight/rpi_backlight/bl_power
0

In wpe and scheduler it works. In mqtt and node-red it does not.

imrehg commented 5 years ago

@owarek I think the issue is that you are setting the user in node-red:

USER node-red

thus that user doesn't have the privileges to modify the file. So I think you will have to set up that user to have the right permissions, or keep using the root user?

owarek commented 5 years ago

Yes, that may be the reason but I do not know how to add permisions to write to that file to nodered user. I have tried to add sudo chmod 777 after ther USER root in dockerfile and also tried to chown node-red in host OS both with no success. Only thing that worked is chmod 777 in host OS. Do you have any idea how to set this differently or more safe?

imrehg commented 5 years ago

You are already running a privileged container, not sure what's the reason you are trying to switch the user. As you see in this project as well, that the user is not switched. I think the main way to solve this to use a root user as you already do in the other two containers anyways.