vectronic / homebridge-ping-hosts

Ping state sensor plugin for homebridge

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Socket creation error in raw_socket crashes homebridge on ping

scastan13 opened this issue · comments

No problem on install or configuration. Simply trying to ping a local network device.
Each time the plugin tries to ping a host it crashes Homebridge :

[2020-7-21 11:43:04] Error: Operation not permitted
at new Socket (/usr/local/lib/node_modules/@vectronic/homebridge-ping-hosts/node_modules/raw-socket/index.js:47:14)
at Object.exports.createSocket (/usr/local/lib/node_modules/@vectronic/homebridge-ping-hosts/node_modules/raw-socket/index.js:202:9)
at Session.getSocket (/usr/local/lib/node_modules/@vectronic/homebridge-ping-hosts/node_modules/net-ping/index.js:147:20)
at new Session (/usr/local/lib/node_modules/@vectronic/homebridge-ping-hosts/node_modules/net-ping/index.js:101:7)
at Object.exports.createSession (/usr/local/lib/node_modules/@vectronic/homebridge-ping-hosts/node_modules/net-ping/index.js:545:9)
at PingHostContactAccessory.doPing (/usr/local/lib/node_modules/@vectronic/homebridge-ping-hosts/index.js:85:24)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7)
[2020-7-21 11:43:04] Got SIGTERM, shutting down Homebridge...
[2020-7-21 11:43:04] [RPi] localhost: disconnected from localhost:8888
[2020-7-21 11:43:09] [RPi] goodbye
homebridge.service: Main process exited, code=exited, status=143/n/a
homebridge.service: Unit entered failed state.
homebridge.service: Failed with result 'exit-code'.
homebridge.service: Service hold-off time over, scheduling restart.
Stopped Node.js HomeKit Server.

Any Idea of what going on ?

Looks like a user permissions issue. See the documentation for the underlying module being used here:

https://github.com/nospaceships/node-raw-socket#readme

In the section: "Raw Socket Behaviour" it explains some OSes restrict raw sockets to privileged users and in this case you will get a Operation not permitted error.

What OS are you running homebridge on and as what user?

Many Thanks for your concern.

This is running on a Linux raspian OS : PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
User is a dedicated "homebridge" user.

No particular explanation on node_raw_socket#readme but I find this one more explicit and also using raw_socket on a RPi with a homebridge user (like me) :
AlexGustafsson/homebridge-wol#8

I've try to find how to give my homebridge user the CAP_NET_RAW capabilities... without success... capabilities seems to be more aimed to process than to users.

Instead, to make a try, I've tried to make my homebridge a "root like" user (by using visudo) but unfortunatly got the same result as before :
[2020-7-21 19:38:50] Error: Operation not permitted
at new Socket (/usr/local/lib/node_modules/@vectronic/homebridge-ping-hosts/node_modules/raw-socket/index.js:47:14)

Any idea ?

I am pretty sure this is just the fact that CAP_NET_RAW is not set on the node executable.

Please try something like:

sudo setcap cap_net_raw+eip $(eval readlink -f `which node`)

(no guarantees that will work on Raspbian).

If I get time next weekend I will try to replicate on a RaspberryPi I have here...

Dude You got it !!!

This exact command worked for me on the RPi. This may be helpfull to add it on plugin Readme ?

Now the sensors works perfectly : closed if device is reachable, opened if not.

Many thanks.

Good news! Updating readme now. thx.

commented

I'm running homebridage in a docker on Synology NAS, the command, how can I run the command in docker?

Thanks.

Google search leads me to using --cap-add on the docker command:

https://docs.docker.com/engine/reference/commandline/run/

No guarantees that will work but give it a try. To be clear this is not an issue with this plugin, it is a security constraint imposed by the OS.