Rhasspy as service with Debian installation

This post is a placeholder description for how to setup the standalone Rhasspy voice-assistant as a service on Debian/Ubuntu until the official docs are updated. This was gleaned from various posts on the Rhasspy forums and the OLD Rhasspy github, and then refined via trial and error.

Steps:

  1. Create a service account to run the Rhasspy daemon as a service. Instructions are here.
  2. Switch to the Rhasspy service account
$ sudo su rhasspy
$ cd ~
  1. Install the Rhasspy based on your use case. For me, this was for running Rhasspy as a satellite on various Raspberry Pi 4s around the house, that use a central Rhasspy instance running as a server interconnected with Home Assistant.

  2. Make sure that Rhasspy runs

$ rhasspy --profile en 2>&1 | cat

In a browser, navigate to http://:12101

You should see the following:

If you are good, then stop Rhasspy by using the keystrokes [CNTL]+C

  1. Switch back to your privileged account
$ exit
  1. Setup up the service account config directory
$ sudo mkdir /opt/rhasspy
  1. Create the service definition file
$ sudo nano /etc/systemd/system/rhasspy.service

then

[Unit]
Description=Rhasspy Service
After=syslog.target network.target mosquitto.service

[Service]
Type=simple
# for command, see https://github.com/rhasspy/rhasspy/issues/42#issuecomment-711472505
ExecStart=/bin/bash -c 'rhasspy -p en --user-profiles /home/rhasspy/.profiles/rhasspy 2>&1 | cat'
WorkingDirectory=/opt/rhasspy
User=rhasspy
Group=audio
RestartSec=10
Restart=on-failure
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rhasspy

[Install]
WantedBy=multi-user.target

Save the file using [CNTL]+o, and [CNTL]+z

  1. Enable the service
$ sudo systemctl enable rhasspy
  1. Now start the service
$ sudo systemctl daemon-reload
$ sudo systemctl start rhasspy
  1. Test that Rhasspy works by navigating to the Rhasspy Admin website on the device

In a browser, navigate to http://:12101

You should see the following:

If you are good, you should be able to start configuring the device as a satellite by following the instructions on the Rhasspy documentation site.

As is the case with all techno-things this approach will become outdated over time, so check the commands against the current version of Debian or Ubuntu. Drop me a line on Twitter if you find this useful or if needs updating.

Creating a Linux user who cannot get an interactive shell on Debian or Ubuntu

Every now and then you find yourself repeating the same Linux admin tasks, querying the community and having to piecemeal together an answer. This is the case with creating a “service account” to run satellite instances of Rhasspy on a bunch of Debian-based IoT devices scattered around my house. The purpose is so that you aren’t running a service (daemon) as yourself or as root. This creates a situation where if someone where to use the webpage to somehow hack into the computer, they would be limited in what they can do because they won’t have access immediately to a Linux shell.

3D Printed Rhasspy running on Raspberry Pi4 courtesy @tobetobe

The commands below will create a user named ‘rhasspy’ with its own $HOME directory for placing the settings in the “.profile/rhasspy” and for installing the service account’s instance of a Python environment. Because rhasspy uses the audio resources of the computer indirectly, I went ahead and added the $username to the ‘audio’ group. and then finally set the default shell of the $username to ‘/sbin/nologin’.

username=rhasspy
password=REPLACEWITHYOUROWNPASSWORD

sudo adduser --comment "" --disabled-password $username
sudo chpasswd <<<"$username:$password"
sudo usermod -a -G audio $username
sudo usermod -s /sbin/nologin $username

As is the case with all techno-things this approach will become outdated over time, so check the commands against the current version of Debian or Ubuntu. Drop me a line on Twitter if you find this useful or if needs updating.