Linux Splitting/duplicating X11 server - linux

(ubuntu 19.10)
Hello,
I was wondering if it's possible to split what's output to a Linux x11 server and duplicate it onto a VNC server.
Basically I currently have a Java Application (prebuilt JAR so I don't have much control over it) that renders something to the native X11 server in: /tmp/.X11-unix. What I want to do is duplicate the information that's being written to the X11 socket to also be written to a VNC server at the same time.
Currently:
Running Java GUI Application --producesData--> Data --isWrittenTo--> /tmp/.X11-unix
Desired:
Running Java GUI Application --producesData--> Data --isWrittenTo--> /tmp/.X11-unix AND --isWrittenTo--> /tmp/vnc-server
Other (less desired) solution:
Running Java GUI Application --producesData--> Data --isWrittenTo--> /tmp/.X11-unix --isCopiedTo--> /tmp/vnc-server (not sure if there's even a difference between just running a normal VNC server)
If possible I'd rather not copy the entire X11 server's content (the whole desktop), but just what's being delivered by the Java Application. If this isn't possible what's the next best solution?
Thanks

Related

Standalone program for accessing and developing in Linux in web browser

Is there any software working like this?
Runs as a standalone program. No install is needed. Thus, can be used as an Ansible module.
After running the program in a remote Linux machine, I can open up a web browser, then open a web page provided by the program. The program provides features similar to file explorer, IDE-level code editor, debugger, etc. In terms of debugger, there is already similar one; gdbgui.
There is another way such as Gnome, KDE or X11. However, these requires much packages to be installed. I don't want they be installed, because my Linux machines are kept to be small and secure.
You might consider having some terminal emulator running inside a browser. Such things exist, e.g. libonion has oterm as an example application. Then you can do all the things that a command line interface thru a unix shell provides (of course, you won't be able to run GUI applications, e.g. X11 clients such as GTK or Qt applications).
You could also consider some webmin like stuff.
Notice that you don't need to have a desktop environment on a remote Linux machine. Most of them (e.g. internet servers) have only command line interface.
Learn more about X11: you could have an X11 server on your laptop (e.g. under Windows if so needed) and run remotely X11 clients (that is GUI applications) with ssh -X on your remote Linux system.
However, these requires much packages to be installed. I don't want they be installed, because my Linux machines are kept to be small and secure.
I don't understand that requirement. On my VPS, running in some OVH datacenter, I do have X11 client applications (notably emacs). I don't believe that lowers the security of my system, and the disk space consumption for X11 applications and libraries is small enough these days. And of course I use standard commands (like cp(1), mv(1), rm(1), grep(1), find(1), less(1), file(1), sed(1) ....) to manage files. Any graphical file manager is useless (and I never use them, while using Unix since 1986)
You really should learn how to use the command line on Linux. It is incredibly powerful.

Cloning display output via ssh

Is it possible to clone image from display via ssh? I want to see what is on my first laptop display from another laptop, but without any additional software like teamviewer or vnc.
The short answer is: Yes, but you may be unhappy with the results.
The protocol you are looking for is called X11 Forwarding. This option must be enabled on your server by setting X11Forwarding yes in /etc/ssh/sshd_config, then reloading the daemon.
Once enabled on the server, the client must initiate their ssh session using the -x flag.
The major limitations of this technology are that:
The data is not optimized for transfer over the wire. For most environments you end up with a low framerate and/or graphical artifacts. As long as you're doing something like running a GUI installer it should not be a problem, but do not expect to be able to stream video / play a game using X11 forwarding.
The client must have an X server installed. If you are connecting from a Windows machine (or another machine that does not have an X server installed), you may need to use a project such as Xming in order to actually interpret the data once you get it to the client.

Forwarding display in batch context

I have Linux compute server A on which I would like to execute an application, say HV (I use this HV application to render a CAE model and capture the image). Eventhough I run this HV in batch mode, from putty terminal, it requires X windows. That is I need to run Xming and forward the display from server A, else it exits with error "No valid fonts - exiting". (In this case I am connecting to server A from my windows laptop using putty)
Instead of using Xming, the workaround I use is Xvfb. This works great in 90% of the cases. In the remaining 10% cases, few of the objects are not rendered in the captured image file.
Is there any alternate to Xvfb. There are few mention on net about Xdummy, but not much details. Or, it there any way to pass the relevant font, without forwarding the display?
My actual use case is, I have web application running on another Linux server, let us call it Server B. When I trigger the event from the client browser, the Server B connects to Linux Server A via ssh and executes the HV application. Even in this scenario, I tried ssh -X instead of just ssh for the connection between B and A. Still the application is exiting error "No valid fonts - exiting" if I don't use Xvfb.
We had the similar issue with xvfb not working consistent and contacted the vendor, their suggestion was to upgrade graphics drivers to the latest version. It did the trick. Xvfb created consistent size images.
Thanks,
anony

How to launch firefox from C program/daemon under Linux

I am having some problems with launching firefox from a Linux daemon written in C.
When I launch firefox on the machine itself (via terminal) from the command shell using /usr/bin/firefox it works OK and a firefox browser window lanunches as it should.
However if I try this within my C daemon using system("/usr/bin/firefox"), firefox launches its process in the terminal but the browser window is not opened?
A similar thing happens when I try to do this using remote terminal acces. It's something to do with telling the system to open firefox in window mode rather than trying to open it in terminal mode - but I dont know how to specify this using bash commands?
I am using Lubuntu 11.10 in my Linux System.
Any help is most appreciated.
There's a reason I asked why you're attempting to do what you want. I didn't want to get into great details in my comment.
Firefox on Unix is an X-Window process (most of the Linux/Unix desktops are based upon the X11 protocol which is the heart of X-Window). What X-Window does is separate the display of the program from the process running the program. For example, I am now running Firefox from a Linux box at work, but the Linux box is actually displaying the Firefox browser window at home on my Mac.
In order to do this, I had to:
Run X11 on my Mac. The X11 program creates a default X11 client display called 0.0 which pretty much says the first screen and the first instance of X11 running (computer geeks like counting from zero). The process runs in the background on my Mac. In a certain sense, it's really a server process and not a client because it's waiting on port 6000 for a client X11 process (Firefox) to tell it what to do.
Before I run firefox, I have to tell my Mac's X11 process that I grant the X11 server running Firefox to be able to display on my X11 client process. Otherwise, you can imagine someone spamming another person by continuously popping up Windows on their display. You can use the xhost program to do this.
In order to run Firefox on the Linux box, I have tell the Firefox process what X11 client I'm running it on. I can do this by setting the DISPLAY environment variable to something like "10.0.1.33:0.0". This means the X11 client is running the the machine on IP address 10.0.1.33, and I want you to use the first screen, and the first instance of the X11 client on that screen.
Now, I can run Firefox on my Linux box, and the display will display on my Mac.
The problem you're running into is that there's simply no X11 client when you're starting FireFox as a daemon process. An X11 client is associated with a user and a display of some sort. The display could be a virtual display, but there's got to be an X11 client that's running and is addressable in some way, so the process knows where to display the output.
By the way, you said daemon which has a very, very specific meaning in Unix/Linux. A daemon is a process that runs in the background and usually has a service (and a port) associated with it. For example, there's an FTP daemon called ftpd, the mail server uses the sendmail daemon, ssh has the sshd daemon. Daemons have no display associated with them.
However, it looks like you might be using the word to mean launching Firefox via another process. Is that true? If so, you'll have to make sure that Firefox knows the X11 display to use (there's a command line setting to use to specify the display), and that your X11 client (your login session) has given permission for another process to update your display with the program window.
Can you please explain what you're trying to do in a bit more detail? If you simply want to download a file from a remote http server (which of course is running the http daemon process called httpd), you should use curl or wget which don't require a display and are way simpler to use. If you're trying to do something else, let us know exactly what it is.
Firefox needs to know which display it should open on. When you run it from within a gui, even through a terminal emulator, the DISPLAY environment variable is set to the appropriate value. When you launch from the daemon, try system("/usr/bin/firefox -display=:0").
Make sure that the DISPLAY environment variable is properly set in your daemon to refer to the X server that you want your firefox to use.
If the daemon is run as a different user account than the user account that "owns" the X server that you want to use, you will also need to use xauth(1) to configure the authentication token to grant permission to use the X server.
Often times, it is far easier to use ssh -X to tunnel X and properly configure the xauth(1) tokens in one go than try to manage xauth(1) tokens yourself. Maybe adding ssh -X into your environment would be suitable, maybe not. (I've even used ssh -X root#localhost before when I needed to run an X client as root and didn't want to bother with configuring xauth(1) manually. ssh(1) is just so much easier.)

Re-attatching an X server view of a lost process

I'm running Xorg and my (Qt) program daemonises itself. Now I log out and restart the X server. When I log in again my process is still running fine, but I can't see it.
Is there a way of attatching the new incarnation of the X server to the old process?
If I don't restart the whole server, but log out and in again, is there a way to look at the old process?
Thanks
xpra should achieve your requirement. And it can also start tcp connection (without need of ssh). Start it on the you server:
xpra start :100 --start-child=xterm --bind-tcp=0.0.0.0:10000
Connect it on your client:
xpra attach tcp:SERVERHOST:10000
You can also use mac or windows xpra app to connect it. I tried in on win7 and osx10.10.2. The download link:
windows: https://www.xpra.org/dists/windows/Xpra_Setup.exe
mac: https://www.xpra.org/dists/osx/x86/Xpra.dmg
After the connection to the X server is lost, it is not possible to regain it.
There was an xserver proxy called xmove, but it is quite deprecated and doesn't work with several newer X extension, which are likely used by modern toolkits.
You could try to run your process in another virtual X server like xvnc or (better) NX. NX is a X proxy technology developed by NoMachine. There exist free implementations of NX servers as well.
If you run your program inside such a server, it is possible to attach and detach from it from arbitrary graphical environments.
Use something like Xpra: it allows you to run applications on an off-screen X11 server to which you can re-attach whenever needed, and from remote machines too. It supports "seamless" sessions too so the windows will appear just like local windows.
Practical example:
xpra start :10 --start-child=/bin/YOURAPP
Then whenever you want to re-attach (say after an X11 server restart):
xpra attach :10
Or from a remote machine:
xpra attach ssh://THESERVERHOSTNAMEORIP/10

Resources