[SOLVED] How to start a service only when a user log to Desktop Environment
Linux - DesktopThis forum is for the discussion of all Linux Software used in a desktop context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to start a service only when a user log to Desktop Environment
Hello Members,
I trying to find a solution on starting a service or to execute a binary only when a user logs to his desktop environment. Basically, my binary is dependent on the Display environment of the user.
I tried with systemctl and PAM methods but unable to find a way. I tried with a script using cron, which would check the Display environment and start the binary. But i would like to use the service method rather than the cron method.
It should be a matter of making a user unit file and then working out the correct WantedBy setting.
This would appear to be the canonical solution.
Or, have a look at your DE's autostart options, and add the command there.
Since I don't use a DE, it's ~/xinitrc for me. Maybe ~/.xsession for others.
Or, have a look at your DE's autostart options, and add the command there.
Since I don't use a DE, it's ~/xinitrc for me. Maybe ~/.xsession for others.
I tried with it. But in case when there is a switch user, the process started with one user does not gets stopped/restarted by the other user.
I tried with it. But in case when there is a switch user, the process started with one user does not gets stopped/restarted by the other user.
Isn't that the expected behavior for "starting a service when a user log into Desktop?" I'd expect it to run until the user logs out.
Is not the service user-specific?
Perhaps we need more detail about what exactly you're trying to accomplish.
Dear All
Thank you all for your assistance. The binary i am using is a qt based application and is dependant on active or logged in users Display environment variable. For eg. if "A" user with display environment :0 logins, then the binary will require this information to run properly and when another user say "B" with display environment :1 switch overs, the binary should reload with this display environment.
Anyways, with ideas from you guys, i was able to a probable workaround using the DE's autostart. Created a Client/Server socket. The client will autostart and connect the server which in turn shall check the active user and its display and then reload the binary. That's the reason i call it a workaround. Though it worked in Ubuntu, I hope the same method of autostart will be available in other RPM and DEB based OS'es.
Sharing this workaround possibly someone can be of assistance. Do suggest if any better ways.
If you want to run a binary when a user logs in to a desktop environment, it sounds like the XDG autostart concept is what you want. Read the Arch wiki article, and then the official specification (which is linked in the wiki article).
It is up to a desktop environment to follow the spec; it is a "higher-up" concept than the .xsession contents, but it's what I use and it seems to work adequately. You can do it per user, or for the entire system. Users can have their own overrides for it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.