Raspberry Pi auto-start script

There are three ways to start a script or program on startup.

Env: Raspberry Pi 3, 4 (Debian 10 or Raspbian Buster)

Method 1 with rc.local

sudo nano /etc/rc.local

#!/bin/sh -e
# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.

exit 0

// Done

chmod +x /etc/rc.local

// Enable rc.local on startup
systemctl enable rc.local

Method 2 with systemd

sudo nano /etc/systemd/system/autostart.service

// Paste this into it
Description=Auto keepalive daemon
## make sure we only start the service after network is up

## use 'Type=forking' if the service backgrounds itself
## other values are Type=simple (default) and Type=oneshot
## here we can set custom environment variables
ExecStop=/usr/bin/killall -9 autostart
### NOTE: you can have multiple `ExecStop` lines
ExecStop=/usr/bin/killall autostart
# don't use 'nobody' if your script needs to access user files
# (if User is not set the service will run as root)

# Useful during debugging; remove it once the service is working


// END

// Make it autostart 
sudo systemctl enable autostart.service

Done and Reboot

Method 3 start after LXDE desktop is loaded

// Make an auto-start directory
mkdir /home/pi/.config/autostart

// Put your script in it
nano autoChrome.desktop

[Desktop Entry]
Name=Video auto play

Done and reboot 

If you got (code=exited, status=203/EXEC) error, you have to add #!/bin/sh at the very beginning in your .sh script.