So here is how it works!
First, in the Linux spirit, your question is incomplete
. Bear in mind Linux has always been made for servers and is multi-users
by default, unlike another more widespread proprietary O.S.
So the question is, do you want to "autostart" something for:
- the whole machine (commonly called "a service")
- only for the current user in session
For the former, ie starting a service, you would add a service to systemd or something in rc.local.
Your service will be started as root, because you are in a phase where there is not yet any user logged in, and the service would be accessible to whatever user logs in the machine later.
Also, remember that at this point you might NOT have a graphical environment, so no graphical program should be put here.
A typical use case would be starting a web proxy (like Squid) that all users would use for their browsing sessions.
For the later, you want the session to be started, and you want the program to be launched with the user account, and not with root, otherwise there is a misunderstanding of basic security!
So here, you use the LXDE autostart described above.
Programs here are launched with the account on the user, and within the desktop environment that is started. So a graphical program is suitable here.
But there is a nasty trick!
If you read carefully the documentation, it says that if there is a user's local autostart, this one is executed instead of the "global" one.
This means that you cannot just create an autostart and put your command in it, because then only your command would run and not what was in the "global" autostart that is responsible for showing your desktop.
As a result you would end up with a black screen with a mouse pointer and you program running.
So the correct way to do things is:
First, copy the "global" autostart to your config directory
Code: Select all
cp /etc/xdg/lxsession/LXDE-pi/autostart ~/.config/lxsession/LXDE-pi
Then add your command after the standard ones, which in my example reads like that:
Code: Select all
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
That way, you still have your desktop showing, plus "my_program" will run once.
Note on Kodi
If the program you want to run is kodi, know that kodi has 2 modes.
The standard mode of Kodi (aka "standalone") is that it does NOT need a DE (Desktop Environment), but only a basic graphic stack (I don't know exactly but things like Mesa/X11).
The other mode is known as "full screen" and is made to run on top of a graphical environement, like Openbox/LXDE in the case of classic Raspbian.
So if you intended to run Kodi "standalone" you are very mistaken using Raspbian, because the DE in this case is useless and a nuisance to Kodi. If this is your intention, you'd better use something like LibreElec which is exactly that: minimal stuff to run Kodi.
So if you intend to run Kodi on Raspbian, and want it autostart, the right command is
That will run Kodi "full-screen" on top of LXDE. Should you decide that you want to exit Kodi and do usual desktop stuff, you just need to click on "exit" and you are back to LXDE... which does not work on "standalone" mode!