Prolonging terminal sessions/fr: Difference between revisions

From Alliance Doc
Jump to navigation Jump to search
(Created page with "Pour une introduction à tmux : * [https://leanpub.com/the-tao-of-tmux/read <i>The Tao of tmux</i>] * [https://www.youtube.com/watch?v=252K9lrRdMU <i>Getting Started With TMUX</i>], vidéo de 24 minutes * [https://www.youtube.com/watch?v=Y1Of3S5iVog <i>Turbo boost your interactive experience on the cluster with tmux</i>], vidéo de 58 minutes")
(Created page with "[http://hyperpolyglot.org/multiplexers Voyez la documentation complète].")
Line 33: Line 33:
===Aide-mémoire===
===Aide-mémoire===


<div lang="en" dir="ltr" class="mw-content-ltr">
[http://hyperpolyglot.org/multiplexers Voyez la documentation complète].
For a complete reference, see [http://hyperpolyglot.org/multiplexers this page].
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">

Revision as of 14:23, 4 July 2023

Other languages:

Pour soumettre et faire le suivi des tâches, modifier des fichiers et plusieurs autres opérations, vous aurez peut-être besoin de vous connecter à une grappe via SSH. Il est quelquefois nécessaire de garder la connexion active pendant plusieurs heures, même plusieurs jours et nous décrivons ici certaines techniques pour ce faire.

Configuration de SSH

Une solution simple pour prolonger une connexion est de modifier la configuration de votre client SSH. Avec MacOS et Linux, cette configuration se trouve dans $HOME/.ssh/config alors qu'avec Windows elle est dans C:\Users\<username>\.ssh\config. Si le fichier n'existe pas, vous devez le créer at ajouter les lignes

Host *
    ServerAliveInterval 240

Par la connexion SSH, ceci transmet un signe de vie à un serveur distant (comme une grappe de l'Alliance) à toutes les 240 secondes (4 minutes), ce qui devrait garder la connexion active même si elle est inactive pendant quelques heures.

Multiplexeur de terminal

The programs tmux and screen are examples of a terminal multiplexer—a program which allows you to detach your terminal session entirely, where it will keep on running on its own until you choose to reattach to it. With such a program, you can logout from the cluster, turn off the workstation or hibernate the laptop you use to connect to the cluster and when you're ready to start working again the next day, reattach to your session and start from right where you left off.

Login node dependency
Each of our clusters has several login nodes and your tmux or screen session is specific to a login node. If you wish to reattach to a session, you must ensure you're connected to the right login node, which of course means remembering which login node you were using when you started tmux or screen. Login nodes may also occasionally be rebooted, which will kill any detached terminal sessions on that node.

tmux

The tmux software is a terminal multiplexer, allowing multiple virtual sessions in a single terminal session. You can thus disconnect from an SSH session without interrupting its process(es).

Pour une introduction à tmux :

Aide-mémoire

Voyez la documentation complète.

Command Description
tmux Start a server
Ctrl+B D Disconnect from server
tmux a Reconnect to server
Ctrl+B C Create a new window
Ctrl+B N Go to next window
Ctrl+B [ Enable "copy" mode, allowing to scroll with the mouse and Page-Up Page-Down
Esc Disable "copy" mode

Launch tmux inside a job submitted through tmux

If you submit a job with tmux and try to start tmux within the same job, you will get the lost server error message. This happens because the $TMUX environment variable pointing to the tmux server is propagated to the job. The value of the variable is not valid and you can reset it with:
Question.png
[name@server ~]$ unset TMUX

However, nested use of tmux is not recommended. To send commands to a nested tmux, one has to hit Ctrl+B twice; for example, to create a new window, one has to use Ctrl+B Ctrl+B C. Consider using screen inside your job (if you are using tmux on a login node).

GNU Screen

The screen program is another widely used terminal multiplexer. To create a detached terminal session, you can use the following command

Question.png
[name@server ~]$ screen -S <session name>

It's a good idea to give a descriptive name to your terminal sessions, making it easier to identify them later. You can use the command screen -list to see a list of your detached terminal sessions on this node,

Question.png
[name@server ~]$ screen -list
There is a screen on:
        164133.foo      (Attached)
1 Socket in /tmp/S-stubbsda.

You can attach to one of your sessions using the command screen -d -r <session name>.