linuxuser-interfacedaemonlaunchinit.d

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. 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.

I'm observing that I can launch non-GUI scripts just fine from foo, but not a GUI application. (I kinda knew I'd run into hurdles here.)

Question: How is this task generally accomplished in Linux? That is, the launching of a GUI application in the foreground from some sort of a daemon launcher process running in the background.

Note: I don't have the source code of this 3rd Party GUI application. Thus, any solution has to work wholly from outside of it.


Solution

  • The correct way is that you start an application within your X session (GUI login) that listens to new events. If you have to decouple the event listening from the X session, you need to defer. 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. The application that listens to events then triggers your application that runs within X.

    So how to do this?

    1. Depending on your X session there are several "autostart" methods, e.g. applications that are started after the user logs in. These applications will have the X context, e.g. no security barriers when connecting to the X server (which they need to run as a GUI application).

    2. An "application" here can also be a simple script that keeps running. You don't need to fire up a compiler for this. E.g. Perl might be a good language for this.

    3. Your application that listens to events can write to a named socket in /tmp/ when an event occurs.

    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.

    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.