MIKE LEVIN LPVG SEO

Future-proof your tech-skills with Linux, Python, vim & git as I share with you the most timeless and love-worthy tools in tech — and on staying valuable while machines learn... and beyond.

Created Windows Shortcut To Start Linux Jupyter on LXD

by Mike Levin

Tuesday, September 20, 2022

Okay, I added LXD.lnk to the WSL2LXD repo. It’s very simple:

wt PowerShell -c "wsl -d Ubuntu-18.04"

This works because when the Ubuntu 18.04 .bash_login script is:

jupyterlogin

And this is a program in /usr/local/sbin on WSL:

until
        lxc jupyterstart 2>/dev/null
do
        sleep 1
done
lxc exec jupyter -- su --login ubuntu

And now this is actually using the alias feature of lxc which you can see when logged into just WSL with lxc alias list. Anyway, jupyerstart is an alias for:

exec jupyter -- su --login ubuntu -c /usr/local/sbin/jupyterstart

And now there’s one more /usr/local/sbin file in the picture, but this one is under LXD and just starts the Jupyter server:

cd ~/repos
screen -wipe >/dev/null 2>&1
if ! screen -list | grep -q "jupyter"; then
    screen -dmS jupyter /home/ubuntu/py310/bin/jupyter lab --ip 0.0.0.0 --port 8888 --no-browser --ServerApp.password='[long hash deleted]'
fi
echo "Visit http://localhost:8888"

Pshwew! There’s a lot of getting around API limitations going on here by use of sbin commands. There’s a temptation to make bash script one-liners and feed them on the command-line parameters of wsl and lxd, but that generally doesn’t work. If it’s not permission problems then it’s semicolon parsing. It turns out that dropping magic little sbin commands into place and calling them on the command-line seems to always work.