Best way to autorun at boot?

Hello guys, i’m just learning linux so i’m not an expert,
i have rhasspy installed on a raspberry whit a .deb package and i start it from console whit : rhasspy --profile en
Now i want to autostart at boot, what is the best way to do it?
i have learned the service venv, but i don’t understand if i can use it or i have to reinstall rhasspy whit venv? :confounded:
I just try systemd but rhasspy doesn’t start :frowning:
what i’m doing wrong?

I use the deb package as well. I didn’t want to deal with making rhasspy a service so I just used python and screen, worked for me. I have no idea if my way is the best way, I doubt it.

#!/usr/bin/python3
import time
import os
time.sleep(20) #sets a time delay so that systems can catch up as we run this script at startup via cron
#the below command runs screen as another user
startvoicestuff = ‘su - YOURUSERNAME -c “/usr/bin/screen -d -m -S rhasspystuff rhasspy --profile en”’
os.system(startvoicestuff) #sends the command to the system
#name this script rhasspystart.py and set it to executable
#sudo chmod +X rhasspystart.py
#install screen if it is not installed sudo apt-get install screen
#now lets set up a cron job
#sudo crontab -e
#put this at the bottom of the contab file sans the comment tag # at the start and correct the path to match yours
#@reboot screen -d -m -S startrhasspy python3 /path/to/thisfile/rhasspystart.py
#be sure your user is in the audio group if it is not
#sudo adduser YOURUSERNAME audio

Thanks, but i miss somethings and don’t start :frowning:
startvoicestuff = ‘su - YOURUSERNAME -c “/usr/bin/screen -d -m -S rhasspystuff rhasspy --profile en”’
here in YOURUSERNAME i use the “pi” user…correct? i use adduser pi audio and it’s just in audio group

Humm, well lets try again then,
user pi is likely already in your audio group on a raspberry pi os, so you can likely ignore that command,
but if it is not you can just do this command instead and restart. ```
sudo usermod -a -G audio pi
for trouble shooting you can try this command in a terminal

su - pi -c "/usr/bin/screen -d -m -S rhasspystuff rhasspy --profile en

then type

sudo screen -r

and it should reattach the screen so you can see the readouts from rhasspy

name this script rhasspystart.py put in in /home/pi/YOURFOLDER and set it to executable

sudo chmod +X /home/pi/YOURFOLDER/rhasspystart.py

install screen if it is not installed sudo apt-get install screen
now lets set up a cron job

sudo crontab -e

put this at the bottom of the contab file

@reboot screen -d -m -S startrhasspy python3 /home/pi/YOURFOLDER/rhasspystart.py

Here is that python script for your crontab again with the pi user set,

#!/usr/bin/python3
import time
import os
time.sleep(20) #sets a time delay so that systems can catch up as we run this script at startup via cron
#the below command runs screen as another user
startvoicestuff = ‘su - pi -c "/usr/bin/screen -d -m -S rhasspystuff rhasspy --profile en"’
os.system(startvoicestuff)
1 Like

i found my stupid error…i used copy-paste for the script and the double quotes "’ are broken, just rewrite it and it work!! thx man :+1:

Yep, I should have used the code feature of this board to start with. Good luck.

I solved the service problem by running Rhasspy inside tmux.
Here is my service file:

[Unit]
Description=rhasspy
After=pulseaudio.service

[Service]
Type=forking
WorkingDirectory=/home/pi/rhasspy
ExecStart=/bin/bash -c "/usr/bin/tmux new-session -c /home/pi/rhasspy -s pi -n rhasspy -d /home/pi/rhasspy/bin/rhasspy-voltron -p fr"
ExecStop=/bin/bash -c "/usr/bin/tmux send-keys -t rhasspy C-q"
User=pi

[Install]
WantedBy=multi-user.target