A new featther to systemd

If it doesn't relate to Debian, but you still want to share it, please do it here

A new featther to systemd

Postby arzgi » 2020-04-30 14:49

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/documentation/linux/usage/rc-local.md

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

EDiT
And bonus, script again works as user.
arzgi
 
Posts: 635
Joined: 2008-02-21 17:03
Location: Finland

Re: A new featther to systemd

Postby pylkko » 2020-05-04 10:45

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
pylkko
 
Posts: 1738
Joined: 2014-11-06 19:02

Re: A new featther to systemd

Postby Head_on_a_Stick » 2020-05-04 11:54

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.
User avatar
Head_on_a_Stick
 
Posts: 12130
Joined: 2014-06-01 17:46
Location: /dev/chair


Return to Offtopic

Who is online

Users browsing this forum: No registered users and 8 guests

fashionable