9 ms·
Systemd by Example (2021)
- smetj 3y agoThis doc format works best for me ... just enough to get you started and get results. Digging deeper can be done where required. More like this!
- MichaelMoser123 3y agoalso it is a whole series, there are the other parts as well! Great series, makes systemd understandable - and less fear inspiring. https://seb.jambor.dev/posts/systemd-by-example-part-2-dependencies/ https://seb.jambor.dev/posts/systemd-by-example-part-2-depen... https://seb.jambor.dev/posts/systemd-by-example-part-3-defining-services/ https://seb.jambor.dev/posts/systemd-by-example-part-3-defin... https://seb.jambor.dev/posts/systemd-by-example-part-4-installing-units/ https://seb.jambor.dev/posts/systemd-by-example-part-4-insta...
- dang 3y agoRelated: Systemd by Example - https://news.ycombinator.com/item?id=36817510 https://news.ycombinator.com/item?id=36817510 - July 2023 (11 comments) Systemd by Example - https://news.ycombinator.com/item?id=30071240 https://news.ycombinator.com/item?id=30071240 - Jan 2022 (69 comments) Systemd by Example – The Playground - https://news.ycombinator.com/item?id=30070159 https://news.ycombinator.com/item?id=30070159 - Jan 2022 (1 comment)
- kosolam 3y agoI like it
- hiAndrewQuinn 3y agoSystemd is a pretty neat little thing. It's what keeps me running Ubuntu and Debian servers instead of switching to Alpine, at least in those situations where I can't containerize what I want to do. The thing that got me into it was systemd timers. I really like being able to split up what should run from when should it run. `cron` works best if you desire simplicity above all else, and Slack used `cron` for a very long time before moving to something more custom. But I ultimately don't feel like the learning curve for systemd timers is that bad, and the benefits it can bring (like writing all your echo statements to journalctl instead of some random hard coded logfile in a script) feel very worth it to me.
- charcircuit 3y ago>`cron` works best if you desire simplicity above all else It may be simple, but it's config file is hard to comprehend compared to a systemd timer. Being able to just use "Friday 17:00" or "hourly" is so much more readable.
- hashworks 3y agoWhile I support systemd timers over cron, AFAIK cron has stuff like @hourly.
- caiusdurling 3y agoSome cron implementations do, it's not portable.
- bheadmaster 3y agoNeither are systemd timers. I don't think there's a single system out there implementing the systemd timer interface.
- dale_glass 3y agoWhat do you mean? There's a single implementation as far as I know, deployed on many distributions and working identically.
- bheadmaster 3y ago> There's a single implementation as far as I know That's exactly what I mean. Systemd itself, including timers, is deeply coupled with the Linux API, and cannot be (easily) ported on any other system. Cron, on the other hand, exists on almost every UNIX-like system.
- yau8edq12i 3y ago
- zokier 3y agoPersonally I find systemd man pages pretty great, they comprehensively explain pretty much every thing that you need to know. Sure, they are more of a reference than a tutorial and there is lot of material to read there, but still I'd recommend reading the relevant sections whenever you are working with systemd https://www.freedesktop.org/software/systemd/man/latest/systemd.html https://www.freedesktop.org/software/systemd/man/latest/syst...
- usrbinbash 3y ago> Sure, they are more of a reference than a tutorial Well, that's kinda the point of a `man`ual page.
- girvo 3y agoI was finally impressed with systemd when I recently had to port our single-process multi threaded TCP/UDP server (listening on a heap of ports) at work to a multiple binary/process, single threaded asynchronous IO system. PartOf= let us still have one top level “lithium” service to start and stop which starts and stops all of the other services, while being able to use journalctl to view them as one log file via a wildcard! Super nice, it’s been quite lovely.
- shdh 3y agoA lot of people still probably hate on systemd, but it and journalctl are pretty nice to me.
- sph 3y agoNot a lot of people, a very loud minority. They can go use Void Linux or other niche distros which replace it with the monstrosity that were SysV init scripts. It's the type of people that never had to write one of those scripts by hand, and maybe support two or three different distros. The UX of systemd tools (systemctl, journalctl) is a bit crap, to be honest, but systemd does what it needs to do well and it is an established component of a modern Linux system.
- deleted 3y ago[deleted]
- frankjr 3y ago> The UX of systemd tools (systemctl, journalctl) is a bit crap, to be honest Huh, what do you mean? I'm pretty happy with those.
- sph 3y agoI really dislike that systemctl subcommands do not respect the accepted standard of `command subcommand -h`. For example, try `git branch -h` or `systemctl start -h`. The latter won't give any useful information. The man page does not help either. `man git branch` opens the manual of the `git-branch` binary, so only the relevant options are shown. `man systemctl start` will show the man of the entire systemctl command, which is a bit unwieldy. `journalctl` is the same: it both does paging through the logs, but also manages rotating or vacuuming the logs. Why not have two commands?
- mixmastamyk 3y agoI just did `systemctl start -h` and got a ton of information. Is the problem it is too much?
- Emigre_ 3y agoThe blog post series author then did an online playground [1] that lets you create systemd examples and experiment with systemd in the browser. It's really interesting. [1] https://systemd-by-example.com/ https://systemd-by-example.com/
- andrewfromx 3y agofunny, to me systemd == no docker, no containers, just a VM. it's my goto way to keep my programming running and have it be restarted if the vm reboots. I use VMs like "pods". I deploy code directly to the VM and run it there along with other programs. I scale up and scale down with: https://www.pulumi.com/ https://www.pulumi.com/
- bruh2 3y agoIf I correctly understand your point, then it's worth noting the article is using a container merely to showcase the different parts of systemd in a sterile, reproducible environment. They're not running containers as systemd services, even though that's possible with podman Love Pulumi btw
- andrewfromx 3y agooh I guess I mean "most kids today" know nothing of running code outside docker. And don't ever need systemd. The "orchestration" of their pods is done by k8s. But I just don't get why. The extra complexity for what? Just make each ec2 instance VM a pod.
- znpy 3y agoBack in the day when LinuxAcademy was still cool, I asked for a systemd course... and they did it. Can't find the link right now, but that was what made systemd really click for me. Weird that still there is no apress/o'reilly/packt/manning introductory book about systemd.
- 1xdevnet 3y agoA casualty of acquisitions, I think. Linux Academy got bought by A Cloud Guru, who then got bought by Vista Equity along with Pluralsight. I think the material lives there now [0]. Packt does have "Linux Service Management Made Easy with systemd" as of Feb 2022, but I've not yet read it. [0] https://www.pluralsight.com/cloud-guru/courses/mastering-systemd https://www.pluralsight.com/cloud-guru/courses/mastering-sys... [1] https://www.packtpub.com/product/linux-service-management-made-easy-with-systemd/9781801811644 https://www.packtpub.com/product/linux-service-management-ma...
- andrewstuart 3y agoSystemd is one of the things that is really enhanced by ChatGPT. “Write me a service to start this program” Or “Write a socket activated service to…..” Or “Write a systemd timer that runs every ten minutes” Etc etc
- gradschool 3y agoI wish I could make friends with systemd like y'all. I spent at least a week wrestling unsuccessfully with systemd (admittedly starting from complete ignorance) to make a service that synchronizes a local directory on a laptop with a remote directory on a server after a docker container is stopped but before the filesystems and network stack are torn down during poweroff. It was easy enough to accomplish by manually invoking a script prior to powering off but no amount of cajoling, poring over documentation, or reading and adapting examples from forum posts on my part would get systemd to do it automatically without conflicts, race conditions, or timeouts. Is this not exactly the kind of problem systemd dependences are intended to solve?
- bmicraft 3y agoNaively, I'd expect `ExecStop=` to just work™. Is this not the case?
- PlutoIsAPlanet 3y agoDocker and systemd aren't exactly good friends, this is partially why Red Hat created Podman. Podmans integration with systemd is much greater, especially when you use quadlets (systemd controlled podman containers).
- traverseda 3y agoI am not having a good time with systemd on my embedded device. Somewhat complicated scenario, I need to change the mode of a wifi driver (which I do via modprobe), use iw to create a second interface for that wifi device, and finally use networkmanager to create a wifi hotspot based on the host name of the device. We set the hostname based on the mac address of wlan0. There are a lot of places this can go wrong, and you need a lot of deep knowledge of systemd to get it right. I start with three services, one to set the hostname, one to create the wlan0_ap device, and one to start up the wifi hotspot using nmcli. Alright, simple enough, this is the kind of thing systemd is good at, right? Well no, (and pardon me if my memory isn't perfect on this, it's tricky to debug weird race conditions) sometimes setting the hostname fails. Why? Well sometimes wlan0 doesn't exist, there's a udev rule that renames wlan0 during start up. Apparently I can add the systemd tag to that udev rules, and it will create a `.device` dependency I can Require. Alright, use both require and after keywords just to be sure. Good enough. Huh, onehsot services are listed as stopped even though they've run. Do some research, find out I need the `RemainAfterExit` keyword yet. Sure, dependencies are working. Now wlan0_ap device creation sometimes fails. Why? No really, why, this is hard to debug. Well looking around at dmesg it looks like the problem is that networkmanager is trying to do something with the device at the same time I am. Looks like it's enumerating device capabilities at the same time I'm trying to create a new device? Oh well, I'll just add the retry keyword to my service. Oh, wait, I can't add the retry keyword to one-shot services? Really? Internet tells me to change the service type to simple. Sure, we'll try that. Now that wlan0_ap device exists, let's start our access point. Also it's still sometimes failing on the hostname step still? The set-hostname command is asynchronous I think? I'll add a line to the start_access_point script that waits until the hostname isn't the default. Everything is looking good. Oh wait, it's sometimes failing intermittently. What the hell, why doesn't wlan0_ap exist? Service type `simple` considers a service to be started when the command first launches, not when it exit successfully. I've introduced another race condition. How can I make a service that works like a oneshot, but that you can retry? What, write a shell script and use systemd-notify to say it's complete? Long story short I ended up just writing a traditional shell-script based init script. Maybe I'm thinking about systemd wrong or something.
- dezgeg 3y ago
- doix 3y agoHa, systemd is basically my git. I'm always surprised by how many developers don't grok git despite understanding significantly more complex things. I keep thinking if they would just take a day or two, they would get it and then wouldn't complain about having to copy paste commands and "rm -rf && git clone" to fix their workspaces. And yet I do the _exact_ same thing with systemd. I don't get it, I don't like it, and every time I need to do _anything_, I'm googling, copy pasting commands into my terminal until something vaguely correct happens. The CLI options are indecipherable to me, like reading hieroglyphics. Deep down I understand that it solves some pretty complex things when it comes to system initialization, but something about the UX of using journalctl and systemctl is so bad (for me) that it creates a mental block that I cannot overcome. Luckily, nothing I do in my day job requires messing with systemd.
- sph 3y agoSounds like a you problem. You have identified a hole in your knowledge, you should address it. Systemd is not rocket science, and I would say it's more intuitive that git is anyway.
- sneak 3y agoIt’s not rocket science, but it is baroque. TFA ends with 30 lines of config to make it boot and do nothing, including some to disable a bunch of spooky action at a distance invisible default dependencies, which still ends up with a system with a bunch of other units that aren’t explained.
- js2 3y agoI know how you feel. I finally brewed myself a pot of coffee the other day and just followed the advice I always give everyone else-RTFM: https://www.freedesktop.org/software/systemd/man/latest/systemd.html https://www.freedesktop.org/software/systemd/man/latest/syst... It's pretty well documented, especially for Linux. Follow the links from that page at least one level deep. Part of the complexity is that it's tightly integrated into the same Linux concepts that enable containers. In fact, systemd-nspawn can manage containers on your behalf. But start with the concepts and unit files, then read the man pages for systemctl and journalctl. That'll get you most of the knowledge you need to interact with it on a day-to-day basis.
- braincat31415 3y agoFrom the personal experience, systemd works quite well when it works, but sometimes I ran into problems with it that were very hard for me to solve. I admit I never became a systemd expert, but I think I had a decent working knowledge of it. This was the final straw though: https://forums.debian.net/viewtopic.php?t=154562 https://forums.debian.net/viewtopic.php?t=154562 I am back to sysvinit and happy.
- wrs 3y agoI haven’t been in the weeds with systemd for a while, but this post was very helpful in understanding how systemd actually works, which didn’t match my (or, I would think, nearly anyone’s) intuition as a user of it. I don’t know if there’s any other full technical explanation of how units, jobs, transactions, etc. are actually handled. https://blog.darknedgy.net/technology/2020/05/02/0/index.html#tech-critique https://blog.darknedgy.net/technology/2020/05/02/0/index.htm... >systemd’s developers and almost all public documentation revolve around a “unit-centric” definition of systemd (except when discussing bugs), but my position is that for systemd-the-service-manager the most important construct is not the unit but the job, and hence one ought to understand systemd in a “job-centric” way.
- js2 3y ago> Now we need to tell systemd to execute halt.service when it reaches halt.target. The halt service, along with poweroff, reboot, and kexec get special treatment: https://www.freedesktop.org/software/systemd/man/latest/systemd-halt.service.html https://www.freedesktop.org/software/systemd/man/latest/syst...
- CyberEldrich 3y ago“Systemd .. reminds me of every overly convoluted script a junior coder has ever written” https://www.reddit.com/r/linux/comments/bsunzw/systemd_vs_init_scripts_an_essay/ https://www.reddit.com/r/linux/comments/bsunzw/systemd_vs_in...
- SuperNinKenDo 3y agoTook me a while to read through so I could come back and comment. I've got to say, this is probably the best single explainer of the basics of systemd I've read. I've only recently started fiddling with systemd extensively since I had my Linux-coming-of-age prior to its widespread adoption. I've got to be honest. I've found the experience very confusing and disorientating. The man pages feel really terse, even by manpage standards, and all the information is heavily split up so it's quite difficult to build a mental model of the full system IMO. Somethint like this would have been magic before, but it was still really helpful to me now with the way it explained things, I feel like it took me most of the way from cargo culting, into more understanding. Great write-up!