📜 ⬆️ ⬇️

Linux: running graphical applications in the background

Greetings, colleagues!

- Do you want to run linuxdcpp from the console on your home computer while at work?
- You want it to start immediately after booting the system, but do not want to use autologon?
- On your server there is a program that works only in graphical mode, but you do not want to keep the graphical user session all the time included?

If the answer to at least one of the questions is yes, then this article is for you.
')


I think that you, like me, often faced the task of launching something in the background so that you could connect to something later. If there are no problems with console programs, there are tools and they are known, for example, the same screen , then there are no ready-made tools for graphic applications (or they are little known).

Xvfb (X virtual framebuffer) comes to the rescue - a virtual X-server that uses not memory card for output, but RAM.

Everything works quite simply and transparently, so I will not go deep (yes, by the way, there’s nothing to go deep into), but I’ll just describe the working versions of the scripts. The only thing that I had to tinker with in the process of writing them was with X-server authorization to be able to connect to the session without bypassing security issues (i.e., not using work around in the form of “xhost +”) - understanding how everything should work It did not come right away. But first things first.

Requirements for running scripts


- Installed packages: xvfb, x11vnc and vncviewer, for example xtightvncviewer
- Ubuntu 10.04 (this is not really a requirement, this is what everything started and tested. After minor edits, this will work on RHEL 5, but you need to keep in mind that there is no xvfb-run wrapper on the xvfb package, but It can be found on the Internet or taken from the deb-package in Ubuntu)

Application startup script


#!/bin/bash # start_xvfb.sh #   user="giner" #        resolution="700x500x24" #    X- command=linuxdcpp # ,      #   X-     ,  # xvfb-run - -  Xvfb # /tmp/${user}.xvfb.auth - ,    MAGIC-COOKIE    X-.         $user # -screen 0 ${resolution} -auth /tmp/${user}.xvfb.auth -   Xvfb   #  X-   :99,       --server-num,    start_command="/usr/bin/xvfb-run -f /tmp/${user}.xvfb.auth -s '-screen 0 ${resolution} -auth /tmp/${user}.xvfb.auth' $command" #   .      $user,     "su". #         root (,   ) if ( [ "$(whoami)" = "$user" ] ) then bash -c "$start_command" else su -c "$start_command" -l $user fi 


Script to connect to the running application


 #!/bin/bash # xvfb_connect.sh user=giner #     :99  VNC- x11vnc,      vncviewer.       MAGIC-COOKIE,         Xvfb XAUTHORITY=/tmp/${user}.xvfb.auth DISPLAY=:99 x11vnc -listen localhost -bg && vncviewer localhost 


Start at system startup


To start the application at system startup, it is enough to add the start_xvfb.sh script to /etc/rc.local, for example:
 ... /etc/_giner/scripts/start_xvfb.sh & ... 


That's all. Enjoy your administration!

Update1 : in the comments they told (ykl) about xpra, which is part of the partiwm project. In essence, this is a ready-made solution for performing the same tasks as my scripts written in python and not requiring VNC.

Update2 : as paramobilus rightly noted , it is possible to launch applications on the server in the same way even in the absence of a working environment, a window manager, Xs, and even a video card.

Source: https://habr.com/ru/post/113928/


All Articles