How start a program on boot with a pygame interface ?

May 29, 2024, 19:59

lenonante

Hey 🙂 I want to start a program when the Raspberry boot. I add this lines in the .bashrc file :
cd /home/pi/Documents
python3 main.py
the program start when the RPI boot but without his pygame interface. When i launch a terminal, the porgram start WITH his pygame interface. (And of course, if i execute the program manually everything is ok) Thanks for helping me !

xkevinfpx

<@429355183311683584> did you get it work?

lenonante

No… i tried with a .sh script but sale problem

xkevinfpx

you could try it with a systemd service

xkevinfpx

wich starts the .sh script

lenonante

I tried to exécute the python script. So the same command that I put in the .bashrc

lenonante

I think I already tried, but I didn’t understood everything so i will retry

xkevinfpx

Just create a service file:
sudo nano /lib/systemd/system/MyService.service

xkevinfpx

Content of this file:
[Unit]
Description=HighTech Service
After=network.target

[Service]
User=pi
ExecStart=PATH_TO_YOUR_.SH_SCRIPT #(/bin/bash /home/pi/START_SCRIPT.sh)

[Install]
WantedBy=multi-user.target

xkevinfpx

sudo systemctl enable MyService.service

lenonante

Ok thanks ! I'will try this today. But i have some questions... 1. The .sh script is the one that i already did ? (with pyhon3 main.py) 2. If i modify the main.py file, will the modifications be available ? (Or the service file will execute the script as it was when i created the service file ?)

xkevinfpx

1. yes

xkevinfpx

2. if you restart your raspberry or you restart the service via
sudo systemctl restart Myservice.service
it will execute the new script

lenonante

Ok thanks, i will try this this afternoon