[英]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.我尝试使用 systemctl 和 PAM 方法,但找不到方法。 I tried with a script using cron, which would check the Display environment and start the binary.
我尝试了使用 cron 的脚本,该脚本将检查显示环境并启动二进制文件。 But i would like to use the service method rather than the cron method.
但我想使用 service 方法而不是 cron 方法。
If your Linux environment is systemd based, you can create a systemd service unit for the user.如果您的 Linux 环境是基于systemd的,您可以为用户创建一个 systemd 服务单元。 See the ArchLinux wiki .
请参阅ArchLinux 维基。
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.由于您的应用程序依赖于用户的图形环境,我认为使用XDG方式会更安全:
~/.config/autostart
下的.desktop
文件(对于单个用户)或/etc/xdg/autostart
下的所有用户。 See the Desktop Application Autostart Specification .请参阅桌面应用程序自动启动规范。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.