Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I release ports which are being held by a notebook server after it has been stopped?

I'm starting up a jupyter notebook server on an AWS instance (Redhat Linux server) to connect to over https. In the config file I have that this should be on port 9999. However when I stop and restart the process with Ctrl-C, the port is not being released, as shown below.

[user@ip-xxx-xx-xx-xxx notebook]$ [I 08:39:27.901 NotebookApp] The port 9999 is already in use, trying another random port.
[I 08:39:27.901 NotebookApp] The port 10000 is already in use, trying another random port.
[I 08:39:27.902 NotebookApp] The port 10001 is already in use, trying another random port.
[I 08:39:27.905 NotebookApp] Serving notebooks from local directory: /home/user/docs/notebook
[I 08:39:27.905 NotebookApp] 0 active kernels
[I 08:39:27.905 NotebookApp] The Jupyter Notebook is running at: https://[all ip addresses on your system]:10002/
[I 08:39:27.905 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

As an aside, those "random ports" don't look very random to me.

like image 990
Jamie Bull Avatar asked Jan 27 '16 08:01

Jamie Bull


People also ask

How do you exit a notebook terminal in Jupyter?

NOTE: You can also shutdown a Jupyter Notebook session by clicking in the Terminal window and clicking Ctrl+c . You will be asked to confirm that you want to Shutdown this notebook server (y/[n])? . Type y and hit Enter to confirm. Then, you can close the Terminal by typing the command exit and hitting Enter .

What ports does Jupyter notebook use?

When launching a jupyter notebook server, it will typically be run on port 8888 . We can forward this port on the remote machine to a port on our local machine. In this case, we will use port 8000 of our local machine.

Why is port 8888 already in use?

A 'port' is basically an address on your computer. By default, Jupyter uses port 8888 to let you talk to it (you can see this in the URL when you're looking at a notebook: localhost:8888 ). If you're already running a server, it will try 8889 , then 8890 , then 8891 and so on, until it finds an opening.


1 Answers

sometimes the stop command of a service doesn't return any error and deletes the pid file of a process, but does actually not terminate the process itself.

you can check if the process is still running by running the stop command and then either

ps aux | grep -i notebook

or

netstat -tlnp | grep <portNumber>

As you stated you can then either kill the process manually, or fix the stop script (usually /etc/init.d/serviceName+d). The reason for the process to not be killed is often (not always) linked to permissions owned by the user executing the command

like image 68
Tom Avatar answered Sep 22 '22 02:09

Tom