This question already has answers here:
How to kill a process running on particular port in Linux?
(34 answers)
Closed 6 years ago.
I have tried everything from last 2 days. But nothing really helped me out.
Background : I followed this to install flask app on production but I need to change serverName in vhost file so I forgot to kill an already running flask app/process and edited same vhost file to point to other location with few changes.
Problem : Now after apache restart, I continue getting following error when I access modified serverName.
mod_wsgi (pid=1685): Target WSGI script '/var/www/html/machine/machine.wsgi' cannot be loaded as Python module., referer: http://dev.badiyajobs.com/
mod_wsgi (pid=1685): Exception occurred processing WSGI script '/var/www/html/machine/machine.wsgi'., referer: http://dev.badiyajobs.com/
Traceback (most recent call last):
File "/var/www/html/machine/machine.wsgi", line$
from run import app as application
File "/var/www/html/machine/assessment/run.py",$
app.run()
File "/usr/local/lib/python2.7/dist-packages/fl$
run_simple(host, port, self, **options)
File "/usr/local/lib/python2.7/dist-packages/we$
inner()
File "/usr/local/lib/python2.7/dist-packages/we$
fd=fd)
File "/usr/local/lib/python2.7/dist-packages/we$
passthrough_errors, ssl_context, fd=fd)
File "/usr/local/lib/python2.7/dist-packages/we$
HTTPServer.__init__(self, (host, int(port)), $
File "/usr/lib/python2.7/SocketServer.py", line$
self.server_bind()
File "/usr/lib/python2.7/BaseHTTPServer.py", li$
SocketServer.TCPServer.server_bind(self)
File "/usr/lib/python2.7/SocketServer.py", line$
[self.socket.bind(self.server_address)
File "/usr/lib/python2.7/socket.py", line 224, $
return getattr(self._sock,name)(*args)
error: [Errno 98] Address already in use
Anybody please suggest how to get rid of already running app. I have tried lots of things regarding killing processes, but noting actually worked.
The easiest way to kill all processes that are listening on that port would be to use the fuser(1) command. For example, to see all of the processes listening for http requests on port 80 (run as root or use sudo):
fuser 80/tcp
If you want to kill them, then just add '-k' option
Source
Related
This question already has answers here:
Are a WSGI server and HTTP server required to serve a Flask app?
(3 answers)
How do I get Flask to run on port 80?
(15 answers)
Closed 4 years ago.
I tried to launche Flask in hosting using:
if __name__ == "__main__":
app.run('0.0.0.0', 8000)
But hoster has 8080 port as closed, it is possible to run Flask with default port 80?
I tried it gives me this error:
Use a production WSGI server instead.
* Debug mode: off
Traceback (most recent call last):
File "__init__.py", line 461, in <module>
app.run('0.0.0.0', 80)
File "/home/o/oliwin4/project/public_html/myenv/local/lib/python2.7/site-packages/flask/app.py", line 943, in run
run_simple(host, port, self, **options)
File "/home/o/oliwin4/project/public_html/myenv/local/lib/python2.7/site-packages/werkzeug/serving.py", line 814, in run_simple
inner()
File "/home/o/oliwin4/project/public_html/myenv/local/lib/python2.7/site-packages/werkzeug/serving.py", line 774, in inner
fd=fd)
File "/home/o/oliwin4/project/public_html/myenv/local/lib/python2.7/site-packages/werkzeug/serving.py", line 660, in make_server
passthrough_errors, ssl_context, fd=fd)
File "/home/o/oliwin4/project/public_html/myenv/local/lib/python2.7/site-packages/werkzeug/serving.py", line 577, in __init__
self.address_family), handler)
File "/usr/lib/python2.7/SocketServer.py", line 419, in __init__
self.server_bind()
File "/usr/lib/python2.7/BaseHTTPServer.py", line 108, in server_bind
SocketServer.TCPServer.server_bind(self)
File "/usr/lib/python2.7/SocketServer.py", line 430, in server_bind
self.socket.bind(self.server_address)
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 1] Operation not permitted
So, hoster said tht 80 port is open.
The Flask documentation states that:
While lightweight and easy to use, Flask’s built-in server is not
suitable for production as it doesn’t scale well. Some of the options
available for properly running Flask in production are documented
here.
The documentation also states several methods of using WSGI servers to deploy your web application. WSGI (Web Server Gateway Interface) is a standard that forwards requests from web servers to web applications written in Python. You'll want to use a WSGI server to run your website on your host, since it sounds like you're trying to deploy a Flask app to a production setting.
To answer your original question, the Flask library intentionally throws an error when you try to run it on port 80, because they specifically say that you should not use Flask's built-in server for production use. That's this part of your stacktrace:
Use a production WSGI server instead.
* Debug mode: off
and
socket.error: [Errno 1] Operation not permitted
For the lazy, or if the above link goes dead, here is an example using Gunicorn (copied directly from the above documentation link)
Gunicorn
Gunicorn ‘Green Unicorn’ is a WSGI HTTP Server for UNIX. It’s a
pre-fork worker model ported from Ruby’s Unicorn project. It supports
both eventlet and greenlet. Running a Flask application on this server
is quite simple:
gunicorn myproject:app
Gunicorn provides many command-line options – see gunicorn -h. For
example, to run a Flask application with 4 worker processes (-w 4)
binding to localhost port 4000 (-b 127.0.0.1:4000):
gunicorn -w 4 -b 127.0.0.1:4000 myproject:app
I am trying to deploy a flask app on google cloud app engine. It runs smooth in my virtual environment locally but I get an 502 error running it in the cloud.
Now I am trying to debug my code on the cloud server, using debug mode and SSH into my instance. Using docker exec -it [ID] /bin/bash I am able to to access the root of my application. Now I upon running python app.py I get the following error:
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
Traceback (most recent call last):
File "app.py", line 479, in <module>
app.run(port=8080)
File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 941, in run
run_simple(host, port, self, **options)
File "/usr/local/lib/python3.6/site-packages/werkzeug/serving.py", line 814, in run_simple
inner()
File "/usr/local/lib/python3.6/site-packages/werkzeug/serving.py", line 774, in inner
fd=fd)
File "/usr/local/lib/python3.6/site-packages/werkzeug/serving.py", line 660, in make_server
passthrough_errors, ssl_context, fd=fd)
File "/usr/local/lib/python3.6/site-packages/werkzeug/serving.py", line 577, in __init__
self.address_family), handler)
File "/usr/local/lib/python3.6/socketserver.py", line 453, in __init__
self.server_bind()
File "/usr/local/lib/python3.6/http/server.py", line 136, in server_bind
socketserver.TCPServer.server_bind(self)
File "/usr/local/lib/python3.6/socketserver.py", line 467, in server_bind
self.socket.bind(self.server_address)
OSError: [Errno 98] Address already in use
I've been trying to kill those processes listed when I run:
ps -fA | grep python
However, this does not solve the problem of the address being in use. Also changing the port in the app.run() does not solve the issue for me.
I had a similar problem, it was caused by the Flask app also being run when the module was loaded, because I had
if __name__ == "__main__":
app.run()
at the bottom. Note that the recent requirement to name your sever file "main.py" could cause this bug to emerge.
I think the problem is that you don't need to specialize the port for cloud. Google Cloud finds the port to run your app on its own. So instead of app.run(port=8080) just write app.run()
While I was not able to figure out how to "free" the running address, I solved the problem by starting another flask process by running it on a different port like so:
flask run --port=80
I followed this installation guide for odoo and I get an error in the very end
when I run odoo-bin file it gives me this error
teo#teo-Lenovo-Yoga-3-14:/opt/odoo/odoo-10.0$ ./odoo-bin
2017-07-06 15:03:20,583 3754 INFO ? odoo: Odoo version 10.0
2017-07-06 15:03:20,583 3754 INFO ? odoo: addons paths: ['/home/teo/.local/share/Odoo/addons/10.0', u'/opt/odoo/odoo-10.0/odoo/addons', u'/opt/odoo/odoo-10.0/addons']
2017-07-06 15:03:20,583 3754 INFO ? odoo: database: default#default:default
2017-07-06 15:03:20,601 3754 INFO ? odoo.service.server: HTTP service (werkzeug) running on 0.0.0.0:8069
Exception in thread odoo.service.httpd:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/opt/odoo/odoo-10.0/odoo/service/server.py", line 251, in http_thread
self.httpd = ThreadedWSGIServerReloadable(self.interface, self.port, app)
File "/opt/odoo/odoo-10.0/odoo/service/server.py", line 106, in __init__
handler=RequestHandler)
File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 440, in __init__
HTTPServer.__init__(self, (host, int(port)), handler)
File "/usr/lib/python2.7/SocketServer.py", line 417, in __init__
self.server_bind()
File "/opt/odoo/odoo-10.0/odoo/service/server.py", line 116, in server_bind
super(ThreadedWSGIServerReloadable, self).server_bind()
File "/usr/lib/python2.7/BaseHTTPServer.py", line 108, in server_bind
SocketServer.TCPServer.server_bind(self)
File "/usr/lib/python2.7/SocketServer.py", line 431, in server_bind
self.socket.bind(self.server_address)
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
error: [Errno 98] Address already in use
I think it may be related to the odoo.conf file because I specify a port but it still assumes de default port 8069
this is my odoo.conf file
[options]
; This is the password that allows database operations:
; admin_passwd = PASSWORD
db_host = False
db_port = 8470
db_user = odoo
db_password = False
addons_path = /opt/odoo/odoo-10.0/addons
;Log Settings
logfile = /var/log/odoo/odoo.log
log_level = error
Does anyone have an idea of what's happening, for the record I tried to install odoo before but failed so I already had DB user created for e.g.
Because odoo service automatically start when system starts, so you have to kill the odoo-service manually, and then run the ./odoo-bin file, at which point you should be able to see odoo running again.
sudo pkill -9 python
By doing this you'll stop python from finding the odoo service process id and subsequently killing that process.
ps aux | grep odoo
sudo kill <process id>
There are multiple pid running with odoo, ending with /etc/odoo-server.conf, which you have to select.
I think the best option is probably
sudo pkill -9 python
All the best, I hope I solved your problem.
Your odoo config has another DB port set, but 8069 is the port used for xmlrpc requests. If you want to change that in config, you have to set xmlrpc_port = 8470.
You getting this error because you have same port busy, you need to kill the existing process and then you can try again.
check process :
ps -aux|grep odoo.py
kill 09 [process id ]
You can check more details of installation tutorial here using Apache2 and WSGI : enter link description here
For this [Errno 98] error you use following two commands:
root#odoo:~# ps aux | grep odoo
Now you getting this type code
postgres 26041 0.1 2.3 1568276 196668 ? Sl Sep25 5:24 python ./odoo-bin
root#odoo:~# sudo kill -9 26041
Then your error will be fix.
[Errno 98] error you use following two commands
Get the id of the process running by following command
root#odoo:~# ps ax | grep servername
Then kill the already running process
sudo kill -9 process_id
You have another process running with the 8069 port. Kill the process killing python.
With the config file in odoo, you can change to different port changing 8069 with xmlrpc_port = 2003.
For example:
[options]
; This is the password that allows database operations:
admin_passwd = admin
db_host = 0.0.0.0
db_port = 5432
db_user = randall
db_password = admin
dbfilter = odoo
addons_path = /usr/lib/python2.7/dist-packages/openerp/addons
addons_path = /software/odoo/10.0/odoo-server/addons,/software/odoo/10.0/custom-addons,
xmlrpc_interface = 127.0.0.1
xmlrpc_port = 2002
Regards,
If your odoo set up, it's already running when you start your ubuntu.
It can be found in
/etc/init.d/odoo-server
Use this command to kill the existing services
ps -ef|grep odoo-bin
sudo kill ####
Solved with #ShivaGuntuku answer, just adding another way to solve the issue:
You're trying to run Odoo on port 8470, but as the error says you (Address already in use), another application is already running on that port (probably, another Odoo process).
So simply kill the process running on that port:
sudo fuser -k 8470/tcp
Then start your Odoo service again.
I have remote Ubuntu server, and I'm trying set up remote debugging.
Configured as shown here.
import sys
import pydevd
sys.path.append('/root/home/scripts/pycharm-debug.egg')
pydevd.settrace('my_remote_server_IP', port=51234,
stdoutToServer=True, stderrToServer=True)
I also connect remote host for synchronizing and uploading my python scripts to remote server. (Tools -> Deployment -> ...)
When I start debugging:
C:\Python27\python.exe C:/Projects/python/demo.py
Could not connect to xx.xx.xx.166: 51234
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 2.7.1\helpers\pydev\pydevd_comm.py", line 428, in StartClient
s.connect((host, port))
File "C:\Python27\Lib\socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
error: [Errno 10061] ����������� �� �����������,
Process finished with exit code 1
How to solve this problem?
The first argument of pydevd.settrace function should be the host, where PyCharm is installed. Not remote server.
Also in most cases if you want to run and debug your code remotely it is more convenient to use remote interpreter feature.
I resolved this problem by changing the port.
I'm currently attempting to setup a SiriServer (that's beside the point) on Xubuntu 12.10 x64, when I run the server python returns error
socket.error: [Errno 98] Address already in use.
The server by default is attempting to run on port 443, which unfortunetly is required in order for this application to work.
To double check if anything is running on port 443, I execute the following:
lsof -i :443
There's no results, unless I have something like Chrome or Firefox open, which I end up closing. Here's the full return from attempting to run the server application.
dustin#dustin-xubuntu:~/Applications/SiriServer$ sudo python siriServer.py
CRITICAL load_plugins Failed loading plugin due to missing module: 'Wordnik library not found. Please install wordnik library! e.g. sudo easy_install wordnik'
INFO <module> Starting Server
Traceback (most recent call last):
File "siriServer.py", line 493, in <module>
server = SiriServer('', options.port)
File "siriServer.py", line 425, in __init__
self.bind((host, port))
File "/usr/lib/python2.7/asyncore.py", line 342, in bind
return self.socket.bind(addr)
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use
I'm stuck on what to do, as this is the last part of setting up this application. Any help is appreciated.
You're not root -- that's your problem. To bind to ports under 1024 on Unix, you must be the superuser. So, hit su and try the python code again. Alternatively, bind to a port from 1024 to 65535.
This often happens when a python program doesn't exit properly when pressing ^C or ^Z. You could try reseting the terminal or exiting the terminal. You can also do killall -9 server.py
Another effective way to help prevent this even if you have root privs this can happen if a socket is not closed properly, here is a fix:
s=socket.socket( )
s.bind(("0.0.0.0", 8080))
while 1:
try:
c, addr = s.accept()
except KeyBoardInterrupt:
s.close()
exit(0)
I got that error even if port number is more than 1024
You can use
pkill -9 python
run command twice, it will list all python files which are killed
List all processes that you have running with
ps -a
Take the PID corresponding to python and pipe it into the kill command with (Example PID 2770)
kill -9 2770