LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 10-07-2019, 05:29 AM   #1
linom
Member
 
Registered: May 2015
Location: India
Distribution: Debian, CentOS,Redhat, Fedora, Ubuntu
Posts: 91

Rep: Reputation: 13
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.
 
Old 10-07-2019, 06:29 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,336
Blog Entries: 3

Rep: Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731
It should be a matter of making a user unit file and then working out the correct WantedBy setting.

Or use .xsession instead.

Last edited by Turbocapitalist; 10-07-2019 at 06:30 AM.
 
Old 10-07-2019, 11:13 AM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by Turbocapitalist View Post
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.
 
1 members found this post helpful.
Old 10-07-2019, 01:28 PM   #4
linom
Member
 
Registered: May 2015
Location: India
Distribution: Debian, CentOS,Redhat, Fedora, Ubuntu
Posts: 91

Original Poster
Rep: Reputation: 13
Quote:
Originally Posted by Turbocapitalist View Post
It should be a matter of making a user unit file and then working out the correct WantedBy setting.

Or use .xsession instead.
Tried with the Systemd but it did not workout. Any examples on .xsession will be helpful
 
Old 10-07-2019, 01:31 PM   #5
linom
Member
 
Registered: May 2015
Location: India
Distribution: Debian, CentOS,Redhat, Fedora, Ubuntu
Posts: 91

Original Poster
Rep: Reputation: 13
Quote:
Originally Posted by ondoho View Post
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.
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.
 
Old 10-07-2019, 01:37 PM   #6
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,738

Rep: Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213
Quote:
Originally Posted by linom View Post
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.
 
Old 10-11-2019, 04:51 PM   #7
linom
Member
 
Registered: May 2015
Location: India
Distribution: Debian, CentOS,Redhat, Fedora, Ubuntu
Posts: 91

Original Poster
Rep: Reputation: 13
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.
 
Old 10-12-2019, 04:41 PM   #8
bgstack15
Member
 
Registered: Jul 2017
Distribution: korora
Posts: 90

Rep: Reputation: Disabled
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.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to log internal-sftp chroot jailed users access log to /var/log/sftp.log file LittleMaster Linux - Server 0 09-04-2018 03:45 PM
Does Deepin Desktop Environment support addons that can heavily modify the desktop environment? Joe232 Linux - Software 1 02-07-2018 07:43 AM
[SOLVED] Environment variable - only root can log in graphically, lots of programs won't start Pscylo Slackware 9 09-06-2012 03:31 PM
PHP Site - Controlling User Environment for the Session During Log-in and Log-out devUnix Programming 2 03-27-2012 10:14 PM
how to create sftp user only in red hat 4 not ftp user ..only sftp user princeu28 Linux - Newbie 1 10-14-2008 08:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 01:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration