eschava / psmqtt

Utility reporting system health and status via MQTT
MIT License
159 stars 35 forks source link

In Docker on Debian 12 : Exception: Use sudo to read '/dev/nvme0' SMART data #45

Open deepcoder opened 6 months ago

deepcoder commented 6 months ago

Under docker, even if I sudo docker run, I receive the following error for the disk info.

Linux yippie-ha 6.1.0-18-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.76-1 (2024-02-01) x86_64 GNU/Linux

[2024-05-07 17:43:14,103] ERROR Use sudo to read '/dev/nvme0' SMART data
[2024-05-07 17:43:14,103] INFO mqttc.publish('psmqtt/yippie-ha/smart/nvme0/temperature/error', 'Use sudo to read '/dev/nvme0' SMART data')
[2024-05-07 17:43:14,103] ERROR run_task caught: smart/nvme0/temperature : Use sudo to read '/dev/nvme0' SMART data
Traceback (most recent call last):
  File "/opt/psmqtt/src/task.py", line 154, in run_task
    payload = get_value(task)
              ^^^^^^^^^^^^^^^
  File "/opt/psmqtt/src/handlers.py", line 802, in get_value
    value = handler.handle(tail)
            ^^^^^^^^^^^^^^^^^^^^
  File "/opt/psmqtt/src/handlers.py", line 536, in handle
    raise Exception(errmsg)
Exception: Use sudo to read '/dev/nvme0' SMART data

Thank you for your work and help!

f18m commented 6 months ago

hi @deepcoder ,

Under docker, even if I sudo docker run, I receive the following error for the disk info.

Using 'sudo docker run' is not doing what you think probably. The 'docker' program is just a client for the dockerd server which runs as a daemon in background. The 'docker' client is just asking the server to start a new container when you use 'docker run'. Doing that with root permissions does not mean that the new container will be started by the server with root permissions. To do that, you should be using 'docker run --privileged'. This is mentioned in the README at https://github.com/eschava/psmqtt?tab=readme-ov-file#deploy-with-docker Can you retry with --privileged?

deepcoder commented 6 months ago

I was using the 'privileged' in both my non sudo and sudo attempts, as per your documentation. Both throw the same error. The docker commands I tried are listed below. FYI, trying to use ":latest" for the image threw a different error and would not start container, so I hard coded the v1 image version.

docker run -d -v /home/user/psmqtt/psmqtt.conf:/opt/psmqtt/conf/psmqtt.conf \
   --privileged --hostname $(hostname) \
   ghcr.io/eschava/psmqtt:latest

docker run -d -v /home/user/psmqtt/psmqtt.conf:/opt/psmqtt/conf/psmqtt.conf \
   --name="psmqtt-1.0.0" \
   --privileged --hostname $(hostname) \
   ghcr.io/eschava/psmqtt:1.0.0
f18m commented 6 months ago

I was using the 'privileged' in both my non sudo and sudo attempts, as per your documentation. Both throw the same error. The docker commands I tried are listed below. FYI, trying to use ":latest" for the image threw a different error and would not start container, so I hard coded the v1 image version.


docker run -d -v /home/user/psmqtt/psmqtt.conf:/opt/psmqtt/conf/psmqtt.conf \
   --privileged --hostname $(hostname) \
   ghcr.io/eschava/psmqtt:latest

You're right the 'latest' tag is not being pushed. FYI I have an issue open on the github action project: https://github.com/mr-smithers-excellent/docker-build-push/issues/238

docker run -d -v /home/user/psmqtt/psmqtt.conf:/opt/psmqtt/conf/psmqtt.conf \ --name="psmqtt-1.0.0" \ --privileged --hostname $(hostname) \ ghcr.io/eschava/psmqtt:1.0.0


This one however should really work. Can you run 'sudo smartctl --scan' (outside of any docker container) and paste the output here?
f18m commented 5 months ago

ping @deepcoder