Automatically starting a program on Raspberry Pi OS
-
I’ve got a Raspberry Pi running (what I think is) the latest version of the OS, and I can’t get the damned thing to auto-start a program after booting.
I need it to run a web browser, kiosk-style, for which I (with some help from the Internets) wrote a little bash script to set up some stuff and start the browser. This script works fine when run from the terminal.
The script does not in any way want to run automatically on startup, though. According to various web sites I found, the normal ways to do that would be either by calling it from
rc.local
, or to make a.service
file and register that with the OS so it will run on booting.The script doesn’t appear to run at all when I include it in
rc.local
(yes, I made sure to include the complete path to it). When trying it via the service, the browser also doesn’t start, butsystemctl
does report it as “loaded, inactive (dead)” whatever the hell that may mean …Anybody have any ideas on how I go about making this work?
(Worst of all: it did work for a couple of years, but something went wrong with the thing, probably the SD card that got corrupted, and I have no fucking clue how I set it up originally.)
-
@Gurth Does it require some automagically logged in user, and then run the program at login?
-
@Gurth This is what I did:
-
I haven't done anything with a pi in a while but it was usually
@reboot /path/to/script.sh
In crontab.
-
@Gurth said in Automatically starting a program on Raspberry Pi OS:
The script doesn’t appear to run at all when I include it in rc.local
It's expecting your rc file, not your script. You need to write a SysV init script with w/e handlers you need. I had to do this one time to get the company Spyware to run on the company-issued Linux laptop.
-
@BernieTheBernie said in Automatically starting a program on Raspberry Pi OS:
@Gurth Does it require some automagically logged in user, and then run the program at login?
That’s what I’m trying to achieve. The single user on the computer logs in automatically, that’s no problem. But how to run anything automatically after that login, is eluding me.
@Rhywden said in Automatically starting a program on Raspberry Pi OS:
@Gurth This is what I did:
That’s the same instructions I also found and followed, minus the auto-cycling between different tabs stuff because I don’t need that. The part about Setting up the Raspberry Pi Kiosk to start at boot doesn’t work for me, though. I also tried a similar explanation on another page I found that set up the service a bit differently, with the same result: nothing.
@DogsB said in Automatically starting a program on Raspberry Pi OS:
I haven't done anything with a pi in a while but it was usually
@reboot /path/to/script.sh
In crontab.
That might work, but TBH I would prefer not to do it that way.
@Gribnit said in Automatically starting a program on Raspberry Pi OS:
It's expecting your rc file, not your script. You need to write a SysV init script with w/e handlers you need. I had to do this one time to get the company Spyware to run on the company-issued Linux laptop.
Thanks for reminding me why I prefer macOS over Linux ;)
-
@Gurth
.service
files, if properly registered with systemd, should work, but are not for GUI stuff. I suppose the guide linked by @Rhywden works, but it feels like a hack: you shouldn't be setting DISPLAY yourself, you should be starting it from the session init.Instead you should create a
.desktop
entry in/home/pi/.config/autostart
. That is run by the X session when it is starting, so it will run with the proper DISPLAY and X authority set up.Or, if you want to restrict other functions of the session, need to modify the configuration of the X session. Which means diving into the LightDM documentation.
-
@Bulb That sounds like it might be the solution I’m after … will need to test it later today.
-
And indeed, @Bulb’s suggested method works fine and immediately. All I had to do was a quick search to find out what to put into that
.desktop
file, and done.It would be so nice if they had given a GUI way of accomplishing this, though. That would have saved me two part-afternoons of fucking around with stuff that doesn’t actually work …
-
@Gurth It is the standard XDG autostart, inspired by the similar mechanism in Windows, which I couldn't find a BFU-friendly way to add applications to either. I mean, I did want to set my Windows up so that some applications (like Outlook, browser, rancher-desktop or taskplay) start automatically after login and … for applications that don't have their own option I didn't find any gui, just opening the autostart folder inside the menu and create
.lnk
s there. And.desktop
files are basically XDG equivalent of.lnk
s.Full KDE has a settings dialog for it, and full LXDE might as well (I don't use it), but the Raspbian is rather restricted to save space.
-
My main complaint about this method is that it’s such a Linuxy way of doing things: a folder inside a hidden folder in which you must place what amounts to an
INI
file to configure what must be launched when the user logs in. Very discoverable.The difference with Windows is not that the
.desktop
files are the equivalent of.lnk
s, it’s that on Windows, you just chuck a (shortcut to a) program in the right folder, that is non-hidden and exists by default, and it’ll work. On Linux, this was obviously considered too simple …
-
@Gurth The directory on Windows is … deep in a very unobvious place and … I thought it (AppData) actually is hidden, or was in some version. Even if it's not hidden, there are no obvious routes into the userprofile directory from explorer, so effectively it is hidden.
In Linux it is at least easy to remember. And in proper desktops it does get created automatically like on Windows. The PI is way too much cut down.
-
@Bulb said in Automatically starting a program on Raspberry Pi OS:
I thought it (AppData) actually is hidden, or was in some version.
AFAIK, always has been; still is.
-
@Bulb said in Automatically starting a program on Raspberry Pi OS:
@Gurth The directory on Windows is … deep in a very unobvious place and … I thought it (AppData) actually is hidden, or was in some version. Even if it's not hidden, there are no obvious routes into the userprofile directory from explorer, so effectively it is hidden.
Pre-Windows 8 you could right-click the Startup folder under Programs in your Start Menu and open it from there (either All Users or just your User).
In Windows 8+ Microsoft tells you to use the Run box to go to "shell:startup" to get to your User's Startup folder.
Either way, you then put a shortcut there.
Also pre-Windows 8, if the program you wanted to run was already in the Start Menu, you could drag its Start Menu item there in the menus instead of going to Explorer.
-
@Parody said in Automatically starting a program on Raspberry Pi OS:
Pre-Windows 8
Things were more usable in many cases.
-
@Bulb said in Automatically starting a program on Raspberry Pi OS:
@Gurth The directory on Windows is … deep in a very unobvious place
It is? That must have changed since XP or so, then. Around then, there used to be a folder in the Start menu that you just chucked the stuff into that you wanted to launch on logging in, and done.
Edit: I thought I’d check, to make sure my memory isn’t as bad as I’ve been suspecting it’s getting, but VirtualBox refuses to start the one XP VM I’ve got with some vague error. So I CBA for the moment.
-
@Gurth It didn't change since XP, but in XP you could actually right-click the menu folder and ask it to be opened in explorer. Which, as mentioned by @Parody, stopped working in Windows 8 (in large part because the start menu no longer looks like a hierarchical menu).
-
@Gurth FWIW:
-
@HardwareGeek said in Automatically starting a program on Raspberry Pi OS:
@Bulb said in Automatically starting a program on Raspberry Pi OS:
I thought it (AppData) actually is hidden, or was in some version.
AFAIK, always has been; still is.
But the nice thing is if you type
%APPDATA%
(or LOCALAPPDATA) in the address bar of Explorer, it will expand env variables.
-
@Bulb said in Automatically starting a program on Raspberry Pi OS:
@Gurth It didn't change since XP, but in XP you could actually right-click the menu folder and ask it to be opened in explorer. Which, as mentioned by @Parody, stopped working in Windows 8 (in large part because the start menu no longer looks like a hierarchical menu).
But in Win10, you can expand that folder from Start, rclick an icon, click the "..." and "Open file location"
-
@dcon said in Automatically starting a program on Raspberry Pi OS:
@Bulb said in Automatically starting a program on Raspberry Pi OS:
@Gurth It didn't change since XP, but in XP you could actually right-click the menu folder and ask it to be opened in explorer. Which, as mentioned by @Parody, stopped working in Windows 8 (in large part because the start menu no longer looks like a hierarchical menu).
But in Win10, you can expand that folder from Start, rclick an icon, click the "..." and "Open file location"
Yes, you can get there that way (as long as you pick a non-Store app) but it's not direct to the Startup folder.
-
@Parody said in Automatically starting a program on Raspberry Pi OS:
@dcon said in Automatically starting a program on Raspberry Pi OS:
@Bulb said in Automatically starting a program on Raspberry Pi OS:
@Gurth It didn't change since XP, but in XP you could actually right-click the menu folder and ask it to be opened in explorer. Which, as mentioned by @Parody, stopped working in Windows 8 (in large part because the start menu no longer looks like a hierarchical menu).
But in Win10, you can expand that folder from Start, rclick an icon, click the "..." and "Open file location"
Yes, you can get there that way (as long as you pick a non-Store app) but it's not direct to the Startup folder.
True, but at least it gets you closer than trying to dredge that path out of your (ok, mine) ed mind.
-
@dcon At some point, the Basic Fred User has to
GoogleBing how to make application start automatically after login. All those procedures are well beyond that point.
-
@Bulb There's Task Manager's Startup tab where Disable option exists. Obviously it would be too useful to have Add and Remove there...
-
@Applied-Mediocrity said in Automatically starting a program on Raspberry Pi OS:
@Bulb There's Task Manager's Startup tab where Disable option exists. Obviously it would be too useful to have Add and Remove there...
That hasn't been updated to the new style. Can't be adding new features to obsolete programs!
-
@Parody said in Automatically starting a program on Raspberry Pi OS:
@Gurth FWIW:
The last good windows OS. Have an up boat for making me smile on a monday.
-
@dcon said in Automatically starting a program on Raspberry Pi OS:
@Applied-Mediocrity said in Automatically starting a program on Raspberry Pi OS:
@Bulb There's Task Manager's Startup tab where Disable option exists. Obviously it would be too useful to have Add and Remove there...
That hasn't been updated to the new style.
Ugly?
-
@DogsB said in Automatically starting a program on Raspberry Pi OS:
The last good windows OS.
I still remember when that OS was booed and hated as the Playmobil OS...