I'm running a streaming radio on my Raspberry Pi 3 using MPD (Music Player Daemon). We are only 2 to use this radio, and most of the time, neither of us are connected to listen to the radio, which means that the service is running for nothing. I checked that MPD is idling at 5% CPU and goes up to close to 40% when anyone connects, but in a more general way, I was wondering if there was some interruption, system notification or something like that which could be used to trigger a command, say, when someone connects on a specific port, or disconnects from it.
The goal would be to only run a service when needed.
I am using nginx as server, if that's of any help.
Only thing I could gather is a constant polling like what is mentioned here : https://www.tecmint.com/find-all-clients-connected-to-http-or-https-ports/ But, of course, I would need to be "instantly" reactive and not wait in between two pollings.