0

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.

Nitesh Verma
  • 2,281
  • 4
  • 16
  • 33
  • Assuming you set up your virtual environment to isolate your application and dependency code, do you have an application running outside of your virtual environment that could be locking a socket/port? Or do you have some other configuration interfering with your primary configuration? – nicorellius Feb 09 '17 at 18:11
  • Not sure. I tried starting `app` by changing lots of `ports` but getting same error everytime. – Nitesh Verma Feb 09 '17 at 18:13
  • Another thing to try is... if you start a VM that has no other applications running, this could help isolate problem. – nicorellius Feb 09 '17 at 18:25
  • All my application are running on system level. I am not using VMs. – Nitesh Verma Feb 09 '17 at 18:42
  • It has nothing to do with killing off other applications. Your real problem is that you have ``app.run()`` at global scope in code. You need to protect that by a check to see if is ``__main__`` script module. You should not be calling that when hosting your application under mod_wsgi as you don't want to run the Flask web server. The reason for the duplicate is because Apache is multiprocess and creating more than one instance of your application. – Graham Dumpleton Feb 10 '17 at 00:49
  • @GrahamDumpleton What's the solution now ? The marked duplicate is not working for me. – Nitesh Verma Feb 10 '17 at 04:27
  • @GrahamDumpleton : You saved my day dude. Thanks. I was missing `__main__` before `app.run()` – Nitesh Verma Feb 10 '17 at 04:54

1 Answers1

0

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

Cody Myers
  • 161
  • 5