I cannot find a way to kill or remove my postgresql server.
postgres -V
shows the version is 9.5.3 but I cannot find the path file in my mac. I tried lsof -i :5432 and the result comes out as below
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres 1403 jk0819 5u IPv6 0x35013bd948ad16e1 0t0 TCPlocalhost:postgresql (LISTEN)
postgres 1403 jk0819 6u IPv4 0x35013bd9438f8821 0t0 TCP localhost:postgresql (LISTEN)
but when I run kill -9 1403 it does nothing. Can anyone help me?
Thank you.
Related
On a CentOS Linux 7 machine, I have a web app served on port 1314
$ netstat -anp | grep 1314
tcp 0 0 127.0.0.1:1314 0.0.0.0:* LISTEN 1464/hugo
tcp 0 0 127.0.0.1:60770 127.0.0.1:1314 TIME_WAIT -
and I can curl it locally.
I opened port 1314:
iptables-save | grep 1314
-A IN_public_allow -p tcp -m tcp --dport 1314 -m conntrack --ctstate NEW,UNTRACKED -j ACCEPT
I checked with nmap locally:
PORT STATE SERVICE
1314/tcp open pdps
Everything seems fine.
Now if I try to curl the web app from another machine I get connection refused.
When I try nmap from the remote machine:
PORT STATE SERVICE
1314/tcp closed pdps
So the firewall doesn't block the port, but it looks like there is no one listening on port 1314...
But we know that the web app is running on this endpoint so what is going on??
Having a process listening to a port (and that port is open and properly configured) is not enough to enable remote communication. The local address needs to be on the same network as the remote address too!
Here, on the netstat printout, we can see that the local address is localhost (127.0.0.1 or ::1). Localhost is obviously not on the same network as the remote machine I was using to curl my web app. This explains also why nmap was reporting a closed port (meaning that nothing was listening on the local end).
Note: to listen to all the network interfaces, the local address should be 0.0.0.0 or :::.
I created a AWS instance today, and I am running a server and listen to 19999 port. let's see what I got:
root#ip-172-31-18-145:/home/ubuntu# sudo lsof -i -P -n | grep 19999
ssserver 20387 root 4u IPv4 65547 0t0 TCP *:19999 (LISTEN)
ssserver 20387 root 5u IPv4 65548 0t0 UDP *:19999
But i couldn't connect my port on my remote client-side, so I was trying to use nmap. here what I got.
root#ip-172-31-18-145:/home/ubuntu# nmap -Pn 127.0.0.1
Starting Nmap 7.60 ( https://nmap.org ) at 2020-02-15 13:47 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.0000030s latency).
Not shown: 999 closed ports
PORT STATE SERVICE
22/tcp open ssh
My question is what's wrong with nmap? To make sure the port is listening I am running nc to try to listen the 19999 again. and here is the output:
ubuntu#ip-172-31-18-145:~$ nc -l 19999
nc: Address already in use
Nothing is wrong with nmap by default it only scan a 1000 most common ports. You can you use nmap -Pn 127.0.0.1 -p 19999
I ran python manage.py runserver and the website was running at http://127.0.0.1:8000/. I closed the terminal window running the server, reopened terminal and tried to run python manage.py runserver again, but it says Error: That port is already in use. I can't quit the server with Control-C like I normally do, so I am not sure what do to here? Thanks for any help.
Follow these steps to kill the server that's running.
$ lsof -i :8000
8000 is the port. So, if your using django and you run python manage.py runserver it's likely your port will be "8000"
That command will yield something like:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
python 1158 biju 3u IPv4 0x4ae303085ae91559 0t0 TCP localhost:irdmi (LISTEN)
Except under "biju" it would have your username. Do you see the value under "PID" this is the number you need. Now you just kill that process.
$ kill -9 1158
Let's do that one more time:
$ lsof -i :8000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
python 4894 biju 3u IPv4 0x4ae3030864c1dd41 0t0 TCP localhost:irdmi (LISTEN)
$ kill -9 4894
And that's it. You can kill this server without an error running.
I am using a digitalocean ubuntu 14.04 vps. When I run
sudo lsof -i:9000
I get varying results such as
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
gunicorn 23148 django 5u IPv4 51019 0t0 TCP localhost:9000 (LISTEN)
or
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
gunicorn 23174 django 5u IPv4 51179 0t0 TCP localhost:9000 (LISTEN)
gunicorn 23175 django 5u IPv4 51179 0t0 TCP localhost:9000 (LISTEN)
where the number of gunicorn processes varies from 0-4, even if I run lsof immediately after the previous attempt. Simply running
pkill gunicorn
is failing, I believe because the PIDs are constantly changing (as shown above). How can I kill these processes permanently? If it makes a difference, I am user "root", and do not have a login for user "django"
lsof will only show the child processes which are actually binding to the port. You need to kill the master process. If you start gunicorn with the --pid option you can give it a filename to store the PID of that process in, then you can kill it directly; if not you can get it from ps|grep gunicorn.
Even better, as elethan suggests in the comments, set up gunicorn as a service using whatever process manager exists on your system - systemd, upstart, supervisor, or whatever - and use that to start and stop it.
I am a newbie to the whole website thing... Would really appreciate if you could give some help here...
What I want to do is host a Django project on a remote server (red hat, CentOS release 6.5)
I've been running test of the project on a remote server using the development server and port 8000:
python manage.py runserver *.*.*.*:8000 --insecure
In this case, the website works fine and accessible from other machines.
0 errors found
September 04, 2014 - 08:13:03
Django version 1.6.4, using settings 'mysite.settings'
Starting development server at http://*.*.*.*:8000/
Quit the server with CONTROL-C.
Now I want to put it in production, and I've chosen to use Apache http server and mod_wsgi. I have httpd and wsgi installed and activated. I changed the httpd.conf configuration file to:
Listen *:80 (I've also tried Listen *:8000 and Listen (IP address):8000)
#DocumentRoot "/var/www/html"
DocumentRoot "/testsite" (I put a plan html file under the directory just for test)
ServerName <here is the url of the site,with no port number>
However, when I try to open the webpage I am always having a 503 error:
Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime
or capacity problems. Please try again later.
Apache/2.2.3 (CentOS) Server at <site url> Port 80
I tried a couple of things (1) checked what's using the port 80:
~# sudo lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 28732 root 4u IPv6 19802111 0t0 TCP *:http (LISTEN)
httpd 28734 apache 4u IPv6 19802111 0t0 TCP *:http (LISTEN)
httpd 28735 apache 4u IPv6 19802111 0t0 TCP *:http (LISTEN)
httpd 28736 apache 4u IPv6 19802111 0t0 TCP *:http (LISTEN)
httpd 28737 apache 4u IPv6 19802111 0t0 TCP *:http (LISTEN)
httpd 28738 apache 4u IPv6 19802111 0t0 TCP *:http (LISTEN)
httpd 28739 apache 4u IPv6 19802111 0t0 TCP *:http (LISTEN)
httpd 28740 apache 4u IPv6 19802111 0t0 TCP *:http (LISTEN)
httpd 28741 apache 4u IPv6 19802111 0t0 TCP *:http (LISTEN)
~# service httpd status
httpd (pid 28732) is running...
(2) restart the apache server:
service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
(3) placed a plain .html in /var/www/html/testsite, the DocumentRoot directory for testing.
(4) I tried to run the django on a different port (such as 8008, 8001 and 80)
e.g. python manage.py runserver *.*.*.*:8008 --insecure
0 errors found
September 04, 2014 - 07:56:18
Django version 1.6.4, using settings 'mysite.settings'
Starting development server at http://*.*.*.*:8008/
Quit the server with CONTROL-C.
As shown above, in the terminal it looks like it's working , but I cannot even access the website from remote machines even using the development server. I tried different port numbers but only the port 8000 can be used. But why can I open the webpage on localhost when I change the port number? e.g. 127.0.0.1:8008 or 127.0.0.1:8080 will work.
I guess it can be the firewall setting, then I went to /etc/sysconfig/iptables, I found under the web section, there was only one line:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8000 -j ACCEPT
Then I added another line for testing:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8001 -j ACCEPT
Then tried the development again with port 8001. Again, it looks like it's woking on the remote server but not accessible from remote machines.
Sorry if I made this confusing and if I asked something really silly. Now, I have three questions that I really don't understand. First of all, the 503 error really annoys me. Even it shows the apache server is running (restart httpd is OK), nothing actually displays... Second of all, when using the development server why can I only use port 8000 but not any else? Finally, in the 503 error message, it shows apache runs on Port 80 even after I changed the Listen port to 8000 in the configuration file, why is this?
Thanks ahead for any help!
If that is your only configuration I don't see how Apache could be aware of your Django running 8000. There is no indication that you are making Apache to connect or proxy requests to running Django instance.
What you need to do is
Configure mod_wsgi for Apache
or
Configure fgci for Apache
You are free to choose any port with Django development server. You can configure the IP address and the port the development server listens to with command line parameters.
You can make the Django development server to listen all IP addresses, including public IP addresses on the server, as:
python manage.py runserver 0.0.0.0:8000
Also Apache logs can be read at /var/log/apache (or similar directory), so it should explain why you are getting 503.
I doubt iptables are not related to any way to your problem, but somehow Django development server is not listening to public IP address. You can easily try this by disabled iptables firewall on the server.