nexsh — user manual
By Roberto Arato of aratoingegneria.it
nexsh is the NEX shell: a complete bash to which NEX adds the cluster.
You work as usual (variables, pipelines, scripts, jobs, fg), but every
command can run on another node, the working node is changed the way you
change directory and some commands choose the least loaded node by
themselves.
Versions described: nexsh 1.2.0, nex and nexagentd 1.0.0~beta1 (the nex-cluster version).
Contents
- Concepts
- Starting nexsh
- The prompt
- Watching the cluster
- Running on another node:
on - The least loaded node:
on any - The current node:
cn - Automatic remotable commands
- Job control
- Pipelines, redirections and files
- Environment variables
- CPU and memory limits
- Interactive programs
- Scripts with nexsh
- Exit codes
- Rules and security
- Troubleshooting
- Configuration
- Quick reference
1. Concepts
Shared filesystem. All compute nodes mount the same distributed
filesystem, NEXFS, in /nex. A file written in /nex by one node is
immediately visible to the others, with the same owner and the same
permissions. That is why a command can start on another node in the same
directory: the files are the same. Outside /nex (/tmp, /home,
/var) each node has its own files.
Current directory and current node. As the shell has a current
directory, nexsh has a current node: the node it is working on. It is
changed with cn, as the directory is changed with cd.
Agent. nexagentd runs on every node. nexsh talks only to the agent of
its own node; the agents talk to each other over TLS with cluster
certificates. No passwords, no ssh keys between nodes: who you are is told
by the kernel to your agent, and the other agents trust only the cluster's
agents.
Roles. Only nodes with the compute role (and /nex mounted) run
commands. storage-only nodes appear in nodes and nxtop, but do not
accept jobs.
In the reference lab: node-a and node-b are compute, nex-stor is storage only.
2. Starting nexsh
nexsh # interactive shell
nexsh -c 'cd /nex/prog && make' # commands, like bash -c
nexsh script.sh arg1 arg2 # script, like bash script.sh
nexsh --help # short help
A script can declare nexsh as its interpreter:
#!/usr/bin/env nexsh
cd /nex/progetto || exit 1
on any ./elabora dati.txt
At interactive start nexsh reads /etc/bash.bashrc and your ~/.bashrc:
aliases, functions and settings stay the usual ones. Then it adds the NEX
layer. Scripts and programs started from nexsh remain normal bash: the NEX
layer does not propagate behind your back.
To quit: exit or Ctrl-D, as in bash.
3. The prompt
[nex node-a /nex/data/prog]$
node-ais the current node, with its name in the cluster (the one you use withcnandnex run --node), even when the computer has another name: on the USB stick the computernex-0008is the nodesecondo, and the prompt sayssecondo;/nex/data/progis the current directory;- if the directory is not on the shared filesystem the prompt says so:
[nex node-a /tmp local]$
local reminds you that there commands cannot go to other nodes:
the files in /tmp exist only on this node.
To see the whole state at once:
[nex node-a /nex/data/prog]$ nexsh status
nexsh 1.2.0, shared filesystem /nex, automatic: on
current node: node-a (starting node)
remotable commands: cmake make clang ninja cc c++ gcc g++
current directory on the shared filesystem: remotable commands go to the least loaded node
4. Watching the cluster
Node status: nodes
[nex node-a /nex/data]$ nodes
NODE STATE COMPUTE MOUNT LOAD CPU MEM FREE JOBS MS
node-a ok yes nexfs 0.22 2 6.7G 0 0.0
node-b ok yes nexfs 0.15 2 6.8G 0 8.7
nex-stor ok no - 0.00 2 3.1G 0 7.0
- COMPUTE: the node runs commands (
yes) or is storage only (no); - MOUNT:
nexfsif/nexis mounted; - LOAD: average load of the last minute; to be compared with CPU;
- JOBS: NEX commands running on that node;
- MS: response time of that node's agent.
A node that does not answer is reported, never shown with old data:
node-b unreachable connection: Connection refused
In this case the exit code is 2. nodes --json gives the same data in
JSON, for scripts.
Processes of the whole cluster: nxps
[nex node-a /nex/data]$ nxps
NODE PID USER S %CPU MEM AGE COMMAND
node-a 6044 roberto S 0.0 5.1M 2m10s bash --rcfile /usr/share/nex/nexsh.bashrc -i
node-b 6562 roberto S 0.0 1.0M 0m12s sleep 300
...
A normal user sees their own processes on all nodes; root sees them all.
nxps --local shows only the current node, --kernel adds the kernel
threads. nxps is the same command as nex ps.
The cluster top: nxtop
nxtop 20:20:39 3 nodes 6 processes (yours only) sort: CPU
NODE STATE LOAD 1/5/15 CPU MEMORY JOBS UPTIME
node-a ok 0.06 0.05 0.07 2 1000M/7.7G 0 1h08m
node-b ok 0.10 0.12 0.09 2 937M/7.7G 0 1h08m
nex-stor ok 0.01 0.03 0.02 2 698M/3.8G 0 1h08m
NODE PID USER S %CPU MEM AGE COMMAND
node-b 11142 roberto R 98.0 12.0M 0m25s ./calcolo dati.txt
...
It refreshes every 2 seconds. Keys:
| Key | Effect |
|---|---|
c |
sort by CPU (default) |
m |
sort by memory |
t |
sort by running time |
n |
show one node at a time; repeated it moves to the next one and then back to all |
k |
stop a process: asks for node:pid [SIGNAL] |
K |
show or hide the kernel threads |
| space | refresh now |
q |
quit (also Ctrl-C) |
Options: -d 5 refreshes every 5 seconds; --node node-b starts
filtered; --sort mem starts sorted by memory; -b prints one screen as
text and exits (for scripts and logs), -b -n 10 -d 60 prints ten of them,
one a minute.
nxtop -b --sort mem | head -20 # the 10 processes using the most memory
nxtop -b -n 60 -d 60 > /nex/log/carico.txt & # one hour of snapshots
Processors, networks and sockets: nxcpu, nxnet, nxss
$ nxcpu -a
NODE CPU MHZ USE% USER SYSTEM IOWAIT STEAL LOAD MODEL
node-a 2 3398 4.2 2.1 2.1 0.0 0.0 0.54 Intel(R) Core(TM) i7-6800K
cpu0 1.6 0.0 1.6 0.0 0.0 [....................]
cpu1 6.7 3.6 3.1 0.0 0.0 [#...................]
$ nxnet
NODE INTERFACE STATE SPEED RX TX RX TOT TX TOT ERR ADDRESSES
node-a ens34 up 1G 61K/s 24K/s 3.0G 463M 0 10.20.0.10 fe80::...
CLUSTER 83K/s 61K/s (without lo)
$ nxss -l
NODE PROTO STATE LOCAL REMOTE PID USER COMMAND
node-b tcp LISTEN 0.0.0.0:8765 0.0.0.0:* 30519 roberto python3
node-b udp6 UNCONN [::]:9876 [::]:* 30520 roberto python3
nxcpu: usage over the last 2 s interval; IOWAIT is the I/O wait (high if the storage slows down), STEAL the time taken by the hypervisor;-ashows each CPU.nxnet: per-second and total traffic of each interface;-aincludeslo.nxss: TCP and UDP sockets with the process using them;-lonly the listening ones,-t/-uonly TCP or UDP,--node. A user sees their own, root all of them.
All of them accept --node NODE and --json.
Memory: nxfree
[nex node-a /nex/data]$ nxfree
NODE TOTAL USED FREE CACHE AVAILABLE SWAP TOT SWAP USED
node-a 7.7G 1.0G 4.3G 2.6G 6.7G 1.6G 0B
node-b 7.7G 700M 6.4G 622M 6.8G 1.6G 0B
nex-stor 3.8G 483M 2.9G 467M 3.1G 1.6G 0B
CLUSTER 19.2G 1.9G 13.6G 3.7G 16.7G 4.7G 0B
The values are those of free on each node: USED = total minus
available; AVAILABLE is how much a program can still use
without swap. A node that does not answer is excluded from the total and
reported.
Space: nxdf
[nex node-a /nex/data]$ nxdf
CLUSTER FILESYSTEM
MOUNT SIZE USED AVAILABLE USE%
/nex 27.8G 7.3G 20.5G 26% [#####...............]
NEXFS read from node-a; the space already accounts for the copies
NODE DISKS
NODE MOUNT DEVICE TYPE SIZE USED AVAIL USE%
node-a / /dev/sdb1 ext4 27.8G 6.3G 20.1G 24%
node-b / /dev/sda1 ext4 27.8G 6.3G 20.0G 25%
nex-stor / /dev/sda1 ext4 27.8G 4.8G 21.5G 17%
The space of /nex is already divided by the copies: with 3 copies, 20.5G
available means 20.5G of user files (they take three times as much on the
data nodes' disks). If the storage does not answer nxdf does not hang: after
a few seconds it says
the storage does not answer (node-b: storage not answering within 2000 ms)
and exits with code 3.
5. Running on another node: on
on NODE [options] [--] COMMAND [ARGUMENTS...]
The command starts on NODE in the current directory, as yourself (same user and groups), with stdin, stdout and stderr connected to your terminal and signals forwarded. The exit code is the command's.
[nex node-a /nex/data/prog]$ on node-b hostname
node-b
[nex node-a /nex/data/prog]$ on node-b pwd
/nex/data/prog
[nex node-a /nex/data/prog]$ on node-b id -un
roberto
Examples
on node-b make -j4 # compile on node-b
on node-b ./simulazione input.dat > risultato.txt
on node-b python3 analisi.py --anno 2025
on node-b sh -c 'cd sotto && ./prova' # several commands: a shell on the node
on node-b grep -r "errore" log/ # the files are the same as here
on node-b -- -strano-nome # -- separates the options of on from the command
Options
| Option | Effect |
|---|---|
-n |
no stdin (like < /dev/null) |
-t |
force the remote terminal (interactive programs) |
-T |
no remote terminal even if you are at a terminal |
--cpu PCT |
CPU limit as a percentage of one CPU (50 = half, 200 = two) |
--mem SIZE |
maximum memory (512M, 2G); beyond the limit the process dies |
--env NAME=VALUE |
additional variable (repeatable) |
What on refuses, and why
[nex node-a /nex/data]$ on node-b cd /tmp
on: 'cd' is a shell builtin and changes only this shell: it stays local
cd, export, umask, alias change this shell: run elsewhere they
would be useless. Builtins that also exist as programs (pwd, echo,
printf, kill, test) are instead executed.
[nex node-a /nex/data]$ f() { echo ciao; }
[nex node-a /nex/data]$ on node-b f
on: 'f' is a function of this shell and does not exist on node node-b
Functions defined in the shell do not exist on the other node. If you need
them, put them in a script in /nex and run the script.
[nex node-a /tmp local]$ on node-b hostname
nex: directory /tmp is not under /nex, the shared filesystem of the cluster
Outside /nex you cannot go to other nodes: the directory there does not
exist or is a different one.
[nex node-a /nex/data]$ on nex-stor hostname
nex: node nex-stor does not have the compute role: it runs no jobs
6. The least loaded node: on any
[nex node-a /nex/data]$ on any ./calcolo dati.txt
[nex: node-b]
...output of the calculation...
The agent chooses, among the reachable compute nodes with /nex mounted,
the one with the lowest load per CPU, and shows it on stderr
([nex: node]). The calculation:
load per CPU = (max(average load, active jobs) + jobs assigned in the last 30 s) / CPUs
- on a tie (within 0.1) the node you are on is kept: no network for nothing;
- between two remote nodes on a tie the one with more free memory wins;
- recently assigned jobs count immediately, so a burst of commands is spread out instead of all ending up on the same node.
Parallel jobs
[nex node-a /nex/data]$ for i in 1 2 3 4; do on any sh -c "echo lavoro $i su \$(hostname)" & done; wait
[nex: node-a]
[nex: node-a]
[nex: node-b]
[nex: node-b]
lavoro 3 su node-a
lavoro 1 su node-b
lavoro 4 su node-a
lavoro 2 su node-b
A typical case, processing many files:
cd /nex/progetto/dati
for f in *.csv; do
on any -n ./elabora "$f" > "risultati/${f%.csv}.txt" &
done
wait
echo "fatto: $(ls risultati | wc -l) file"
With many files it is better to limit how many jobs start together:
ls *.csv | xargs -P 8 -I{} nexsh -c 'on any -n ./elabora {} > risultati/{}.txt'
The [nex: node] line goes to stderr. To suppress it (for example in a
script that saves stderr to a file): NEXSH_ANNOUNCE=0.
If no node is available:
nex: no node available for --node any: it needs the compute role and /nex mounted (1 nodes unreachable; see nex nodes)
7. The current node: cn
As there is a current directory, there is a current node. cn (change
node) moves the shell to another node: from then on everything runs on
that node, including builtins and local paths.
[nex node-a /nex/prog]$ cn node-b
nexsh: current node node-b (from node-a; cn to go back)
[nex node-b /nex/prog]$ hostname
node-b
[nex node-b /nex/prog]$ make && ./calcolo
...
[nex node-b /nex/prog]$ cd out
[nex node-b /nex/prog/out]$ ls /tmp # /tmp of node-b
[nex node-b /nex/prog/out]$ cn
[nex node-a /nex/prog/out]$
When you come back you are in the directory you had reached
(/nex/prog/out), as if you had done cd over there and here at the same
time.
The forms of cn
| Command | Effect |
|---|---|
cn node-b |
the shell continues on node-b |
cn |
back to the starting node (also exit or Ctrl-D) |
cn node-c (from node-b) |
moves directly to node-c, without nested sessions |
cn node-a (from node-b, if node-a is the start) |
like cn |
cn - |
back to the previous node |
cn any |
goes to the least loaded node; if it is the one you are on, you stay |
[nex node-a /nex/prog]$ cn node-b
[nex node-b /nex/prog]$ cn -
[nex node-a /nex/prog]$ cn -
[nex node-b /nex/prog]$ exit
[nex node-a /nex/prog]$ cn any
[nex: node-b]
nexsh: current node node-b (from node-a; cn to go back)
[nex node-b /nex/prog]$
What it carries along
- the current directory (it must be in
/nex); - the exported variables (
export NAME=...), with the exact values, spaces included; - the terminal:
vim,top,less, Ctrl-C, Ctrl-Z work as locally.
What stays on the starting node: non-exported variables, functions and
aliases defined by hand (those of your .bashrc are there on the node
too), the command history. Variables tied to the local session (SSH_*,
DISPLAY, XDG_*) are not transferred.
[nex node-a /nex/prog]$ export PROGETTO="alfa beta"; LOCALE=1
[nex node-a /nex/prog]$ cn node-b
[nex node-b /nex/prog]$ echo "[$PROGETTO] [$LOCALE]"
[alfa beta] []
When cn refuses
[nex node-b /nex/prog]$ cn nex-stor
cn: node nex-stor has no compute role or no /nex mounted: it does not run shells
[nex node-b /nex/prog]$
The destination is checked before leaving the node: if it is not suitable, you stay where you are.
[nex node-b /nex/prog]$ ./lungo &
[1] 7201
[nex node-b /nex/prog]$ cn
cn: there are active jobs on node-b (jobs): wait for them or end them before changing node
Leaving the node with jobs running would terminate them. Wait for them
(wait), terminate them (kill %1), or start them as independent NEX jobs
with on.
[nex node-a /tmp local]$ cn node-b
cn: /tmp is not on /nex: the current directory must be shared by all nodes
cn or on?
| You want... | Use |
|---|---|
| a command now and then on another node | on node-b command |
| to work for a while on another node | cn node-b |
| to spread many commands | on any command & |
| a single interactive command (vim) | on node-b vim file |
8. Automatic remotable commands
Some commands, listed in the configuration, go by themselves to the least
loaded node: no need to write on any.
[nex node-a /nex/data/prog]$ make
[nex: node-b]
gcc -O2 -c calcolo.c
...
The [nex: node-b] line always says where it went: nothing moves
silently.
When the command stays local
A remotable command goes to another node only if everything it uses is on the shared filesystem. It stays local if:
| Situation | Example | Why |
|---|---|---|
current directory outside /nex |
cd /tmp; make |
the files are only here |
an argument is an absolute path outside /nex |
make -f /tmp/Makefile |
the file is only here |
| an option contains a local path | gcc -I/opt/lib/include x.c |
same |
a local --name=/path option |
cmake --install-prefix=/usr/local |
same |
a relative path that leaves /nex |
make -C ../../../tmp |
same |
| you are root | sudo make |
NEX jobs never run as root |
| automatic mode off | nexsh auto off |
your choice |
[nex node-a /nex/data/prog]$ make -f /tmp/Makefile
make su node-a in /nex/data/prog
[nex node-a /nex/data/prog]$ cd /tmp && make
make su node-a in /tmp
Turning it on and off
nexsh auto off # everything local
nexsh auto on # automatic again
For a single command: command make always runs it locally, because it
skips the automatic function.
Which commands
By default (/etc/nex/nexsh.conf): make, cmake, ninja, gcc,
g++, cc, c++, clang. Each user can add or remove some in
~/.nexsh.conf:
# ~/.nexsh.conf
remote python3 Rscript julia
local cmake
You list command names (looked up in the PATH), not paths: each name
becomes a shell function, and ./simula cannot be one. For a program of
the project use on any ./simula.
Automatic commands start without a remote terminal: Ctrl-Z, bg and fg
work as locally (see chapter 9); the only visible effect is that gcc
does not color its messages.
Note: make goes to the least loaded node as a whole; the gcc
processes it starts run on that node. To spread the single files see
chapter 14.
9. Job control
It works as in bash, also for commands on other nodes.
In the background
[nex node-a /nex/data]$ on node-b ./lungo &
[1] 6478
[nex node-a /nex/data]$ jobs
[1]+ Running on node-b ./lungo &
[nex node-a /nex/data]$ wait
[nex node-a /nex/data]$
A command in the background does not read from the terminal, as in bash.
Suspending and resuming
[nex node-a /nex/data/p501]$ make conta
[nex: node-b]
^Z
[1]+ Stopped nex run -a -T --node any -- "$cmd" "$@"
[nex node-a /nex/data/p501]$ bg
[1]+ nex run -a -T --node any -- "$cmd" "$@" &
[nex node-a /nex/data/p501]$ fg
Ctrl-Z really stops the command on the remote node (not just the local
part); bg restarts it in the background, fg brings it back to the
foreground. The name shown by jobs for automatic commands is that of the
function that starts them; nxps shows the real command.
Terminating
kill %1 # SIGTERM to the remote command
kill -9 %1 # SIGKILL
kill -INT %% # like Ctrl-C on the current job
Ctrl-C on a foreground command interrupts it on the remote node (code 130). If you close the shell or the connection drops, the remote commands started from there are stopped, as with ssh.
Processes of other nodes and messages
nex kill node-b:4242 # SIGTERM to one of your processes on node-b
nex kill -STOP node-b:4242 # suspends; -CONT resumes it; -KILL kills it
nex wait node-b:4242 && echo fatto # waits for it to finish
nex msg mario "riunione fra 5 minuti" # to mario's terminals on all nodes
sudo nex wall "riavvio di node-b alle 18" # to everyone (root)
A user can signal only their own processes; nex msg respects mesg n.
The PIDs are shown by nxps and nxtop.
With the remote terminal
With on node-b vim file (remote terminal) Ctrl-Z is a key for the remote
program and does not suspend the job: quit the program normally.
Inside a cn session instead Ctrl-Z always works, because there is a real
shell on the node there.
10. Pipelines, redirections and files
Redirections are done by your shell, on the node where you are:
on node-b hostname > /tmp/x.txt # the file is in the /tmp of THIS node
on node-b ./calcolo > risultato.txt # in /nex: everyone sees it
echo "riga" | on node-b tr a-z A-Z # stdin from the local node: RIGA
on node-b sort < elenco.txt # elenco.txt read here, sorted on node-b
In a pipeline each piece runs where you say, and the data passes through the local node:
[nex node-a /nex/data]$ on node-a seq 1 100 | on node-b awk '{ s += $1 } END { print "somma su node-b:", s }'
somma su node-b: 5050
For large volumes it is better to have the files written and read in
/nex instead of passing the data through the pipeline:
on node-b ./genera > /nex/tmp/dati.bin # no: the data passes through here
on node-b sh -c './genera > /nex/tmp/dati.bin' # yes: writes directly to /nex
on node-a ./analizza /nex/tmp/dati.bin
Arguments reach the command exactly as you write them: $, %, *,
quotes and spaces are not reinterpreted by the system.
[nex node-a /nex/data]$ on node-b printf '[%s] ' '$$' '$HOME' '100%' '*.c'; echo
[$$] [$HOME] [100%] [*.c]
Expansions (*.c, $HOME, ~) are done by your shell before starting,
as always in bash: on node-b ls *.c expands *.c here, and in /nex the
files are the same. To expand them on the node use a shell over there:
on node-b sh -c 'echo $HOSTNAME'.
11. Environment variables
With on only TERM, LANG, LC_*, TZ and PATH are passed; the
others must be declared with --env:
[nex node-a /nex/data]$ export PROGETTO=alfa
[nex node-a /nex/data]$ on node-b sh -c 'echo "[$PROGETTO]"'
[]
[nex node-a /nex/data]$ on node-b --env PROGETTO=alfa sh -c 'echo "[$PROGETTO]"'
[alfa]
With cn instead all exported variables are passed (chapter 7).
HOME, USER, LOGNAME and SHELL on the node are those of your user on
that node.
12. CPU and memory limits
Every NEX command runs in its own resource group (systemd cgroup):
[nex node-a /nex/data]$ on node-b --cpu 50 sh -c 'cat /sys/fs/cgroup$(cut -d: -f3 /proc/self/cgroup)/cpu.max'
50000 100000
[nex node-a /nex/data]$ on node-b --mem 512M sh -c 'cat /sys/fs/cgroup$(cut -d: -f3 /proc/self/cgroup)/memory.max'
536870912
Beyond the memory limit the process is killed (code 137); swap does not count as a way out:
[nex node-a /nex/data]$ on node-b --mem 50M python3 -c 'b = bytearray(200 * 1024 * 1024)'; echo $?
137
Examples:
on any --cpu 100 --mem 4G ./simulazione # at most one CPU and 4 GB
on node-b --cpu 400 make -j4 # four CPUs
13. Interactive programs
If you are at a terminal, on gives the command a remote terminal:
on node-b vim note.txt
on node-b top
on node-b htop
on node-b less log/grande.log
on node-b bash # a shell on node-b (better: cn node-b)
Window size, colors, Ctrl-C and resizing work as locally. To force or
exclude the terminal: -t / -T.
Graphical programs
If you work at a screen (DISPLAY set), on and cn bring the windows of
remote programs to your screen, like ssh -X:
on node-b gimp foto.png # gimp computes on node-b, the window is here
cn node-b
xclock & # also in the cn session
- the window is on your screen, the program uses CPU and memory of the node;
- another user of the remote node cannot use your screen: it takes your job's cookie, and the real one never leaves your node;
- if the screen does not answer (old ssh session) the command starts anyway, without graphics;
NEXSH_X11=0turns forwarding off; fromnexdirectly:nex run -X.
On a Wayland desktop (WAYLAND_DISPLAY set) on and cn also bring the
windows of native Wayland programs, with waypipe:
- the
waypipepackage is needed on your node and on the one running the program; a node without waypipe runs the command anyway, without Wayland graphics; - on the remote node the program sees its own
WAYLAND_DISPLAYand a privateXDG_RUNTIME_DIR(/run/nex-wl/<uid>, yours only); - X11 and Wayland can coexist (mixed programs, XWayland);
NEXSH_WAYLAND=0turns forwarding off; fromnexdirectly:nex run -W(refuses if something is missing) ornex run --wayland-auto(without Wayland if it is missing).
Audio follows too: if your node has an audio server (PipeWire with
pipewire-pulse, or PulseAudio), on and cn make remote programs play
through your speakers and record from your microphone:
- on the remote node the program finds
PULSE_SERVERpointing to a private socket of its job (/run/nex-pa/<uid>, yours only) and each connection reaches, through the agent's channel, the audio server of your node; - it applies to programs that speak PulseAudio (almost all, ALSA too with the pulse plugin); those that use only native PipeWire are not covered for now;
- if your node has no audio server the command starts anyway, muted;
NEXSH_AUDIO=0turns forwarding off; fromnexdirectly:nex run -A(refuses if the audio server is missing) ornex run --audio-auto.
14. Scripts with nexsh
In scripts on and on any work as at the terminal; cn does not (it
needs an interactive shell): in scripts use on.
Compiling files in parallel on all nodes
#!/usr/bin/env nexsh
# compile each .c on the least loaded node, then link on this node
set -e
cd /nex/progetto/src
for f in *.c; do
on any -n gcc -O2 -c "$f" -o "${f%.c}.o" &
done
wait
command gcc -o ../programma *.o # command: this step stays here
echo "compilato con $(ls *.o | wc -l) oggetti"
Checking the errors of each job
The [nex: node] line of on any goes to stderr: in a script that saves
stderr to a file you remove it with NEXSH_ANNOUNCE=0, so that the .err
files contain only the program's errors.
#!/usr/bin/env nexsh
export NEXSH_ANNOUNCE=0
cd /nex/elaborazioni
pids=()
for f in input/*.dat; do
on any -n ./elabora "$f" > "output/$(basename "$f").out" 2> "output/$(basename "$f").err" &
pids+=($!)
done
falliti=0
for p in "${pids[@]}"; do
wait "$p" || falliti=$((falliti + 1))
done
echo "lavori falliti: $falliti"
exit $falliti
The same command on all compute nodes
#!/usr/bin/env nexsh
for n in $(nodes --json | python3 -c '
import json, sys
for n in json.load(sys.stdin)["nodes"]:
i = n.get("info", {})
if n["status"] == "ok" and i.get("compute") and i.get("mounted"):
print(n["node"])'); do
echo "== $n"; on "$n" uname -r
done
Periodic snapshot of the cluster
#!/usr/bin/env nexsh
# every 5 minutes, state of nodes, memory and space to a log file on /nex
while sleep 300; do
{ date; nodes; nxfree; nxdf; } >> /nex/log/cluster.log 2>&1
done
15. Exit codes
| Code | Meaning |
|---|---|
| the command's | the command ended normally (exit 3 → 3) |
| 128 + N | killed by signal N: 130 Ctrl-C, 143 SIGTERM, 137 SIGKILL or memory beyond --mem |
| 127 | command not found on the node |
| 126 | command not executable |
| 255 | NEX error (request refused, node unreachable) or job LOST |
| 2 | from on/cn: wrong usage or refusal; from nodes, nxfree, nxdf, nxtop -b: some node does not answer |
| 3 | from nxdf: the storage does not answer |
LOST means that the command's node stopped answering while the command was running: the outcome is unknown (not "succeeded", not "failed"). The message is
nex: job LOST: {"node":"node-b","reason":"connection to the node lost"}; unknown result
and it arrives within about 25 seconds of the node going down. Before repeating a LOST job check its output files: it may have got to the end.
16. Rules and security
- Never root. NEX commands do not run as root, neither with
onnor automatically.sudoremains a local command. - Only compute nodes with
/nexmounted. - Only directories in
/nexfor commands on other nodes. - Same user: on the node the command runs with your user and your groups; the user must exist on that node with the same uid.
- No credentials: no ssh keys or passwords are needed between nodes; the traffic between agents is encrypted and authenticated with the cluster certificates.
- No silent moves: every automatic choice of node is shown
(
[nex: node]).
17. Troubleshooting
| Message | Cause | Remedy |
|---|---|---|
directory X is not under /nex |
you are outside the shared filesystem | cd into /nex/... |
unknown node X (not in the agent.peers of ...) |
wrong name or node not configured | nodes for the list |
node X unreachable: ... |
node off, network, agent stopped | nodes; on the node systemctl status nexagentd |
node X does not have the compute role |
storage-only node | choose a compute node |
root may not use nex run |
you are root | use your own user |
the password changed with passwd "goes back" |
passwd changes one node only |
nex passwd (in nexsh passwd does it by itself) |
unknown user uid N on node X |
your user does not exist on that node | use a cluster user (nexctl users, see ops/README.md) |
no node available for --node any |
no compute node with /nex mounted |
nodes; nexctl join on the nodes |
job LOST |
the node went down during the job | chapter 15 |
cn: there are active jobs |
jobs running on the node | wait or kill %N |
cn: /nex/.nexsh is missing |
incomplete installation | sudo install -d -m 1777 /nex/.nexsh |
is nexagentd running? /run/nex/agent.sock |
agent stopped on this node | sudo systemctl start nexagentd |
the storage does not answer (nxdf) |
NEXFS does not answer (storage nodes unreachable) | nexfsctl health from an administration node |
a command on /nex stops for a few seconds, or fails with Connection timed out |
the storage does not answer: each call waits up to 8 s (the process shows state D in nxps), then returns the error |
short interruptions pass by themselves; if the error comes, nexfsctl health from an administration node, then run the command again |
18. Configuration
| File | Content |
|---|---|
/etc/nex/nexsh.conf |
remotable commands for everyone |
~/.nexsh.conf |
personal additions and removals |
~/.bashrc |
read by interactive nexsh as by bash |
/etc/nex/node.json |
node configuration (shared mount, peers); managed by the administrator |
/nex/.nexsh/ |
temporary files of cn (folder 1777) |
Format of nexsh.conf:
# comment
remote COMMAND... # go to the least loaded node
local COMMAND... # removed from the list
nexsh variables (read-only, except NEXSH_AUTO, NEXSH_ANNOUNCE, NEXSH_X11 and NEXSH_WAYLAND):
| Variable | Meaning |
|---|---|
NEXSH_VERSION |
version |
NEXSH_MOUNT |
shared filesystem (/nex) |
NEXSH_NODE |
node where this shell runs, with its name in the cluster (node in /etc/nex/node.json) |
NEXSH_HOME_NODE |
starting node, only in cn sessions |
NEXSH_AUTO |
1 automatic mode on, 0 off |
NEXSH_ANNOUNCE |
0 removes the [nex: node] line of on any and of automatic commands |
NEXSH_X11 |
0 does not forward graphics with on and cn |
NEXSH_WAYLAND |
0 does not forward Wayland with on and cn |
NEXSH_AUDIO |
0 does not forward audio with on and cn |
19. Quick reference
nexsh start the shell
nexsh -c 'commands' non-interactive commands
nexsh status current node, configuration
nodes node status
nxps nxtop nxfree nxdf processes, top, memory, cluster space
on NODE COMMAND run on NODE
on any COMMAND on the least loaded node
on NODE -n|-t|-T|--cpu P|--mem S|--env K=V COMMAND
cn NODE the shell continues on NODE
cn back to the starting node (exit, Ctrl-D)
cn - previous node
cn any least loaded node
nexsh auto on|off automatic remotable commands
command make this time locally
COMMAND & jobs fg bg wait kill %N Ctrl-Z Ctrl-C as in bash