Raspberry Pi Zero 2W Guide: Running the Project on Startup
By Omar Hamoudeh 4/14/25
This guide goes into detail on how to create a system service that will automatically run the project on startup. It is achieved by creating a system service.
Step 1: Create the Service File
-
Open a Text Editor with Root Privileges:
zsh sudo nano /etc/systemd/system/runproject.service
-
Enter the Following Content: ```ini # This service runs the runproject at boot using the Python interpreter from the virtual environment. [Unit] Description=Run runproject at boot After=network.target
[Service] User=kali Type=simple ExecStart=/home/kali/Desktop/myvenv/bin/python3 /home/kali/Desktop/ECECapstoneProject/rover_code/main.py StandardOutput=inherit StandardError=inherit Restart=on-failure
[Install] WantedBy=multi-user.target ```
Step 2: Enable and Start the Service
-
Reload systemd to pick up the new service:
zsh sudo systemctl daemon-reload
-
Enable the service to start at boot:
zsh sudo systemctl enable runproject.service
Step 3: Stop the Service on Login
To avoid having the service running in the background while you are logged in, add a command to stop it in your login shell configuration.
-
Open your login configuration file:
zsh nano ~/.zprofile
(If you’re using Bash, consider editing~/.bash_profile
or~/.profile
.) -
Add the following lines at the end of the file:
zsh sudo systemctl stop runproject.service
-
Save and close the file.
-
Troubleshooting:
Always verify service status withsudo systemctl status runproject.service
to help debug any issues.