LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (http://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   service application that has access to the GUI (http://www.linuxquestions.org/questions/linux-desktop-74/service-application-that-has-access-to-the-gui-4175496772/)

bjdodo 03-02-2014 04:35 PM

service application that has access to the GUI
 
Hi

I have written the app that has a GUI part (it generates images from invisible javafx controls and saves them into images). As a next step I'd like to make it an application that is always running, i.e. something like a service.

I have looked at monit to make it a service, but monit complains:

Failed in XOpenDisplay
(java:4465): Gtk-WARNING **: cannot open display:

Do you have an idea if I can use monit or any similar application to directly run my app?

Features I need:

start my app after reboot
restart my app if it goes down

Any help is appreciated.

Thank you,
Jozsef

catkin 03-03-2014 09:09 AM

Have you tried having the GUI user enabling local access to their X display?
Code:

/usr/bin/xhost +localhost

bjdodo 03-03-2014 05:53 PM

You have directed me to the right direction (knew what to search for on the internet), thank you for your help.

For beginners like I am:

If you want to run a process from a shell that is not a child process of X, define an environment variable:

export DISPLAY=:0

Maybe you'll need to run the above recommended

/usr/bin/xhost +localhost

and then start your app, and it will find the primary X server (of course X server has to be running for this).

So now to run my app as a service, I run monit from an ordinary user account with the -c switch (how to do it during pc start is the next thing I'll need to look at)
(I need the -c switch so that it uses a config file that I supply rather than the config file in /etc which is set up so that it needs to be run as root because it reads/writes everything in /var)
To run monit as a daemon I do monit -c <conffile> -d 60
And in the startMyApp script I simply added

export DISPLAY=:0
/usr/bin/xhost +localhost

So I can run monit from a shell that is not a child process of X and my app will be able to use the GUI.


All times are GMT -5. The time now is 08:16 AM.