by klodolph · 5y ago · 0 comments
> Note, we did get a little more complicated and create a SystemD script to launch it at startup.
There's a good chance that most of what you want is in Systemd.
Restart a process if it fails health checks? Systemd. Do you want to isolate a process in a container? Systemd. Open privileged sockets? Systemd. You can do a lot with Systemd.
That said there is a problem when you want to run things on multiple machines. What then? Unix and systemd were not designed as an OS for machine clusters, even though it won't be hard to imagine the concepts to be stretched even to this realm.
The docker/kubernetes crowd has been targeting the multi-machine OS scene much sooner and better, even though the solution of let's pack all dependencies, the entire machine and then some to a fat package and then have it run by a scheduler complex as f seems not like the ultimate future of the space.
I took a look at Nomad as a replacement for Kubernetes, which is much much simpler and you can get up and running with a single binary within 2 hours using this tutorial [0]. Nomad supports not only docker as a backend, but you can run raw_exec backend as well - that is any binary, such as shell script, that you wish to run without packaging the entire world with it. Now imagine if only you could schedule to run systemd units using Nomad. You'd scale from a single machine OS to cluster OS just like that.
I predict that Kubernetes will NOT be the ultimate answer as many are hoping for, betting their careers on it. It is too complex and not supporting other than docker runtimes makes it much inferior product than Nomad. Simple solutions usually win ultimately, so Nomad or systemd extended for multi machine services or even just vanilla linux process management extended to cluster level seem like much saner approaches.
[0] https://medium.com/hashicorp-engineering/hashicorp-nomad-fro...
With some tweaks to your unit files this is actually possible. Nomad has the concept of custom task drivers you can implement to make it schedule any kind of workload you like. I am maintaining a task driver which allows you to run systemd-nspawn containers with Nomad [1].
Using this task driver you can deploy your systemd units running inside a systemd-nspawn container into a Nomad cluster. If this sounds interesting to you I have written a how-to blog-post about this [2]
[1]: https://github.com/JanMa/nomad-driver-nspawn
[2]: https://janma.tk/2021-01-10/nomad-deploy-systemd-units/
Think I just saw from your article that Nomad supports straight up Java binaries but don't know how flexible that is
[0] https://github.com/coreos/fleet#fleet---a-distributed-init-s...
I find it ironic half of k8s mojo, etcd, came out of this project as well.
Btw i wrote an article about how great, easy and feature rich Nomad is which might interest you - https://atodorov.me/2021/02/27/why-you-should-take-a-look-at...
(Two things really help here, we have Windows/macOS/Linux devs all developing and running the code locally so they’re pretty good at not accidentally becoming dependant on stuff outside the JVM, and the healthcheck endpoint the load balancers use is very comprehensive and over the years has been updated to include every non-detected failure or performance degradation.)
Get something running in any environment really quickly because it is already a separate environment
Nobody has to deal with package managers messing up their system, or have to deal with package manager managers that lets them switch between different versions of a package manager just so they can run some obscure dependency before getting to the project
The point of this post is to not complicate things, but what I hear is even more complicated be it via a docker alternative.
It's not needed, but that's why a lot of older apps have their very custom solution to deal with that issue. (For example MySQL) Each with their custom exit condition handling, cleanup, backoff, etc. A simple loop also won't cleanup processes forked from the main server.
This 1kLoC script https://github.com/mysql/mysql-server/blob/8.0/scripts/mysql... can be almost entirely replaced with a few lines of systemd.service config. (with fairly logical names for each setting)
Now we can replace those with "Restart=always". If you want to be fancy, you could even add a watchdog.
> Process isolation to run a go binary on a presumably dedicated web server?
1. "presumably" 2. Apparently a web server which gets SSH sessions from devs - nice place to check for forwarded keys or collect passwords.
> Privileged sockets, not even sure what those might be.
Ports below 1024 (or whatever your local threshold is)
> but what I hear is even more complicated
It really isn't. Just unfamiliar to you.
I Google systemD the first result has 160 sections just in the documentation table of contents alone [0].
For day to day usage there are two man pages which should be enough for reference: https://www.freedesktop.org/software/systemd/man/systemd.exe... and https://www.freedesktop.org/software/systemd/man/systemd.ser...
Or you could start with one of the blog posts linked in the page you referenced.
You need a systemd unit file that starts your daemon properly when the server boots anyways (most common distros use systemd for init), and it's only a few more lines to make sure it gets restarted if it dies.
I agree overall, but apparently systemd supports musl. No clue why or who uses it, but it's a thing.