Restart service via Telegram bot

I’m using Tor hidden services for GUI and SSH, with a Telegram bot as fallback for when Tor occasionally decides to stop working.

I would like to be able to restart Tor via the bot, so I have added this to my configuration.yaml:

  restart_tor: 'sudo systemctl restart tor'

When ran, I get this:

hassbian sudo[2437]: pam_unix(sudo:auth): conversation failed
hassbian sudo[2437]: pam_unix(sudo:auth): auth could not identify password for [homeassistant]
hassbian hass[2380]: 2019-01-12 23:58:15 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `systemctl restart tor`, return code: 1
hassbian hass[2380]: NoneType: None

I’m assuming user homeassistant does not have the necessary rights to do this?

Without sudo, the error is practically the same, just without the pam_unix lines.

Any ideas on how to achieve this?

Here’s the solution

Basically I added this line

%homeassistant ALL= NOPASSWD: /bin/systemctl restart tor



That file must have an empty line at the end!

I’m now trying to restart Home Assistant in the same manner. It works, but it throws return code -15. I’ve tried googling this, but everything I’ve found suggests there are no negative return codes…any idea what this return code might mean?

Have you solved this “return code: -15” issue?

Nope; I just ignored it since the restart worked anyway and I couldn’t find anything on “-15”.