Skip to main content
Topic solved
This topic has been marked as solved and requires no further attention.
Topic: Tool to automatically start dinit for each new logged in user (Read 7073 times) previous topic - next topic
0 Members and 4 Guests are viewing this topic.

Tool to automatically start dinit for each new logged in user

Good Afternoon,

I have developed a tool, dinit-user-spawn, https://github.com/initMayday/dinit-user-spawn, of which automatically starts a dinit process for each user that has logged in, allowing each user to have their own user services with ease. Recently, I released the first master (ie. stable) release, and hence I believe this build is fine for others to use (a few others have tested the development branch before its promotion to master/stable, but of course more testing from others would be appreciated). The way the program works is quite simple and comes in at around 500 lines of c++ code and hence should be readable by most who understand c++. How it precisely works is also explained in the README.

The master release is on the AUR, for those who wish to try: https://aur.archlinux.org/packages/dinit-user-spawn-master-git

If also possible, i think it would make a good addition to the wiki for the dinit installation. The main reason i created this over turnstile is that it is more adjacent in functionality to turnstile's original goal where it was initially known dinit-userservd, and before it expanded its scope to become a logind replacement, of which it has not yet accomplished. With the last update to it being 7 months ago and with only relatively minor commits in the months leading upto the last commit (considering that its goal has not yet been reached), I thought a project with more limited scope of which is much more easily achievable (which it has done) was warranted for purely spawning dinit as a user process for each user.

Thank you.

Re: Tool to automatically start dinit for each new logged in user

Reply #1
I was running turnstile (just to try it out as i run most of my services etc system wide) and it was OK, or at least seemed to be. However, saw this and thought i'd at least try it out, especially as it seems simpler (that's my assumption) than turnstiled. So, disabled all the turnstiled stuff, installed this and enabled and yeah, seems to be running and doing exactly what it was designed to do.... Nice one.

As soon as i find something that i can run as a user service i'll try it out properly. Many thanks and kudos to you for making it happen. Dinit is a such a great init system, i'm hoping that more people will see that and start using it.  :)

Re: Tool to automatically start dinit for each new logged in user

Reply #2
I will package this for the world repo.

Re: Tool to automatically start dinit for each new logged in user

Reply #3
@initMayday

Could you please make a git tag for the upcoming package?

Re: Tool to automatically start dinit for each new logged in user

Reply #4
Good evening,

Zendjinn: glad you have found the program useful, and yes it is much simpler than turnstile, as much more akin to turnstile's original goal and name of dinit-userservd, before it expanded to attempt to replace all of logind. The scope is much more limited to what it says on the tin.

artoo: Sure thing, I believe I have done so just now (https://github.com/initMayday/dinit-user-spawn/releases/tag/v1.0.0), however, let me know if anything further needs to be done. Just to note, the master branch is always stable (work is only done on the dev branch before eventual promotion to master)

Thank you.

Re: Tool to automatically start dinit for each new logged in user

Reply #5

artoo: Sure thing, I believe I have done so just now (https://github.com/initMayday/dinit-user-spawn/releases/tag/v1.0.0), however, let me know if anything further needs to be done. Just to note, the master branch is always stable (work is only done on the dev branch before eventual promotion to master)


It is more for packaging purposes/rules to pull a tag.
Your neat tool is precisely the kind of "trickery" dinit needed to match a current openrc. :)

https://gitea.artixlinux.org/packages/dinit-user-spawn

Maybe integrate the service install as meson option?
That is the only slight improvement I see from deployment side. 
Next I will test it.

Re: Tool to automatically start dinit for each new logged in user

Reply #6
I think it is better to have the service within the PKGBUILD, although that should probably be split off into a separate package called dinit-user-spawn-dinit, as nothing inherently ties this program to having dinit as the main init system. Technically it would work just fine to start dinit for each user no matter the root init system (i can't imagine people doing this though). Perhaps other distros may also have different preferred locations for the dinit service directory, so it is just a bit more modular incase other distros want to package it.

(Incase you haven't seen it, the PKGBUILD builder is found at: https://github.com/initMayday/dinit-user-spawn/blob/dev/packages/make-packages.sh, and uses https://github.com/initMayday/dinit-user-spawn/blob/dev/packages/template/PKGBUILD, may be useful for your own)

Re: Tool to automatically start dinit for each new logged in user

Reply #7
I integrated dinit-user-spawn via alpm hooks in current gremlins dinit packages.
Plesae test.
The dinit-user-spawn service is enabled on install by alpm hook.

Re: Tool to automatically start dinit for each new logged in user

Reply #8
1. It doesn't work with startx in .bash_profile
2. Why make such stuff as hard dependency?

UPD:
It actually works with auto startx but it takes 2 minutes to start the service.

Re: Tool to automatically start dinit for each new logged in user

Reply #9
1. It doesn't work with startx in .bash_profile
2. Why make such stuff as hard dependency?

UPD:
It actually works with auto startx but it takes 2 minutes to start the service.
I don't see why you'd even want to start this alongside X11 (or even within your shell) and not simply via a system service such as the one provided under Dinit. I have a good few user services myself at the moment that are independent of a display server (e.g. dbus, pipewire), and I personally always thought it'd be a better idea to start those immediately upon login. I could be wrong, though.

Re: Tool to automatically start dinit for each new logged in user

Reply #10
1. It doesn't work with startx in .bash_profile
2. Why make such stuff as hard dependency?

UPD:
It actually works with auto startx but it takes 2 minutes to start the service.
If you don't want the hook to be used you can create a symlink, with the same name, to /dev/null in /etc/pacman.d/hooks

Re: Tool to automatically start dinit for each new logged in user

Reply #11
I don't see why you'd even want to start this alongside X11 (or even within your shell) and not simply via a system service such as the one provided under Dinit. I have a good few user services myself at the moment that are independent of a display server (e.g. dbus, pipewire), and I personally always thought it'd be a better idea to start those immediately upon login. I could be wrong, though.

I do start it as system service (sudo dinitctl enable blahblahblah), but for whatever reason it has issues when .bash_profile contains startx.
https://wiki.archlinux.org/title/Xinit#Autostart_X_at_login

If you don't want the hook to be used you can create a symlink, with the same name, to /dev/null in /etc/pacman.d/hooks

No problems with hook, but the util itself isn't working properly, whick is a pity.

Re: Tool to automatically start dinit for each new logged in user

Reply #12
It is likely because of environment variables, when you start dinit as your user manually it inherits your env vars, including everything set at runtime. dinit-user-spawn is unable to do as such (since it doesn't inherit from your shell), and can only get env vars as far as su - yourusername -c "env" can give it, which is usually a subset (although if you know what the env var should be if you set it such that env logs it, it'll inherit from that, Note if anyone does have an idea of how to easily get the full set of env vars as from the shell, feel free to contribute such).

Beyond this for dinit services, you can provide your service an environment file (see docs: https://davmac.org/projects/dinit/man-pages-html/dinit-service.5.html#env), which seems to be the more official way of doing things.

Ultimately, the easiest way of gaining full control is to simply launch dinit from your bashrc or other equivalent.

If it is not env vars, then dinit-user-spawn quite literally only starts the dinit process for each user that logs in (and cleans it up), so if the dinit process itself is running, then it has completed its task.

Although, nothing should really have a hard dependency on dinit-user-spawn, as the manual method of launching it yourself offers you more control (and works perfectly fine), albeit at a bit less convenience.

Re: Tool to automatically start dinit for each new logged in user

Reply #13
It is likely because of environment variables, when you start dinit as your user manually it inherits your env vars, including everything set at runtime. dinit-user-spawn is unable to do as such (since it doesn't inherit from your shell), and can only get env vars as far as su - yourusername -c "env" can give it, which is usually a subset (although if you know what the env var should be if you set it such that env logs it, it'll inherit from that, Note if anyone does have an idea of how to easily get the full set of env vars as from the shell, feel free to contribute such).
Yes, this is it.
Ultimately, the easiest way of gaining full control is to simply launch dinit from your bashrc or other equivalent.
That's how I do it. I launch user instance of dinit from .bash_profile:
Code: [Select]
pgrep -u "$USER" -x "dinit -q" > /dev/null || { dinit -q & }
trap "dinitctl shutdown" EXIT
But I like the idea of dinit-user-spawn.  ;)

 

Re: Tool to automatically start dinit for each new logged in user

Reply #14
Yeah dinit-user-spawn seems a bit more "pure" but i think the ultimate solution is to just strip down the program (or even create a new bash script, which would be very minimal even compared to dinit-user-spawn) such that it autocreates your ~/dinit.d and such, and appends (with confirmation) to your bashrc or such the command to launch dinit.

This of course is slightly manual, but not to much of a great degree since the script automates it and just prompts you to accept, and of course you'd have to live with your bashrc or equivalent having a command to launch dinit, but this mitigates all issues associated with environment variables in a very understandable manner with no 'hacks', and I personally would see it as a successor to dinit-user-spawn as it is more powerful since you have direct control over the dinit launch (although it is less 'clean').

Ultimately davmac should ideally add proper user service support to dinit, although i don't see this happening as it is said to not suggest features unless you will add them on his github, indicating to me that the project is more in maintenance mode (especially with what i perceive as burnout in his older blogs). Hence I don't think it is for the best that dinit-user-spawn is made a hard dependency on other stuff, as it locks people out of the, what I perceive to be, superior bash launch method (which comes at the cost of a bit of convenience).