Does anyone actually use systemd user services to start apps on user login?
I've been trying to set up some user services, but going mad trying to get things to work. The problem seems to be with graphical applications. I've tried some custom services as well as some of the services that come installed with applications like redshift but none of them actually start automatically, but will do fine if I start them manually after logging in.
I understand a lot of people probably just use ~/.xprofile etc, but I like the idea of having systemd manage the lifecycle of these startup apps.
Has anyone actually managed to get systemd user modules to start graphical applications on user login?
P.S. I'm using lightdm, I've heard it has some problems with pam and systemd, doesn't seem to be the problem in this case though.
About this post
- Posted
- Archived
- Score
- 56 · 100% up
- Kind
- Text
- ID
- boglso
37 comments
User services, yes. But not GUI applications.
systemd is not a right tool for graphical applications. Use desktop entries + xdg autostart. https://wiki.archlinux.org/index.php/XDG_Autostart
This is what makes me wish that systemd had been designed with arbitrary sessions in mind, so that I could have a user session, and one for each graphical session as well.
Never thought I’d be a systemd believer either but here we are.
Looking at dex now, I think I like this more than using wm startup files. Doing it this way seems a lot more unix, like what I wanted from systemd user services.
Using your DE's autostart options is probably the simplest solution you can have. I see no benefits in using a systemd service (unless you want the same autostart behaviour across multiple desktop environments)
Depends. If you want a service running, you should start that via systemd. For a normal app I also can't see any benefit.
What if I need to distribute a script to people of many distros and desktop environments? Do I even have an alternative to systemd these days?
I'm not sure what you're trying to accomplish here... You can just give your script to people and they can add it to their autostart by themselves.
Using a systemd service is a great idea, because most of the popular Linux distros use systemd now.
Those who don't.. I guess that if you're experienced enough to use something else than systemd, you are probably skilled enough to write a system service yourself, for whatever init system you're using
I use it to start my ssh-agent, as I typically like to have it started no matter what I login into, whether it be a tty, or a desktop environment, or whatever.
Here's how I implemented this if anyone else might find it useful.
OK, shortly after asking this, I found something that seems to get things working in this stackoverflow answer, specifically the linked comment: https://superuser.com/questions/759759/writing-a-service-that-depends-on-xorg#comment2052205_1351489
Seems a bit hacky, especially considering each service needs to be changed to run this pre command, but as of now, it works!
I do. Check the setup out in gitlab.com/p4block/dotfiles
The .service for each program is copy-paste galore. They all depend on a custom target that I start from bspwmrc.
So you just have a single command in your bspwmrc that starts your target? That was another solution I saw that I might go with, especially seeing as my "solution" posted above isn't so nice and doesn't really work perfectly (realised it doesn't handle relogins).
I have a similar setup, with a bogus target that autostarts with graphical login and stops when I log out. Then the rest of my service files have
Edit: formatting, on mobile
For graphical applications I use my DE's autostart to start the services rather than enabling them the normal way.
I use a user timer and related service to rotate my wallpapers.
I just use the DE's inbuilt startup options.
Did you pass the Xauhority to the services?
I was under the impression that was done automatically with /etc/X11/xinit/xinitrc.d/50-systemd-user.sh .
I once set up everything to use systemd for startup. And I mean my WM as well. It takes some time, and becomes organized; but I took out of there because I had to import a bunch of variables to systemd (which i understand is not secure) for everything to work well. I find user level systemd to be overkill anyway. But what exactly are you having problems with?
It might be worth checking out xdg autostart specification. Basically, desktop files in .config/autostart (and in /usr/share/autostart i think) wants to be autolaunched. I use
dexto start my applications.I use systemd for redshift and it works great
Deleted before we saved it.
Please don't use my old guide I wrote years ago about how to have a session spawned from systemd. It's deprecated, I don't use it, and the functionality it depended on was an unintended feature that the systemd authors didn't design in on purpose. Every now and then people contact me asking how to do it and I have to politely tell them that they're on their own.
i only use a custom service file for iptables but for for the desktop app (like latte dock) i use the desktop env config (kde plasma)
Yes, I use it to start Resilio Sync for my user when I log in. But that's a background service, so I guess not really the point of your question.
Does your DE have any tools for this (assuming you use one)?
GNOME has an initiative to move to systemd user services from XDG autostart, so once that is complete I think you might be able to use some of their work to be able to do what you want.
I don't use linux privately atm, but couldn't u use cron or some fork of it for that?
I use systemd user timer for my backup script because it provides a very good way to log and monitor my servics.
Yes, I launch emacs daemon and resilio-sync upon user login. Both are daemons, though.
I use it to start daemons like redshift.
Deleted before we saved it.
I guess you need to ensure your gui apps start after X has started. If you use login manager (lighdm) then you could do it after user logs in, but as people pointed out desktop applications are probably better way to do that.
I don't use login manager and am realying on xinit, so I start my stuff in .Xresourses, but I also use systemd to start emacs server for me. No idea if it helps you though :-).
I'm using it to start apache2 or nginx on boot automatically.
...as a user service?
I gave up on systemd units long ago..