简体   繁体   English

Linux:从init.d守护程序启动GUI应用程序

[英]Linux: Starting a GUI application from an init.d daemon

I have an /etc/init.d/foo script that starts on system boot and listens forever for certain events of interest. 我有一个/etc/init.d/foo脚本,该脚本在系统启动时启动,并永久监听某些感兴趣的事件。 These events will typically occur substantially well after the user has logged in and, thus, will have no connection with the login event, per se . 这些事件通常在用户登录后会发生得相当好,因此,与登录事件本身没有任何关系。

Whenever foo detects a specific event, it needs to launch a 3rd party GUI application, and then continue to listen for other events just as before. 每当foo检测到特定事件时,它都需要启动第三方GUI应用程序,然后像以前一样继续侦听其他事件。

I'm observing that I can launch non-GUI scripts just fine from foo , but not a GUI application. 我发现我可以从foo很好地启动非GUI脚本,但不能启动GUI应用程序。 (I kinda knew I'd run into hurdles here.) (我有点知道我在这里遇到了障碍。)

Question: How is this task generally accomplished in Linux? 问题:在Linux中一般如何完成此任务? That is, the launching of a GUI application in the foreground from some sort of a daemon launcher process running in the background. 也就是说,从后台运行的某种守护程序启动器进程在前台启动GUI应用程序。

Note: I don't have the source code of this 3rd Party GUI application. 注意:我没有此第三方GUI应用程序的源代码。 Thus, any solution has to work wholly from outside of it. 因此,任何解决方案都必须完全从其外部起作用。

The correct way is that you start an application within your X session (GUI login) that listens to new events. 正确的方法是在X会话(GUI登录)中启动一个侦听新事件的应用程序。 If you have to decouple the event listening from the X session, you need to defer. 如果必须将事件侦听与X会话分离,则需要延迟。 That means, you have two applications, one that listens to the events, the other one that waits for a trigger just for the GUI application. 这意味着,您有两个应用程序,一个监听事件,另一个等待GUI应用程序的触发。 The application that listens to events then triggers your application that runs within X. 侦听事件的应用程序然后触发在X内运行的应用程序。

So how to do this? 那么该怎么做呢?

  1. Depending on your X session there are several "autostart" methods, eg applications that are started after the user logs in. These applications will have the X context, eg no security barriers when connecting to the X server (which they need to run as a GUI application). 根据您的X会话,有几种“自动启动”方法,例如,在用户登录后启动的应用程序。这些应用程序将具有X上下文,例如,连接到X服务器时没有安全屏障(它们需要作为X服务器运行。 GUI应用程序)。

  2. An "application" here can also be a simple script that keeps running. 这里的“应用程序”也可以是保持运行的简单脚本。 You don't need to fire up a compiler for this. 您无需为此启动编译器。 Eg Perl might be a good language for this. 例如,Perl可能是一种很好的语言。

  3. Your application that listens to events can write to a named socket in /tmp/ when an event occurs. 当事件发生时,侦听事件的应用程序可以将其写入/ tmp /中的命名套接字。

  4. Your script/application in the X session can read from that named socket and fire up the GUI application whenever a new message appears. X会话中的脚本/应用程序可以从该命名的套接字读取,并在出现新消息时启动GUI应用程序。

In the end it is not much work at all, but you might have to read a bit or search for such solutions on the web. 最后,它根本不花太多精力,但是您可能需要阅读一些内容或在网络上搜索此类解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何捕获从init.d运行的linux守护进程的pid - How to capture pid of a linux daemon run from init.d init.d守护程序脚本中的lockfile用途(Linux) - lockfile purpose in init.d daemon scripts (linux) 具有优先级的Amazon EC2 Linux Distro init.d脚本启动守护程序 - Amazon EC2 Linux Distro init.d script launching daemon with priority 将jar作为Linux服务运行-init.d脚本无法启动应用程序 - Running jar as a Linux service - init.d script gets stuck starting app Linux使用/etc/init.d/中的脚本自动启动 - Linux autostart with script in /etc/init.d/ SUSE Linux 的 WildFly init.d 脚本 - WildFly init.d scripts for SUSE Linux 在/etc/init.d脚本中调用守护进程是阻塞的,而不是在后台运行 - Call to daemon in a /etc/init.d script is blocking, not running in background Erlang:守护进程'init.d'脚本无法启动 - Erlang: daemon 'init.d' script fails to start 为什么我的 init.d start-stop-daemon 脚本在启动时没有启动应用程序,但我可以手动启动服务? - Why didn't my init.d start-stop-daemon script start the application on boot, but I can start the service manually? 如何将init.d脚本从Ubuntu / Debian Linux转换为Solaris? - How do I translate init.d scripts from Ubuntu/Debian Linux to Solaris?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM