Spawn fails - permissions error with SystemdSpawner

I am trying to launch JupyterHub on CentOS 7 using SystemdSpawner and FirstUseAuthenticator. After I launch JupyterHub (whether in the command line or as a service), I can log into the JupyterHub page, but then I see “Spawn failed”. When the spawn fails, the following error appears in the command line:

ERROR:asyncio:Task exception was never retrieved
future: <Task finished coro=<BaseHandler.spawn_single_user() done, defined at /data/programs/miniconda3/envs/huracan_deps/lib/python3.7/site-packages/jupyterhub/handlers/base.py:697> exception=PermissionError(13, 'Permission denied')>
Traceback (most recent call last):
  File "/data/programs/miniconda3/envs/huracan_deps/lib/python3.7/site-packages/jupyterhub/handlers/base.py", line 889, in spawn_single_user
    timedelta(seconds=self.slow_spawn_timeout), finish_spawn_future
  File "/data/programs/miniconda3/envs/huracan_deps/lib/python3.7/site-packages/jupyterhub/handlers/base.py", line 807, in finish_user_spawn
    await spawn_future
  File "/data/programs/miniconda3/envs/huracan_deps/lib/python3.7/site-packages/jupyterhub/user.py", line 642, in spawn
    raise e
  File "/data/programs/miniconda3/envs/huracan_deps/lib/python3.7/site-packages/jupyterhub/user.py", line 546, in spawn
    url = await gen.with_timeout(timedelta(seconds=spawner.start_timeout), f)
  File "/data/programs/miniconda3/envs/huracan_deps/lib/python3.7/site-packages/systemdspawner/systemdspawner.py", line 302, in start
    slice=self.slice,
  File "/data/programs/miniconda3/envs/huracan_deps/lib/python3.7/site-packages/systemdspawner/systemd.py", line 113, in start_transient_service
    runtime_dir, unit_name, environment_variables
  File "/data/programs/miniconda3/envs/huracan_deps/lib/python3.7/site-packages/systemdspawner/systemd.py", line 50, in make_environment_file
    ensure_environment_directory(environment_file_directory)
  File "/data/programs/miniconda3/envs/huracan_deps/lib/python3.7/site-packages/systemdspawner/systemd.py", line 22, in ensure_environment_directory
    os.makedirs(environment_file_directory, mode=0o700, exist_ok=True)
  File "/data/programs/miniconda3/envs/huracan_deps/lib/python3.7/os.py", line 221, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/run/jupyter-huracan-jamapp-singleuser'

It looks like there is a PermissionError in /run/jupyter-huracan-jamapp-singleuser. That folder doesn’t exist. I tried creating the directory manually. When I do so, and I re-launch JupyterHub, I see the following error after logging in:

ERROR:asyncio:Task exception was never retrieved
future: <Task finished coro=<BaseHandler.spawn_single_user() done, defined at /data/programs/miniconda3/envs/huracan_deps/lib/python3.7/site-packages/jupyterhub/handlers/base.py:697> exception=PermissionError(1, 'Operation not permitted')>
Traceback (most recent call last):
  File "/data/programs/miniconda3/envs/huracan_deps/lib/python3.7/site-packages/jupyterhub/handlers/base.py", line 889, in spawn_single_user
    timedelta(seconds=self.slow_spawn_timeout), finish_spawn_future
  File "/data/programs/miniconda3/envs/huracan_deps/lib/python3.7/site-packages/jupyterhub/handlers/base.py", line 807, in finish_user_spawn
    await spawn_future
  File "/data/programs/miniconda3/envs/huracan_deps/lib/python3.7/site-packages/jupyterhub/user.py", line 642, in spawn
    raise e
  File "/data/programs/miniconda3/envs/huracan_deps/lib/python3.7/site-packages/jupyterhub/user.py", line 546, in spawn
    url = await gen.with_timeout(timedelta(seconds=spawner.start_timeout), f)
  File "/data/programs/miniconda3/envs/huracan_deps/lib/python3.7/site-packages/systemdspawner/systemdspawner.py", line 302, in start
    slice=self.slice,
  File "/data/programs/miniconda3/envs/huracan_deps/lib/python3.7/site-packages/systemdspawner/systemd.py", line 113, in start_transient_service
    runtime_dir, unit_name, environment_variables
  File "/data/programs/miniconda3/envs/huracan_deps/lib/python3.7/site-packages/systemdspawner/systemd.py", line 50, in make_environment_file
    ensure_environment_directory(environment_file_directory)
  File "/data/programs/miniconda3/envs/huracan_deps/lib/python3.7/site-packages/systemdspawner/systemd.py", line 30, in ensure_environment_directory
    os.chmod(environment_file_directory, 0o700)
PermissionError: [Errno 1] Operation not permitted: '/run/jupyter-huracan-jamapp-singleuser'

I’m launching JupyterHub as an admin user, “admjamapp”, and logging in as a local user: “huracan-jamapp”.

Does anyone have suggestions on how to fix the errors above?

Update: I switched to SudoSpawner and got it to work.