From Sparkfun website:
The three methods covered in this tutorial are:
rc.local - Likely the easiest and simplest way to get your program to run on boot. The downside is that tasks started with rc.local happen before the X windows system starts, which means you will not have access to graphical user interface (GUI) elements.
autostart - Used to automatically run your programs once LXDE (graphical desktop environment used by Raspbian) starts. It's slightly more complicated than rc.local, but it lets you run programs that require graphical elements.
systemd - The new and popular way to automatically start programs in Linux. It is definitely the most complicated of the three, but it allows you to run before LXDE starts, wait until you have access to other processes (e.g. networking, graphical desktop), or simply restart your program over and over again until it works. As such, it is a robust way to create and manage services that run in the background.
With systemd (example for running chromium at start-up)
Note: on Sparkfun /lib folder is specified but USE /etc system folder is best choice...
~$ sudo nano /etc/systemd/system/chromium.service
[Unit]
Description=Start Chromium
After=graphical.target
Wants=graphical.target
[Service]
User=pi
Group=pi
ExecStart=/bin/bash -c "export DISPLAY=:0; export XAUTHORITY=/home/pi/.Xauthority; chromium-browser"
[Install]
WantedBy=graphical.target
Configuration:
~$ sudo systemctl daemon-reload
~$ sudo systemctl enable chromium.service
# Now you can test your service (chromium must start)
~$ sudo systemctl start chromium.service
# or for testing at startup
~$ sudo reboot
# Verify the service
~$ sudo systemctl status chromium.service
# for prevent the browser to reopen his processus when you click on the window close button, use:
~$ sudo systemctl stop chromium.service
After=graphical.target
in the[Unit]
section. Then there is no need to restart the browser because it is started to early. These attempts are a waste of resources just on startup. – Ingo May 25 '19 at 17:14Type=oneshot
. That's only for programs that run just once a short time. Chromium runs all the time and as I see you want to stop it with systemctl. – Ingo May 25 '19 at 18:41After=graphical.target
dependency it will definitely start once after the GUI is present. – Ingo May 25 '19 at 18:49After=graphical.target
in unit, but now this doesn't work, chromium is not started on my system. – Ephemeral May 25 '19 at 18:49