Differences between revisions 1 and 2
Revision 1 as of 2022-06-09 15:39:46
Size: 2599
Editor: stroth
Comment:
Revision 2 as of 2022-06-09 15:40:15
Size: 2601
Editor: stroth
Comment:
Deletions are marked like this. Additions are marked like this.
Line 43: Line 43:
Server bound to <public ip of VS_HOST>:<random port> (IPv4) Server bound to <public ip of OVS_HOST>:<random port> (IPv4)
Line 46: Line 46:
Web UI available at http://<VS_HOST>:<random port>/?tkn=01234567-89ab-cdef-0123-456789abcdef Web UI available at http://<OVS_HOST>:<random port>/?tkn=01234567-89ab-cdef-0123-456789abcdef

Run Visual Studio Code as a service on a remote host

Two SEPP software packages of Visual Studio Code are available:

  • Code, started from the command line with code, the desktop application

  • OpenVSCode Server, started from the command line with openvscode-server, the web application

This article explains how to start openvscode-server as a service on a remote PC or cluster node and connect to it with a web browser.
A typical use case is to start it within a cluster job for debugging.

Example: Start openvscode-server in an interactive Slurm job

Within an interactive shell in a Slurm job, issue the following command:

OVS_HOST=$(hostname -f) && openvscode-server --host $OVS_HOST --accept-server-license-terms --telemetry-level off |sed "s/localhost/$OVS_HOST/g"

The output of openvscode-server will tell you the URL to access the web-based Code editor:

Server bound to <public ip of OVS_HOST>:<random port> (IPv4)
Extension host agent listening on <random port>

Web UI available at http://<OVS_HOST>:<random port>/?tkn=01234567-89ab-cdef-0123-456789abcdef

Example: Slurm job with openvscode-server

Adjust the following script snippet to your needs and insert it into your sbatch script:

# Set a logfile path in a variable
OVS_LOG=$HOME/openvscode-server.log

# Store the hostname in a variable
OVS_HOST=$(hostname -f)

# Define the command to start openvscode-server
OVS_COMMAND="openvscode-server --host ${OVS_HOST} --accept-server-license-terms --telemetry-level off |sed 's/localhost/$OVS_HOST/g'"

# Start a job step with openvscode-server with its own cpu core and put it into the background
srun --exclusive --ntasks=1 --cpus-per-task=1 "$OVS_COMMAND" >"$OVS_LOG" &

# Run some more code
python ...

OVS_LOG will contain the URL to access the web-based Code editor:

Server bound to <public ip of OVS_HOST>:<random port> (IPv4)
Extension host agent listening on <random port>

Web UI available at http://<OVS_HOST>:<random port>/?tkn=01234567-89ab-cdef-0123-456789abcdef

The token

The example token 01234567-89ab-cdef-0123-456789abcdef is saved in $HOME/.openvscode-server/data/token and will be re-used at future starts of openvscode-server.

FAQ/VS-Code_Server (last edited 2022-06-21 08:42:05 by stroth)