.. meta::
   :description: Overview of the different points where ThinLinc's
                 session startup can be modified.

.. _configuration_customizing_user_session:

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
:ref:`session lifecycle <session_lifecycle>`.

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

.. _configuration_master_scripts:

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
:file:`42-foo` will be executed before :file:`43-bar`.

:file:`/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 :environ:`USER` is set to the username of the
  user connecting to the cluster.

:file:`/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 :environ:`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:

   .. code:: bash

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

For further information, see
:ref:`configuration_session-startup-vsmserver`.

.. _configuration_agent_scripts:

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 :file:`42-foo` will be executed before :file:`43-bar`.

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

:file:`/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 :file:`xstartup.d/`, the
  :ref:`profile chooser <profiles>` (:file:`20-tl-select-profile.sh`) is
  run. It will set the environment variable :environ:`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.

:file:`/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 :file:`.sh` scripts in
  :file:`xstartup.d/` at the start of the session will still be
  available here.

For further information, see
:ref:`configuration_session-startup-vsmagent`.

Examples
~~~~~~~~

.. _configuration_start_program:

Inhibit "Start a program"
^^^^^^^^^^^^^^^^^^^^^^^^^

The native client can be configured to suppress the :ref:`profile
chooser <profiles>` and instead run a command specified by the user. See
:ref:`client_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 :environ:`TLCOMMAND`
to this command. In this case, the profile selection dialog will be
disabled, and :program:`tl-run-profile` will execute the command
specified by the client instead of a profile command. To disable this
functionality, create the file
:file:`/opt/thinlinc/etc/xstartup.d/00-no-startprog.sh`, containing:

.. code:: sh

   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:

.. code:: console

   $ 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 :environ:`LANG` variable. For example, on Fedora, the files
:file:`/etc/profile.d/lang.sh` and :file:`/etc/profile/lang.csh` will
override the :environ:`LANG` variable set by
:file:`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 :file:`/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.
