Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 18 Next »

We strongly recommend using the VS Code application on the O2 Portal. For more information, please visit O2Portal - Visual Studio Code AppandO2Portal

This page shows you how to install and run VS Code using your local browser. Let us know if you have any questions.

Connect to O2

Please review the How to Login to O2 and the Using Slurm Basic wiki pages for more details. If using a Windows computer, we recommend to download/install https://mobaxterm.mobatek.net/and open a new terminal. If using a Mac computer, you can open the ‘Terminal’ app and use the ssh command as follow:

# Select a port between 50000 to 60000 for yourself using the command 'netstat' in a local terminal. Select a port that says 'listening' or 'established'.
export PORT=51234 
export CLUSTER_USER=YourHMSID 
ssh -L $PORT:127.0.0.1:$PORT $CLUSTER_USER@o2.hms.harvard.edu

Newer versions of code-server aren't compatible with CentOS 7. Therefore, a container is necessary to circumvent the compatibility issue.

Run the latest (v4.20.0) of code-server using a container

# Export the port number
export PORT=51234 

# Launch an interactive job (resources: 2 hours and 3 GiB of RAM) 
srun --pty -p priority -t 0-2 --mem=3G --tunnel $PORT:$PORT bash

# Start code-server using the singularity container
singularity exec /n/app/singularity/containers/code-server-v4.20.0.sif /app/code-server/bin/code-server

# In theory, you should see something similar to:
singularity exec /n/app/singularity/containers/code-server-v4.20.0.sif /app/code-server/bin/code-server
[2024-01-11T17:15:54.233Z] info  code-server 4.20.0 
[2024-01-11T17:15:54.237Z] info  Using user-data-dir /home/<HMS_ID>/.local/share/code-server
[2024-01-11T17:15:54.264Z] info  Using config file /home/<HMS_ID/.config/code-server/config.yaml
[2024-01-11T17:15:54.265Z] info  HTTP server listening on http://127.0.0.1:50003/
[2024-01-11T17:15:54.265Z] info    - Authentication is enabled
[2024-01-11T17:15:54.266Z] info      - Using password from /home/<HMS_ID>/.config/code-server/config.yaml
[2024-01-11T17:15:54.266Z] info    - Not serving HTTPS
[2024-01-11T17:15:54.267Z] info  Session server listening on /home/<HMS_ID/.local/share/code-server/code-server-ipc.sock

# To see the password on /home/<HMS_ID>/.config/code-server/config.yaml
# You'll need to open a new terminal, connect to O2, and paste the following command:
cat ~/.config/code-server/config.yaml

Install and test an old version of VS code-server locally

export PORT=51234 
srun --pty -p priority -t 8:0:0 --tunnel $PORT:$PORT bash 

mkdir -p ~/.local/lib ~/.local/bin
curl -fL https://github.com/cdr/code-server/releases/download/v4.7.0/code-server-4.7.0-linux-amd64.tar.gz | tar -C ~/.local/lib -xz
mv ~/.local/lib/code-server-4.7.0-linux-amd64 ~/.local/lib/code-server-4.7.0

# Start code server
~/.local/lib/code-server-4.7.0/bin/code-server 

# You should see output: 
$ [2021-10-05T13:58:56.961Z] info  code-server 4.7.0 4cd55f94c0a72f05c18cea070e10b969996614d2
[2021-10-05T13:58:56.962Z] info  Using user-data-dir ~/.local/share/code-server
[2021-10-05T13:58:56.995Z] info  Using config file ~/.config/code-server/config.yaml
[2021-10-05T13:58:56.995Z] info  HTTP server listening on http://127.0.0.1:51234
[2021-10-05T13:58:56.995Z] info    - Authentication is enabled
[2021-10-05T13:58:56.995Z] info      - Using password from ~/.config/code-server/config.yaml
[2021-10-05T13:58:56.995Z] info    - Not serving HTTPS

# Command + click the "http://127.0.0.1:51234" to open the link
# Then copy and paste the password to browser
cat ~/.config/code-server/config.yaml

Directly login, run interactive job and start VS Code Server from local machine

# Set DUO default to push if you didn’t do it yet. 
# Run this command on O2:  
echo export DUO_PASSCODE=push >> $HOME/.bashrc

# On your local machine
# set up alias. You could add this row to your ~/.bash_profile
alias vscode='PORT=51234; CLUSTER_USER=YourHMSID; ssh -L $PORT:127.0.0.1:$PORT $CLUSTER_USER@o2.hms.harvard.edu -t "hostname; echo port is: $PORT; kill -9 $(/usr/sbin/lsof -t -i:$PORT) 2>/dev/null; srun --pty -p priority -t 8:0:0 --tunnel $PORT:$PORT bash -c \"hostname; echo port is: $PORT; kill -9 $(/usr/sbin/lsof -t -i:$PORT) 2>/dev/null; export PORT=$PORT; ~/.local/lib/code-server-4.7.0/bin/code-server & bash;\""'

# login to O2, start interative job and run vs code server
vscode

You don’t have to use 51234 for PORT and you can pick any number in the 50K for the PORT value

port 51234 is in use or unavailable"? Make sure you close the VS Code editor page within your browser

# If you see this error: 
channel 3: open failed: connect failed: Connection refused
channel 3: open failed: connect failed: Connection refused
login03.o2.rc.hms.harvard.edu
port is: 51234
port 51234 is in use or unavailable
Connection to o2.hms.harvard.edu closed.

Make sure you close the VS Code editor page with your browser




Please contact us if you have any questions/comments.

  • No labels