jupyter – JupyterHub populate user home with notebooks (and data)

I have a JupyterHub server hosted on an Ubuntu machine.

(Mainly) since I want to avoid adding hundreds of potential users to the machine I opted to use c.JupyterHub.authenticator_class="jupyterhub.auth.DummyAuthenticator" (with a password)

The Spawner I use is
c.JupyterHub.spawner_class="jupyterhub.spawner.SimpleLocalProcessSpawner" although I also tried 'jupyterhub.spawner.LocalProcessSpawner'.

I want users to have some pre-populated notebooks once they log in.

I first tried tljh.jupyter.org/en/latest/howto/content/share-data.html putting the data in /etc/skel put it wasn’t copied.

Then, according to various docs I could set c.Spawner.pre_spawn_hook = populate_user_home (tried also c.SimpleLocalProcessSpawner.pre_spawn_hook = populate_user_home) and have that method copy the files I want over to the user’s home.

The method I have looks something like:

def populate_user_home(spawner):
    username = spawner.user.name
    # DummyAuthenticator creates users in /tmp
    volume_path = os.path.join('/tmp', username)
    if not os.path.exists(volume_path):
        os.mkdir(volume_path, 0o777)
        copyDirectory(<path_to_tutorials>, os.path.join(volume_path, 'tutorials'))

Problem is that this method is never called!

  1. What am I doing wrong?
  2. Is there another (simpler?) way to populate the home of new users?

Read more here: Source link