简体   繁体   中英

How to start a service only when a user log to Desktop Environment

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.

If your Linux environment is systemd based, you can create a systemd service unit for the user. See the ArchLinux wiki .

As your application depends on the graphical environment for the user, I think it can be safer to use the XDG way: a .desktop file under ~/.config/autostart (for a single user) or under /etc/xdg/autostart for all users. See the Desktop Application Autostart Specification .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM