Skip to content

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.

56 points35 comments
Open on Reddit
About this post
Posted
Archived
Score
56 · 100% up
Kind
Text
ID
boglso

Author

2
posts
14
comments
1
media
View profile

37 comments

systemd is not a right tool for graphical applications. Use desktop entries + xdg autostart. https://wiki.archlinux.org/index.php/XDG_Autostart

35 points

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.

5 points

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.

3 points

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)

13 points

Depends. If you want a service running, you should start that via systemd. For a normal app I also can't see any benefit.

8 points

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?

1 points

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

1 points

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.

13 points

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.

5 points

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).

1 points

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

[Install]

WantedBy=bogus-target-name.target

Edit: formatting, on mobile

2 points

For graphical applications I use my DE's autostart to start the services rather than enabling them the normal way.

3 points

I use a user timer and related service to rotate my wallpapers.

3 points
unknown author1 hidden

Did you pass the Xauhority to the services?

1 points

I was under the impression that was done automatically with /etc/X11/xinit/xinitrc.d/50-systemd-user.sh .

2 points

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 dex to start my applications.

1 points
unknown author

Deleted before we saved it.

1 points

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.

1 points

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)

1 points

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)?

1 points

I don't use linux privately atm, but couldn't u use cron or some fork of it for that?

1 points

I use systemd user timer for my backup script because it provides a very good way to log and monitor my servics.

1 points

Yes, I launch emacs daemon and resilio-sync upon user login. Both are daemons, though.

1 points
unknown author

Deleted before we saved it.

1 points

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 :-).

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.