UBC-DSCI / jupyterhub-infrastructure

0 stars 0 forks source link

persistent storage #10

Open ttimbers opened 4 years ago

ttimbers commented 4 years ago
def create_fs_hook(spawner):
      username = spawner.user.name
      callysto_user = 'jupyter'
      course = 'dsci100'
      check_call(['/srv/jupyterhub/zfs_homedir.sh', course, username, callysto_user])

c.Spawner.pre_spawn_hook = create_fs_hook

And uncomment this line:

# c.DockerSpawner.volumes = {'/tank/home/dsci100/{username}': '/home/jupyter'}

Put this script in /srv/jupyterhuband name it zfs_homedir.sh

#!/usr/bin/env bash

set -e
set -u
set -o pipefail

ZFSHOME="tank/home"
ZFSOPTS="-o refquota=1G"

sys_user_exists() {
    local username="$1"
    ret=false
    getent passwd ${username} > /dev/null 2>&1 && ret=true
    if ! ${ret}; then
        echo "username \"${username}\" does not correspond to a system user!" >&2
        echo >&2
        exit 1
    fi
}

main() {
    local username

    local zfshome="tank/home"

    # Accept three and only three arguments
    if [[ -z "${1:-}" || -z "${2:-}" || -z "${3:-}" ]]; then
        echo "Usage ${0} <COURSENAME> <USERNAME> <OWNER>" >&2
        echo >&2
        exit 1
    elif [[ ${1} =~ ^[a-z0-9][_-a-z0-9.]*$ || ${1} =~ ^[a-z0-9][-a-z0-9.]*$ ]]; then
        coursename=${1}
        username=${2}
    owner=${3}
    else
        echo "Coursename \"${1}\" must match schema ^[a-z0-9][_-a-z0-9.]*\$" >&2
        echo "Username \"${2}\" must match schema ^[a-z0-9][-a-z0-9.]*\$" >&2
        echo >&2
        exit 1
    fi
    sys_user_exists $owner

    local homefs="${zfshome}/${coursename}/${username}"
    local homedir="/$homefs"
    if [[ -d "${homedir}" ]] ; then
        echo "Homedir already exists, not recreating"
    else
        echo "Creating Homedir: ${homedir}"
        zfs create ${ZFSOPTS} ${homefs}
        chown -R ${owner}:${owner} ${homedir}
    chmod g+w ${homedir}
    fi
}

main "${@:-}"
ttimbers commented 4 years ago

Note - make sure all Docker containers are stopped and removed when testing for persistent storage... Test this via sudo docker ps -a

Stop docker containers:

sudo docker stop <CONTAINER_ID>

Delete docker containers:

sudo docker rm <CONTAINER_ID>
ttimbers commented 4 years ago

Note - anytime you edit the jupyterhub_config.py file you will need to restart the hub for the changes to take effect, do this via:

sudo systemctl restart jupyterhub
hsmohammed commented 4 years ago

I am done setting up persistent storage on the student server

ttimbers commented 4 years ago

Did you just do what I wrote above, or some variation on that?

hsmohammed commented 4 years ago

I did the steps you provided. I didn't do a variation on that.

ttimbers commented 4 years ago

Great, good to know! Thanks!

On Wed, Jul 8, 2020 at 7:32 AM Hossameldin Mohammed < notifications@github.com> wrote:

I did the steps you provided. I didn't do a variation on that.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/UBC-DSCI/rudaux/issues/47#issuecomment-655557263, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUMA6HSGVS35DFPCTANUT3R2R7ODANCNFSM4OP6EODA .

-- Tiffany A. Timbers

Vancouver, BC 604-803-4962

ttimbers commented 4 years ago

It doesn't seem to be working for me @hsmohammed - I get this error when I try to access the hub via Canvas:

Screen Shot 2020-07-08 at 8 51 01 AM

How did you test that it was working?

trevorcampbell commented 3 years ago

Related to jhub infra. Transferring.