Xpra

From ArchWiki
Revision as of 07:59, 26 December 2012 by Chrisl (Talk | contribs) (Article for xpra. I have added a systemd unit I created for autostarting xpra.)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Xpra is a program that allows to start X programs and leave them running after disconnecting to reconnect at them again at a later time.

It is possible to start X programs on a remote machine, connect to the machine over ssh, disconnect and reconnect on a different machine again while the programs continue running, similar to what screen does to console-based programs.

Installation

Install the package xpra-winswitchAUR from the AUR.

Use

Start an xpra server on the machine where you want to run the applications (we are using display number 7 here):

$ xpra start :7

Now you can start an application, e.g. firefox:

$ DISPLAY=:7 firefox

Or, if you want to start a screen session and execute the programs from there to be able to close the console:

$ DISPLAY=:7 screen
[screen starts]
$ firefox

Note that if you start screen like this you don't have to specify the display number when executing programs. They will be running on the xpra display automatically.

After running these commands, you don't see any windows yet. To actually see the applications on your display, you have to connect to the xpra server. If you are connecting to an xpra display on the same machine, start the xpra client like this:

$ xpra attach :7

Or, if you are connecting to a remote machine over ssh:

$ xpra attach ssh:user@example.com:7

After starting the client, any programs running on the remote server display are displayed on your local screen. To detach, type Template:Keypress or use the command:

$ xpra detach ssh:user@example.com:7

Programs continue to run on the server and you can reattach again later.

You can stop the server with:

$ xpra stop :7

on the machine where the server is running, or remotely:

$ xpra stop ssh:user@example.com:7

Tips and tricks

Start at boot

Server

It is possible to start the xpra server at boot using a systemd unit.

Create the unit file:

/etc/systemd/system/xpra@.service
[Unit]
Description=xpra display

[Service]
Type=simple
User=%i
EnvironmentFile=/etc/conf.d/xpra
ExecStart=/usr/bin/xpra --no-daemon start ${%i}

[Install]
WantedBy=multi-user.target

Now create the configuration, adding a line for each username you want to have an xpra display:

/etc/conf.d/xpra
myusername=:7

Enable the service for each username that owns a display. In this example, the service would be xpra@myusername.service.

Client

If the client is a remote machine, use SSH keys to be able to connect to the server without typing a password. Read SSH Keys for more details.

Add to your ~/.xinitrc file the line necessary to start the connection, adding an & at the end of the line.

Make sure to add such line before the exec line.

For example, on a remote client it could be:

~/.xinitrc
xpra attach ssh:user@example.com:7 &