This might be a peculiar case where we need to start the jupyter notebook for all system users on a common machine. All users have their own conda envs (installed in their home) which has same name base. However, for simplicity, we would like to start jupyter notebook after restart using a script for all users.
Present case, works for 2-3 users.
Ask user to execute from their bash session
tmux
conda activate base
jupyter notebook --ip a.b.c.d -- port pqrs
followed by Ctrl+b, d to close the tmux session.
New case (larger number of users)
Script run by root which starts the jupyter server for each user on a specific port.
For this we have prepared a bash script which starts the notebook on an empty port for the current user.
#!/bin/bash
source ~/.bashrc
eval "$(conda shell.bash hook)"
conda activate base
current_env=$CONDA_DEFAULT_ENV
echo -e "\t ----------\n\t Current conda environment : " $current_env
################################################
# get an empty port number between a range
used=$(ss -tulpn | grep -e9{700..800} | awk '{print $5}' | grep -o -E '[^:]+$' | xargs)
#echo -e "\t\t Currently used ports : $used"
# function to generate random number within a range
rnd() {
out=$(shuf -i 9700-9800 -n 1)
echo $out
}
val=$(rnd)
# this loop breaks when val is not found in string
while grep -q "$val" <<<"$string"; do
#echo "port being used"
val=$(rnd)
done
#echo "$val"
port=$val
################################################
jupyter notebook --ip a.b.c.d --port "$port" # start on specific port
################################################
status=$(ss -tulpn | grep "jupyter" | grep "$port")
echo -e "\t\t $status \n\n"
Permission : users can read files from other user. Execution not allowed (even for root) in other users home.
Question : how to automate this as a root user so that all servers (for users) are started upon system restart.
- One way might be use
nohupwith the command instead of usingtmux, and iterate over all users in a loop. Any ideas.
Not using other approach like jupyterhub since it requires Ubuntu and configuring PAM authentication is non-trivial.
Thanks.