# Customizing the user’s session

This chapter describes the primary places where administrator-defined scripts can be inserted to be run at different points of the session lifecycle.

For customizing the available desktop environments, defining new ones, and other configuration of the profiles and profile chooser, see ThinLinc profiles.

## Master node scripts

On a master node, there are two directories of scripts that are run when a user connects to the ThinLinc cluster.

The files are executed in a numerical order, meaning that a script `42-foo` will be executed before `43-bar`.

`/opt/thinlinc/etc/sessionstartup.d/`

> Scripts in this directory are run as the root user after the session has been started but before the client is redirected to the agent. The environment variable USER is set to the username of the user connecting to the cluster.

`/opt/thinlinc/etc/sessionreconnect.d/`

> Scripts in this directory are run as the root user before the client is redirected to the agent. The environment variable USER is set to the username of the user connecting to the cluster.

Note

The client will not be redirected to the agent before the scripts have completed. If background execution is desired, place the command to be run in the background and make sure all file descriptors are closed. For example:

    #!/usr/bin/env bash
    /opt/thinlinc/sbin/tl-limit-printers < /dev/null > /dev/null 2>&1 &

For further information, see Master session startup.

## Agent node scripts

On an agent node, there are two directories of scripts that are run as part of the session’s lifecycle.

The files in these directories are executed in numerical order, meaning that a script `42-foo` will be executed before `43-bar`.

Scripts with a `.sh` extension are sourced as shell scripts instead of executed normally, making it possible to pass environment variables to later scripts in the chain.

`/opt/thinlinc/etc/xstartup.d/`

> Scripts in this directory are run as the logged-in user after the user’s display server has started but before the selected profile is launched.

> As part the of the chain of the scripts in `xstartup.d/`, the profile chooser (`20-tl-select-profile.sh`) is run. It will set the environment variable TLPROFILE to the profile selected. This makes it possible to alter the behavior of scripts later in the chain based on the user’s profile selection.

`/opt/thinlinc/etc/xlogout.d/`

> Scripts in this directory are run after the selected profile has terminated, but before the display server terminates.

> Any environment variables set by `.sh` scripts in `xstartup.d/` at the start of the session will still be available here.

For further information, see Agent session startup.

## Examples

### Inhibit “Start a program”

The native client can be configured to suppress the profile chooser and instead run a command specified by the user. See Advanced tab for more information.

When the client is configured to run a user-specified command in this manner, the agent will set the environment variable TLCOMMAND to this command. In this case, the profile selection dialog will be disabled, and tl-run-profile will execute the command specified by the client instead of a profile command. To disable this functionality, create the file `/opt/thinlinc/etc/xstartup.d/00-no-startprog.sh`, containing:

    unset TLCOMMAND

### Use client language

The ThinLinc client reports the language settings on the client side when requesting a session. This can be used to configure the language on the server side. The idea is that in an environment where several languages are in use, a user could automatically get their preferred language based on what their client computer is configured for.

To activate this, a symlink needs to be created:

    $ sudo ln -s /opt/thinlinc/libexec/tl-set-clientlang.sh \
       /opt/thinlinc/etc/xstartup.d/00-tl-set-clientlang.sh

Also, make sure no other parts of the startup environment are trying to set the LANG variable. For example, on Fedora, the files `/etc/profile.d/lang.sh` and `/etc/profile/lang.csh` will override the LANG variable set by `tl-set-clientlang.sh`.

### Speeding up session startup

If a user has a complicated session startup with many time-consuming operations, it can take quite a while before the user’s desktop environment (for example, KDE or GNOME) begins to start. One example of when this happens is when mounting local drives.

One way of accelerating this process is to execute some of the operations in the background. Often, there is no need to mount the local drives before starting the desktop environment because it takes longer to start the desktop environment than it takes to mount the local drives. The two operations can easily run in parallel. The same goes for the example of mounting shared directories.

The easiest way to accomplish this is to add an `&` sign after commands run by scripts in `/opt/thinlinc/etc/xstartup.d`.

Make sure that commands that must be run before starting the window environment are run sequentially. For example, configuring desktops via TLDC must be done before starting KDE.