7.3.2 : With a job submission
The limitation of the previous method is that you have to keep your terminal open to keep the code server running (and your laptop running). To avoid this, you can submit a job to the cluster to run the code server.To do so, you have to create a script like the following one:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#!/bin/bash #SBATCH --job-name=code_server #SBATCH --output=code_server-%J.out #SBATCH --error=code_server-%J.err #SBATCH --time=3:00:00 #SBATCH --ntasks=1 #SBATCH --cpus-per-task=10 #SBATCH --partition=skylake #SBATCH --mem=10GB #SBATCH --reservation=grayscottcpu # print the hostname of the node hostname # Start the jupyter notebook in your working directory cd ~/where/you/want/to/run # before to pull the image before and create the build directory to not have to do it at each job submission apptainer run --bind build:/build --writable-tmpfs introduction_cpp_algorithms_alpine_micromamba_code_server_latest.sif micromamba run code-server |
Then you can submit the job to the cluster with the following command:
1 2 |
> chmod +x code_server.sh > sbatch code_server.sh |
Once the job is submitted, you can check the status of the job with the following command:
1 |
> squeue -u <username> |
To set up the port forwarding, you can use the same method as explained in the previous section. You can check the output of the job to get the hostname of the node where the code server is running.
Then you can forward the port with the following command:
1 |
$ ssh <hostname> -N |
Now you can enjoy the code server on your laptop at the following url: http://localhost:
The code server job will end after the time specified in the script (3 hours in the example).
To end the code server before the time limit, you can use the following command:
1 |
> scancel <job_id> |
You can find the job id with the squeue command or simply check the file jupyter-.out.