A new featther to systemd

If it doesn't relate to Debian, but you still want to share it, please do it here
Post Reply
Posts: 800
Joined: 2008-02-21 17:03
Location: Finland
Been thanked: 4 times

A new featther to systemd

#1 Post by arzgi »

I have a Raspberry Pi as a headless server for home automation tasks. It's on 24//7, only disconnect power when change connections. 'Semi-proto', most wires are soldered, but still invent something new almost every week :D

Had difficulties to get the python script, which is the core of my system, running after boot, Tried .profile, did fail more than half of boots. rc.local, which Rasbian still supports, a little better, altough run the scrpit as root, worked about 60-70% of boots. Had still ssh from Debian to Pi and start the script manually. So went to rasbperrypi.org to search more info. They recommended systemd: https://www.raspberrypi.org/documentati ... c-local.md

So wrote my first systmed-unit file, and after that script has started at every boot!

And bonus, script again works as user.

User avatar
Posts: 1801
Joined: 2014-11-06 19:02

Re: A new featther to systemd

#2 Post by pylkko »

Yeah, common sense that has been posted multiple times here and also on other forums. In my opinion there is room to argue that you should almost never put anything into rc.local. I have maybe once had to do it. You have to make sure evey command in it runs, because you can block the entire boot if you hang something. I have seen a post where someone had a blank line in the beginning of the file which caused their boot to fail. Things put in there will also be run sequentially, as far as I know, and not simultaneously. It also runs everything as root and you have no control over when and how it runs your stuff, it just runs. Nasty...

So my rule of thumb is that if I need something to autostart and it is a graphical application, then use the desktops autolaunch setting or make a .desktop file and put it into autostart. Many such files are already given to you wen you install some package in places like /usr/share/applications/ a number of .desktop files already exists and you can move them into the autostart folder

if it is a service or script, then I make a systemd service that launches it. But here also, remember that many programs already come with .service files, and you can just activate them instead of writing from scratch (Although that is not hard at all, either)

Many things that are configured in the starting of the OS are also configured in .conf files and it is much more cleaner and easier to use these that force settings with commands in rc.local. Always first check if there is already a flag in a conf file that will do what you are trying to do.

you will also likely eventually forget that there are commands in rc.local and this might confuse you later when you try to debug stuff. Because there are multiple shells and decades of bifurcating shell dialects, .profile and .bash_profile are less cross platform in any case.

many people have issues with systemd. for example, that it is slowly taking over all of the operations of the OS and whatnot. Valid arguments in my opinion, However, if you are already running it, you should also then use it as it allows for much finer control over launching services than rc.local, the multiple versions of cron and anacron that exit or anything else. You can for example launch a program every fourth day of the month if it is a wednsday or only after some other script has run etc.

User avatar
Posts: 13450
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: A new featther to systemd

#3 Post by Head_on_a_Stick »

arzgi wrote:wrote my first systmed-unit file
Yeah, systemd has it's problems to be sure but it's great that functional unit files can be written without having to be an expert in shell scripting.
Black Lives Matter

Debian buster-backports ISO image: for new hardware support

Post Reply