简体   繁体   English

仅当用户登录到桌面环境时如何启动服务

[英]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.

相关问题 如何以特定用户身份启动/停止/重新启动服务并记录此操作? - How start/stop/restart service as specific user and log this operation? 如何使mongodb服务不能在ubuntu 15.10桌面中自动启动? - How to make mongodb service not start automatically in ubuntu 15.10 desktop? 在Ubuntu中没有桌面环境的情况下启动程序时窗口周围没有阴影 - No shadows around window when I start program without desktop environment in Ubuntu 如何创建一个简单的桌面环境? - How to create a simple desktop environment? Sudo进入用户,启动进程并记录它 - Sudo into a user, start a process and log it 如何记录在Linux中重新启动服务的用户详细信息 - How to log user details who restarted a service in linux 如果未设置环境变量,如何记录? - How to log if an environment variable is unset? 服务mysql启动在我的日志文件中留下“特权表:表'mysql.user'不存在”并且服务器失败 - service mysql start leaves “privilege tables: Table 'mysql.user' doesn't exist” in my log file and the server fails 如何使用 systemd 在用户登录时在用户目录中启动 tmux 服务 - How do I start a tmux service in the user's directory on user login using systemd 仅当服务 A 存在时,Systemd 服务 B 才在另一个服务 A 之后启动 - Systemd service B to start after another service A only if Service A exists
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM