Restart other services (ZM, Sonarr) from HASS

Hello guys!

I have zoneminder, sonarr, radarr etc services running on my server.

I already managed to check if its running or not in HASS but no idea how to automate the restart.

shell command: sudo systemctl restart zoneminder.service obviously not working.

Any ideas?

If you are running HA as a specific user, the chances are that the user doesn’t have sudo access. It is generally not a good idea to give the user sudo access, to prevent it being used to control your machine in the event of some successful hacking attempt.

If you want zoneminder to restart when it exits, you should investigate using the Restart=always option in the service file, which is probably in /etc/systemd/system. Try man systemd.service to see the options.

1 Like

The easiest would be allowing the user hass runs under (assuming this is not root) to use certain sudo commands.
You can restrict the allowed commands/arguments in /etc/sudoers like this:

hass ALL=NOPASSWD: /bin/systemctl restart zoneminder.service

You can repeat those lines and expand with the required services and/or commands hass needs to be able to execute.

In hass you can then do the requested shell command (although I would be explicit in the location of systemctl just to be sure)

2 Likes

I tried this:

# User privilege specification
root    ALL=(ALL:ALL) ALL
falkaub ALL=NOPASSWD: /bin/systemctl restart zoneminder.service
falkaub ALL=NOPASSWD: /bin/systemctl restart sonarr.service

It’s still asking for the PW. Tried restarting the pc, but same results. Wheres my fckup?