Skip to main content
Topic: How to run services as a user? (Read 1440 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

How to run services as a user?

I'd like to run a service as a normal user but I am not entirely sure how, just running dinitctl as not root will just make it fail with:
Code: [Select]
dinit-client: connecting to socket /run/user/1000/dinitctl: No such file or directory
is it even possible?

Re: How to run services as a user?

Reply #1
Yes it is possible: https://github.com/Xynonners/dinit-userservd

Just follow the guide there, although I put "session optional pam_dinit_userservd.so" at the bottom of /etc/pam.d/system-login as per this reddit post: https://www.reddit.com/r/artixlinux/comments/wro58v/run_pipewire_as_a_dinit_service/

Works good, I use his pipewire services and made a little one for jackett.  No issues so far.

 

Re: How to run services as a user?

Reply #2
Yes it is possible: https://github.com/Xynonners/dinit-userservd

Just follow the guide there, although I put "session optional pam_dinit_userservd.so" at the bottom of /etc/pam.d/system-login as per this reddit post: https://www.reddit.com/r/artixlinux/comments/wro58v/run_pipewire_as_a_dinit_service/

Works good, I use his pipewire services and made a little one for jackett.  No issues so far.
Yup I also want to run pipewire that way.

However I already have dbus running as root from the normal configuration file, should I just disable dbus as root and just run it as a user? Or do I need to run both at the same time?

Re: How to run services as a user?

Reply #3
Or do I need to run both at the same time?
You need both.
Quote
Linux desktop environments take advantage of the D-Bus facilities by instantiating multiple buses, notably:
    a single system bus, available to all users and processes of the system, that provides access to system services (i.e. services provided by the operating system and also by any system daemons)
    a session bus for each user login session, that provides desktop services to user applications in the same desktop session, and allows the integration of the desktop session as a whole
https://en.wikipedia.org/wiki/D-Bus


Re: How to run services as a user?

Reply #5
If you do not opt for the userservd configuration, then you can do it by creating a user ran instance of dinit,

Code: [Select]
type = process
command = dinit -e <your-env-vars-dir>
smooth-recovery = true
logfile = /var/log/dinit/user-suite.log
waits-for = elogind
waits-for = tmpfs
run-as = <user>

Add this service to your dinit service files and enable it. Your user services may then be placed in ".config/dinit.d" (or wherever you want it to point to). Create a "boot.d" sub-directory and soft-link the services in the first directory to the boot.d directory for user service to start at boot.

Open to any suggestions to improve this.

Re: How to run services as a user?

Reply #6
If you do not opt for the userservd configuration, then you can do it by creating a user ran instance of dinit,

Code: [Select]
type = process
command = dinit -e <your-env-vars-dir>
smooth-recovery = true
logfile = /var/log/dinit/user-suite.log
waits-for = elogind
waits-for = tmpfs
run-as = <user>

Add this service to your dinit service files and enable it. Your user services may then be placed in ".config/dinit.d" (or wherever you want it to point to). Create a "boot.d" sub-directory and soft-link the services in the first directory to the boot.d directory for user service to start at boot.

Open to any suggestions to improve this.
Sorry to necro this after about two months, but are you still using this approach yourself? I tried to make use of it for my own scripts but it doesn't seem to work in this given set-up due to XDG_RUNTIME_DIR not yet being present.

Re: How to run services as a user?

Reply #7
My apologies for the delay. If you have elogind enabled, then XDG_RUNTIME_DIR should be present for your own services. Currently, I am not using this approach (due to a reinstall recently). I see that you have taken a look at the tutorial for user services under dinit (reference for other users). That tutorial along with the script that I posted should work (it did when I tested it with pipewire/wireplumber).

Re: How to run services as a user?

Reply #8
If you have elogind enabled, then XDG_RUNTIME_DIR should be present for your own services.

The XDG_RUNTIME_DIR directory is only created when you log in. If you have a user instance of dinit spawned directly from the system instance, it will run before you have logged in, and the directory won't exist. This will likely cause issues and I advise against this approach for that reason. It's probably better just to run dinit (the user instance) from your login script. Even better still, use dinit-userservd/turnstile.