# Cannot start jupyterhub server when i login

**URL:** <https://discourse.jupyter.org/t/cannot-start-jupyterhub-server-when-i-login/30520>\
**Category:** JupyterHub\
**Created:** [November 29, 2024, 9:47am UTC](https://discourse.jupyter.org/t/cannot-start-jupyterhub-server-when-i-login/30520 "2024-11-29T09:47:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mrunal\_Chipre](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/mrunal_chipre/32/16102_2.png) [@Mrunal\_Chipre](https://discourse.jupyter.org/u/Mrunal_Chipre)\
**Post date:** [November 29, 2024, 9:47am UTC](https://discourse.jupyter.org/t/cannot-start-jupyterhub-server-when-i-login/30520/1 "2024-11-29T09:47:42Z")

</div>

I was able to login but after login i get 500 server error, the server is not starting automatically.

please refer below spawner class  
Note: this is public accessible not restricted for system users

class CustomSpawner(LocalProcessSpawner):  
def get\_env(self):

# Get the environment from the parent class

env = super().get\_env()

```auto
    # Define base notebook directory and user notebook directory
    base_notebook_dir = #my notebook directory path 
    username = self.user.name
    user_notebook_dir = os.path.join(base_notebook_dir, username)

    # Ensure user's directory exists or create it
    if not os.path.exists(user_notebook_dir):
        os.makedirs(user_notebook_dir)

        # Copy files from the admin's directory to the user's directory
        admin_notebook_dir = os.path.join(base_notebook_dir, 'testuser') # Update with admin user name
        if os.path.exists(admin_notebook_dir):
            for item in os.listdir(admin_notebook_dir):
                s = os.path.join(admin_notebook_dir, item)
                d = os.path.join(user_notebook_dir, item)
                if os.path.isfile(s):
                    shutil.copy2(s, d)
                elif os.path.isdir(s):
                    shutil.copytree(s, d)

    # Set environment variables for each user manually (without relying on system users)
    env['HOME'] = user_notebook_dir
    env['USER'] = username
    env['LOGNAME'] = username
    env['PWD'] = user_notebook_dir

    return env

def start(self):
    # Ensure that the user's directory is set up correctly before starting
    self.notebook_dir = os.path.join('/Notebooks', self.user.name)
    if not os.path.exists(self.notebook_dir):
        os.makedirs(self.notebook_dir)

    # Automatically start the server without waiting for explicit action
    self.ready = True # Mark the server as ready immediately
    self._spawned = True # Indicate that the server is spawned

    # Call the parent class start method
    return super().start()

```

# Spawner configuration

c.JupyterHub.spawner\_class = CustomSpawner  
c.Spawner.notebook\_dir = ‘/Notebooks’ # Path for user notebooks  
c.Spawner.default\_url = ‘/lab’ # Launch JupyterLab interface by default
