r/systemd • u/thekingofdorks • Apr 10 '26
Can I order the users during init?
I have a setup where multiple users run a single service using Podman and systemd. For example, one user called "mysql" runs the mysqld in an container. Another user called "gitea" runs the gitea service in a podman container. They talk to each other using Unix sockets.
The problem is, I need to ensure mysql is up and running before gitea. Since they run under different users, user level and system level targets (basic.target, default.target) are no good. And I can't use socket activation via .socket files because some services like gitea doesn't support them. I was thinking of making a bunch of helper services that dip in and out of user and system service spaces, like how podman-user-wait-network-online.service works. That feels hacky.
Is there a way I can "order" how systemd starts user instances? For example, have systemd complete starting up the mysql user and its services before starting up the gitea user?
1
u/_mick_s Apr 10 '26 edited Apr 10 '26
[edit] ok, so i answered too fast. this isn't actually correct if you want to run in containers if so you'll want to read up on container security, rootless, etc.
[original]
Don't use user services, just use normal ones but specify which user the process should run as.Then you can use normal Requires directive.4
u/sogun123 Apr 10 '26
It is not important which user is used to run the services as long as they are started by same systemd instance. Look into
man systemd.unit, there are many directives for ordering units like Wants, Requires, After1
u/schultzter Apr 10 '26
Not sure how it works between different users but have you looked at before= and after= in system service units?
0
u/ghenriks Apr 10 '26
This seems to sat there is an after keyword that sounds like what you need
https://www.redhat.com/en/blog/podman-run-pods-systemd-services#:~:text=BindsTo=pod%2Dmy%2Dpod,5%20minutes%20ago%20container%2Da
0
u/tesfabpel Apr 10 '26
systemd manages services dependencies just fine.
also, for each service, you can specify which user to run the service as.
so, you don't order the users, you order the services...
0
u/mpdscb Apr 10 '26
If worse comes to worst, you can put a sleep into the startup script for gitea to give mysql time to come up.