I am trying to run server3.py, but whenever I try to do this, I am not able to because I keep getting an error that the server is already in use. So naturally, I tried to find if any other process is using that port and then killing it. However, either I am doing that wrong, or there is some hidden process because no other process is using python.
I am new to servers and local hosts, so any help would be appreciated.
Try using netstat -vanp tcp | grep 8000 (mac)
or
netstat -tulpn | grep 8000 (linux)
or
netstat -abno | findstr :8000 (windows)
I am presuming you are using flask kind of framework, In any server instance only one port will be listening, in your case port is already been used by other service
Change the port number and try
If really want to check which port is listening use "netstat commond"
In Linux:
netstat -tulnp
In windows:
netstat -abno
In Mac:
netstat -pant | grep LISTEN
if output is too lengthy you can grep with port number
Related
I cannot seem to figure out why I cannot access my local django webserver from an outside device. I suspect it has to do with port forwarding but none of my attempts to solve it seem to work.
I started by following the suggestions posted here How to access the local Django webserver from outside world by launching the server using python manage.py runserver 0.0.0.0:8000 and by entering <my-ip-address>:<port> in my external device' browser. This did not work, so I tried to explicitly make sure port forwarding was enabled by adding the following lines to iptables.
iptables -A INPUT -p tcp --dport 8000 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 8000 -m conntrack --ctstate ESTABLISHED -j ACCEPT
netfilter-persistent save
Still, I'm not able to access the local webserver. No error messages show up, the browser just tells me that the address took too long to respond. I've tried to do the above but this time with port 80 and using sudo when needed without avail. In addition I've tried to use this line ALLOWED_HOSTS = ['*'] as suggested by multiple users.
I've tried to investigate whether the application is really running on the indicated port using lsof -i which shows several PYTHON lines but I'm not sure what else I'm supposed to look for to see whether things are running correctly. Finally, I've disabled my firewall on my external device, which didn't help either.
Can anyone point me to a direction to find out what's wrong?
EDIT: to clarify, I can access the server perfectly fine from the same device where the local server is running.
i am writing a python application that is sending continously UDP messages to a predefined network with other hosts and fixed IPs. I wrote the python application and dockerized it. The application works fine in the docker, no problems there.
Unfortunately i am failing to send the UDP messages from my docker to the host so they will be sent to the other hosts in the network. The same is for receiving messages. Right now i dont know how to set up my docker so it is receiving a UDP message from a host with fixed IP adress in the network.
I tried to set up my docker network with --net host and i sent all the UDP messages from my docker container via localhost to my host. This worked fine, too. I am missing the link where i can sent the messages no to the "outside world". I tried to make a picture of my problem.
My Question: How do i have to set up the network communcation for my docker/host so it can receive messages via UDP from other hosts in the network?
Thanks
So i experimented a lot and i figured out, that i just need to run the docker container with the network configuration as host. The UDP socket in my container is bound to the IP adress of my host and therefore just needs to be linked to the Network of the host. Everyone who is struggeling the same issue, just run
docker run --network=host <YOURCONTAINER>
Build your own bridge
1.Configure the new bridge.
$ sudo ip link set dev br0 up
$ sudo ip addr add 192.168.5.1/24 dev bridge0
$ sudo ip link set dev bridge0 up
Confirm the new bridge’s settings.
$ ip addr show bridge0
4: bridge0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state UP group default
link/ether 66:38:d0:0d:76:18 brd ff:ff:ff:ff:ff:ff
inet 192.168.5.1/24 scope global bridge0
valid_lft forever preferred_lft forever <br/>
2. Configure Docker to use the new bridge by setting the option in the daemon.json file, which is located in /etc/docker/ on Linux or C:\ProgramData\docker\config\ on Windows Server. On Docker for Mac or Docker for Windows, click the Docker icon, choose Preferences, and go to Daemon.
If the daemon.json file does not exist, create it. Assuming there are no other settings in the file, it should have the following contents:
{
"bridge": "bridge0"
}
Restart Docker for the changes to take effect.
3. Confirm that the new outgoing NAT masquerade is set up.
$ sudo iptables -t nat -L -n
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all -- 192.168.5.0/24 0.0.0.0/0
4.Remove the now-unused docker0 bridge.
$ sudo ip link set dev docker0 down
$ sudo ip link del name br0
$ sudo iptables -t nat -F POSTROUTING
5.Create a new container, and verify that it is in the new IP address range.
(ref.)
I am using Jupyter Notebook for a project. Since I ssh into a linux cluster at work I use
ssh -Y -L 8000:localhost:8888 user#host
Then I start the notebook with jupyter notebook --no-browser & so that I can continue using the terminal. Then on my local machine I open to localhost:8000 and go about my work.
My problem is that I forgot several times to close the server by foregrounding the process and killing it with Ctrl-C. Instead I just logged out of the ssh session. Now when I run jupyter notebook list I get
Currently running servers:
http://localhost:8934/ :: /export/home/jbalsells
http://localhost:8870/ :: /export/home/jbalsells
http://localhost:8892/ :: /export/home/jbalsells
http://localhost:8891/ :: /export/home/jbalsells
http://localhost:8890/ :: /export/home/jbalsells
http://localhost:8889/ :: /export/home/jbalsells
http://localhost:8888/ :: /export/home/jbalsells
I obviously do not want all of these servers running on my work's machine, but I do not know how to close them!
When I run ps I get nothing:
PID TTY TIME CMD
12678 pts/13 00:00:00 bash
22584 pts/13 00:00:00 ps
I have Jupyter 4.1.0 installed.
So I found a solution.
Since jupyter notebook list tells you which ports the notebook servers are running on I looked for the PIDs using netstat -tulpn I got the information from http://www.cyberciti.biz/faq/what-process-has-open-linux-port/
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
PID/Program name
tcp 0 0 0.0.0.0:8649 0.0.0.0:* LISTEN
-
tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN
-
tcp 0 0 0.0.0.0:33483 0.0.0.0:* LISTEN
-
tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN
39125/Xvnc
Without looking too hard I was able to find the ports I knew to look for from jupyter notebook list and the processes running them (you could use grep if it were too hard to find them). Then I killed them with
kill 8337 (or whatever number was associated).
Windows Systems commands on Command Prompt
Be careful to save all the changes made in your notebooks prior to kill the jupyter notebook server process.
i) find the port number used by jupyter notebook server
jupyter notebook list
ex.)
jupyter notebook list
Currently running servers:
http://127.0.0.1:8888/ :: D:\kimkk\Documents\JupyterNotebook
ii) find process ids that use the found port number of jupyter notebook
netstat -ano | find "found portnumber"
ex.)
netstat -ano | find "8888"
TCP 127.0.0.1:8888 0.0.0.0:0 LISTENING 24140
TCP 127.0.0.1:8888 127.0.0.1:55588 ESTABLISHED 24140
TCP 127.0.0.1:8888 127.0.0.1:55612 ESTABLISHED 24140
TCP 127.0.0.1:55588 127.0.0.1:8888 ESTABLISHED 6492
TCP 127.0.0.1:55612 127.0.0.1:8888 ESTABLISHED 6492
find rows with second column value equals to "8888". In above example first, second, and third rows are target rows. In those rows, you can find PID in the last column (ex. 24140).
iii) kill jupyter notebook process with found PID
taskkill /PID found_PID /F
ex.)
taskkill /PID 24140 /F
/F means forcely kill the process.
FYI, Jupyter notebook from version 5.1 supports stop command as follows:
jupyter notebook stop 8888
refer to https://github.com/jupyter/notebook/issues/1950
Use the following command to stop Jupyter notebook running on port 8888:
fuser -k 8888/tcp
This might help:
run jupyter notebook list to get the port number jupyter uses.
run lsof -n -i4TCP:[port-number] to get PID.
The PID is the second field in the output.
run kill -9 [PID] to kill this process.
I ran into the same issue and followed the solution posted above. Just wanted to clearify the solution a little bit.
netstat -tulpn
will list all the active connections.
tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 19524/python
you will need the PID "19524" in this case. you can even use the following to get the PID of the port you are trying to shut down
fuser 8888/tcp
this will give you 19524 as well.
kill 19524
will shut down the port
Section 3.3 should be applicable to this.
http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/execute.html
When a notebook is opened, its “computational engine” (called the kernel) is automatically started. Closing the notebook browser tab, will not shut down the kernel, instead the kernel will keep running until is explicitly shut down.
To shut down a kernel, go to the associated notebook and click on menu File -> Close and Halt. Alternatively, the Notebook Dashboard has a tab named Running that shows all the running notebooks (i.e. kernels) and allows shutting them down (by clicking on a Shutdown button).
Here's a bash script that will kill ALL active Jupyter notebook servers at one go, based on the answers given by #Joalito and #Hongsoog:
#!/bin/bash
jupyter notebook list | {
while IFS= read -r line
do
port=`echo "$line" | grep -o -P '(?<=localhost:).*(?=/ :)'`
echo "killing jn in port $port"
if [ -z "$port" ]
then
netstat -tulpn | grep "$port" | grep -o -P '(?<=LISTEN ).*(?=/py)' | xargs kill -15
fi
done
}
On your notebook the welcoming page is named "Files" and you can see "Running" next to it. There is where you would want to shutdown and see the running notebooks
What worked for me was
jupyter notebook list, which in my case returned:
http://localhost:8889/?token=77d01d687da830b74eba946060660d :: /gpfs/blah/
http://localhost:8889/?token=1243162854ee3648e3154b26643794 :: /ifs/hello/world/
netstat -tulpn | grep "8888", which in my case returned:
tcp 7 0 127.0.0.1:8888 0.0.0.0:* LISTEN 17602/python3.9
And I found the PID in the last column: 17602.
kill -9 17602, which freed up the port.
Currently i have work on Python socket server on Openshift. Managed to get it listen to port (15000) and tested on local with telnet seems working fine.
However, i unable to connect to the socket server other than local ( either telnet to the socket server or using Adobe Air xmlsocket )
when i do a netstat on the server, i got following result:
netstat -tan | grep $OPENSHIFT_PYTHON_IP | grep $OPENSHIFT_PYTHON_PORT | grep ESTABLISHED
/proc/net/tcp: Permission denied
not sure whether i missed anything on the configuration on Openshift.
Btw, how can i get the IP of my server? if i use OPENSHIFT_PYTHON_IP the ip is only for local right?
Your websocket server needs to listen on port 8080, and you need to access it at ws://app-domain.rhcloud.com:8000
I got the following issue when I try to run my edX LMS (port 8000):
Error: That port is already in use
So in my vagrant account I found and did kill -9 on process which was using 8000. But as soon as I killed them, the process was automatically restarting and using port 8000 and I am unable to run LMS.
When that happens, I just do:
vagrant reload
(You will have to logout from SSH before by typing logout)
It is equivalent to:
vagrant halt
vagrant up
I've had times on OS/X with Vagrant where I've had to kill not only the vagrant process, but also virtualbox, when vagrant reload hasn't worked.
On your machine (not the guest VM):
ps -eaf | fgrep -i vagrant
ps -eaf | fgrep -i virtualbox
Then kill all those processes and "vagrant up."
vagrant halt is enough to kill all the processes related to the used port.