Skip to content

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

  1. Open a Text Editor with Root Privileges: zsh sudo nano /etc/systemd/system/runproject.service

  2. 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

  1. Reload systemd to pick up the new service: zsh sudo systemctl daemon-reload

  2. 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.

  1. Open your login configuration file: zsh nano ~/.zprofile (If you’re using Bash, consider editing ~/.bash_profile or ~/.profile.)

  2. Add the following lines at the end of the file: zsh sudo systemctl stop runproject.service

  3. Save and close the file.

  4. Troubleshooting:
    Always verify service status with sudo systemctl status runproject.service to help debug any issues.