image-review serve¶
image-review serve [--work-dir DIR] [--socket-path PATH] [--via USER@LOGIN | --direct] [--ssh-host NODE]
Serves a work directory for browser review over SSH: plain HTTP on a Unix
socket, which a browser on your laptop reaches through ssh -L. There is
nothing to install on the laptop but ssh and a browser, and nothing to keep
in sync: the page is served by serve itself, so it always matches the
server’s version.
For the workflow, see the tutorial Browser review over SSH. The page it serves, with its keys and screens, is described in The browser page.
serve prints a URL that grants access: treat it like a password. When
stdout is not a terminal (e.g. sbatch), it is written to a private file
instead; see What serve prints.
Option |
Default |
Description |
|---|---|---|
|
|
Work directory containing preprocessed data; must exist |
|
|
The socket path |
|
|
The login node to put in the printed ssh command |
|
off; |
Your laptop can ssh to compute nodes without a jump host; the printed ssh command omits |
|
this machine’s FQDN |
The node name to put in the printed ssh command, for when the node’s own FQDN does not resolve from your laptop |
<host> in the default socket path is the short host name, without its
domain.
Token¶
Each start generates a new token. A token in $IMAGE_REVIEW_TOKEN is used
instead, so the URL survives restarts. It must be 22-256 characters from
A-Za-z0-9_-, with no surrounding whitespace (it is refused, not stripped). An invalid one stops
serve with an error that names the variable and the rule but never the
value. An empty value counts as unset.
Generate the token inside the job, in the srun shell or in the batch
script, never before sbatch or salloc. Never write the literal value on
a command line or into a batch script.
Browser review over SSH shows how.
Option rules¶
These are checked before the work directory is opened. Breaking one exits with status 2, before anything is created or logged:
--socket-pathmust not be empty.--direct, from the command line or$IMAGE_REVIEW_DIRECT, cannot be combined with--viaon the command line (”–direct and –via are mutually exclusive.”). With--direct, an$IMAGE_REVIEW_VIAin the environment is ignored.$IMAGE_REVIEW_DIRECTturns--directon with1,true,yes,on,tory, and leaves it off with0,false,no,off,f,nor an empty value (any case). Any other value is refused.--ssh-hosthas no environment variable.
A --socket-path on the command line overrides $IMAGE_REVIEW_SOCKET_PATH,
and an empty $IMAGE_REVIEW_SOCKET_PATH counts as unset, so the default path
is used.
Variable |
Meaning |
|---|---|
|
the socket path |
|
as |
|
as |
|
the token; see Token |
A --work-dir that does not exist also exits with status 2.
These exit with status 1 instead, and leave nothing behind. The first four are also checked before the work directory is opened:
a system without Unix sockets, such as Windows (“this system has no Unix sockets; browser review needs one”);
an invalid
--via(“Invalid –via: …”, or “Invalid $IMAGE_REVIEW_VIA: …” when it came from the environment): it must not be empty or start with-, and may contain only letters, digits and. _ @ % : [ ] / -;an invalid
--ssh-host(“Invalid –ssh-host: …”): a host name only, with nouser@; it must not be empty or start with-, and may contain only letters, digits and. _ : [ ] -;an invalid
$IMAGE_REVIEW_TOKEN(“Invalid $IMAGE_REVIEW_TOKEN: …”);a socket path that cannot be used: one with a
:or a control character, one too long for a Unix socket (107 bytes, 103 on macOS; the message suggests a shorter path such as/tmp/ir.sock), something there that is not a socket, or a socket owned by another user or with a live server behind it. A socket left by a dead server is removed;a
~/.image-reviewthat cannot be created or is not a directory you own, a URL file that cannot be written, or a bind that fails (“Cannot listen on socket …”);a work directory that another writer holds (see
review.lock).
What serve prints¶
The token appears only in the URL below; the server never logs it (see the
security model).
In the examples, TOKEN stands for the real value.
serve prints a notice, then the ssh command to run on your laptop. The
command holds no secret:
Serving review data over a Unix socket for browser review over SSH.
On your laptop, forward a local port to the socket (leave it running):
ssh -N -o ExitOnForwardFailure=yes -o ControlPath=none -J me@login-node -L 127.0.0.1:8080:/home/me/.image-review/serve-node042-12345.sock me@node042.cluster.example
If port 8080 is busy on your laptop, change it in -L and in the URL.
The command’s parts:
-Jis followed by--via. Without it,-Jgets your user name at a placeholder, such as'me@<login-node>': replace<login-node>. The user name is<user>too if it cannot be found. With--directthere is no-J.The
-Largument forwards127.0.0.1:8080on your laptop to the absolute path of the socket. It names 127.0.0.1 so ssh does not also bind::1.The destination is your user name on the node (
<user>if it cannot be found) at--ssh-host, or else the node’s FQDN.ExitOnForwardFailure=yesmakes ssh exit if the forward fails, andControlPath=nonestops a shared connection from keeping the forward alive after Ctrl-C.Each part is quoted for the shell only when it needs it.
When the token came from $IMAGE_REVIEW_TOKEN, the next line is:
Using the token from $IMAGE_REVIEW_TOKEN: the URL stays the same across restarts in this shell.
On a terminal, the URL follows:
Then open this URL. It contains an access token; treat it like a password.
http://127.0.0.1:8080/#TOKEN
Press Ctrl-C to stop.
When stdout is not a terminal, the URL is written to
~/.image-review/browser-<short-host>-<pid>.txt (mode 0600) instead, with
anything in <short-host> outside A-Za-z0-9._- replaced by _, and the
output says how to read it:
Stdout is not a terminal, so the URL (it contains an access token; treat it like a
password) was written to /home/me/.image-review/browser-node042-12345.txt (mode 0600) on this node.
Home directories are usually shared with the login node, so on your laptop read it with:
ssh me@login-node cat /home/me/.image-review/browser-node042-12345.txt
then open it in your browser once the ssh command above is running.
Press Ctrl-C to stop.
The ssh host is the same one as -J, so without --via it also has
<login-node> to replace. With --direct, the output says “On
your laptop, read it from the node with:” and the host is the node itself,
as in the forward command.
Another writer on the work directory¶
If review.tsv changes while this server runs, other than through the
server itself (another writer using the work directory despite its
review.lock, or the file
edited, replaced or deleted), the server refuses the next verdict or undo
without saving it, and every one after it: each gets an error reply (HTTP
500), and the server logs internal error: ReviewLogChanged. Verdicts
already saved are kept. Stop the other writer, then restart serve; it reads
the file afresh.
Stopping¶
Ctrl-C (SIGINT), SIGTERM and SIGHUP all stop the server. SIGTERM is what
Slurm sends on scancel and at the time limit; SIGHUP comes from a closed
terminal or a dropped ssh session. A signal that was already ignored when
serve started stays ignored, so under nohup a hangup does not stop it.
On the way out, serve removes the URL file, closes the socket (removing the
socket file) and releases the work
directory’s lock once any mark in progress has been saved.
Only the first signal counts. While serve cleans up, a further Ctrl-C or
SIGTERM does nothing, so it cannot cut the cleanup short and leave
review.lock behind; wait for the process to exit. kill -9 still stops it
at once, but then review.lock and the socket file stay behind.
A hard kill (SIGKILL, a node crash) skips all of this and leaves behind:
the URL file, which holds the token. It stays in
~/.image-reviewuntil you delete it or a later server writes a file of the same name;the socket file. A later server on the same path removes it;
review.lockin the work directory. It is not cleared automatically when the server ran on another node or before a reboot, so the nextrevieworserveexits 1 saying the work directory is in use. Seereview.lockfor when to delete it by hand.