Skip to content
shrijan-swaminathan edited this page Jul 18, 2023 · 29 revisions

WSL

Prerequisites

In Windows Features, enable Virtual Machine Platform and Windows Subsystem for Linux

Installation

https://learn.microsoft.com/en-us/windows/wsl/install
When installing distributions, install a Red Hat distro (distribution), such as Rocky, Alma, or CentOS from Windows Store.

Basic Commands

Use the command wsl to get into your default distro
To get into wsl on a nondefault distro, use the command wsl -d <Distro>, where Distro is distribution name
To find a list of all wsl distros installed on machine, use the command wsl -l

Setup

First make sure you are connected in some way to the Fermilab network, either by having a direct connection at the lab, or by using a VPN.
https://authentication.fnal.gov/krb5conf/ Enter wsl using the wsl command from your terminal, or by typing wsl into the search bar
Installing Kerberos is very similar to installing on any other Linux machine:

wget https://linux-mirrors.fnal.gov/linux/fermilab/centos/9/yum-conf-fermilab.rpm
sudo dnf install krb5-workstation
sudo dnf install yum-conf-fermilab.rpm

VSCode

Install VSCode on your machine using the Microsoft Store (or website)
https://code.visualstudio.com/download

Extensions

To add extensions, just go to the tab with the 4 boxes and search them in the search box.

  • WSL
    • Connects the wsl machine within VScode itself
  • Dev Containers
    • Connects the containerized environment at the end of the setup
  • Docker
    • Connects to running containers such that VSCode can detect the running containers
  • Python
    • To write code in Python with VSCode text editor
  • Remote - SSH
    • Manage the ssh connections to VMs
  • Remote - SSH: Editing Configuration Files
    • Edit the configuration files for ssh
  • Remote Explorer
    • Access the file system of remote VMs with VSCode

Setup

Make sure to make the default distribution as your Alma9/CentOS distribution. You can list all current distributions installed with the command wsl -l. The current default distribution will be written in parentheses after the distribution name in the list. After, to change the default distribution, copy the distribution name that you want to make default and type the command wsl --setdefault <DISTRO NAME>.

Note: This is a workaround due to the different file formats of both Windows file systems and Linux file systems. After extensions have been added, we’ll need to make a ssh.bat file to help convert the correct configurations from Windows to Linux. Choose a secure place in your files, and make a new text file. Paste the below code into the file, and then rename the txt file to exactly ssh.bat

@echo off
set v_params=%*
set v_params=%v_params:\=/%
set v_params=%v_params:c:=/mnt/c%
set v_params=%v_params:"=\"%
for /f "delims=" %%a in ('powershell -Command "& {'%v_params%' -replace '\/\/wsl\.localhost\/[^\/]*',''}"') do set "v_params=%%a"
C:\Windows\system32\wsl.exe ssh %v_params%

The ssh.bat file essentially converts the Windows file system into Linux file system so that we can run through the wsl configuration in ~/.ssh/config

After the file is created, copy the path of the file (easiest by moving to the folder location of the file in File Explorer, and then double clicking the path at the top and copying it).
With your path copied, navigate to the settings (Ctrl + ,) in VSCode and search for remote ssh path - we are explicitly looking for the path to SSH executable, not the Config file. Paste the file path in the prompt, and make sure your path ends in ssh.bat

Next we’ll be setting up the config file - in your wsl terminal, in the home directory, do the following to create the proper place for your ssh config file: (you can use any text editor other than vi)

mkdir .ssh
vi .ssh/config

Copy and paste the following into your config file and save (NOTE: Instead of the pound symbol, use the 3 digit id for the fermicloud machine. If you don't know how to get those 3 digits, but know the IP of the machine, go to a terminal and type host $IP, where $IP is the ip address):

GSSAPIAuthentication yes
GSSAPIDelegateCredentials yes

Host fermicloud###.fnal.gov
  HostName fermicloud###.fnal.gov
  User root

If you’ve used ssh before, you’ll already have the .ssh directory and should also have a known_hosts file, which will contain all known hosts as you use them. Now after the config has been created, in your Windows File Explorer, navigate to where the config file is stored through the Linux VM. (it should look something like this \wsl.localhost\AlmaLinux9\home[YOUR_USER].ssh\config)

Copy this path, and then go back to VSCode settings and search up remote ssh path. Here we will paste the path to the Config file, making sure the path ends in \config.

After the installation of the previous extensions, click the Remote Explorer Tab (the monitor with two intersecting lines on the bottom right). In Remote Explorer, you can access your hosts and containers by selecting “Remote” for hosts and “Dev Containers” for containers. If you wish to connect to FermiCloud, click the “+” icon next to SSH to connect a new remote, which will prompt a connection. If not, click the two intersecting arrows on the bottom left of VS Code and select "Connect to Host". Choose the machine you desire to connect to and make sure it connects. If it doesnt connect due to a "Permission denied" error, make sure to check if you are connected via Fermilab's network and that a kinit was done in Kerberos authentication.

To check if you are connected to the VM, the name of the VM should show up in the blue >< symbol (intersecting lines) on the bottom left of the window.
Once connected, you can now setup the factory and frontend configurations. NOTE: The dev setup process may change

git clone https://github.com/GlideinWMS/glideinwms.git # make sure to copy the path of this directory after running this command
git clone -b dev-containers https://github.com/BrunoCoimbra/gwms-containers.git
cd gwms-containers/workspaces #essentially cd into where you cloned the gwms-containers. If you ls, there should be a yml file here
git pull
GWMS_PATH=/root/GlideinWMS/glideinwms podman-compose up -d
cd

This creates and runs both the containers. To check whether they are running, use the command podman container ls -a and it will show the state of the containers.

Compute Engine setup

bash startup.sh

To check if everything is working, type the command condor_status -any -wide. Make sure that there is 3 tokens in the condor_status To check the status of the 3 services, type the command systemctl status httpd condor gwms-factory (it should say active for each service)

Factory setup

Next, enter your newly created factory workspace interactively with the command podman exec -it factory-workspace /bin/bash

bash startup.sh

To check if everything is working, type the command condor_status -any -wide. Make sure that there is 3 tokens in the condor_status To check the status of the 3 services, type the command systemctl status httpd condor gwms-factory (it should say active for each service)

Frontend setup

Next, enter your newly created frontend workspace interactively with the command podman exec -it frontend-workspace /bin/bash

bash startup.sh

To check if everything is working, type the command condor_status -any -wide. Make sure that there is 3 tokens in the condor_status To check the status of the 3 services, type the command systemctl status httpd condor gwms-frontend (it should say active for each service) The ce_workspace token should show up in around 5-10 minutes after running startup scripts

You have to update tokens every few hours to make sure that this runs properly. Do so with the following:

TOKEN_DIR=/var/lib/gwms-frontend/.condor/tokens.d
htgettoken --minsecs=3580 -i fermilab -v -a htvaultprod.fnal.gov -o "$TOKEN_DIR"/"$HOSTNAME".scitoken
chown frontend:frontend "$TOKEN_DIR"/*frontend*
ls -lah $TOKEN_DIR

Dev Containers

To make use of dev containers within VSCode, install podman-docker with the command dnf install podman-docker.
Next, restart VSCode. Once that is done, connect to the VM again and, under Remote Explorer, click the Dev containers drop down. The two created containers should show up. You can now connect to them as you would with other VMs

Clone this wiki locally