16

I am trying to upload my project to the server. There is already a project in the server now. I have new project which I want to run and replace the old project with the new one, so I pull the new project to the server. Then I activate the virtual environment and do all the necessary work. Then when I try to run the command:

uwsgi --plugins=python --chdir=/var/www/prjt/src/ --socket=127.0.0.1:8889 --module=prjt.wsgi:application &

it tell me that

probably another instance of uWSGI is running on the same address (127.0.0.1:8889).
bind(): Address already in use [core/socket.c line 761]

I searched for similar problems and found some solutions about killing all instance of uwsgi as mentioned in this answer here but could not find how to do it.

5 Answers 5

42

for me the way to kill uwsgi instances in a bruteforce manner was:

sudo pkill -f uwsgi -9
2
  • This is the only answer that worked for me. Thanks, random dude! Feb 1, 2019 at 15:17
  • This should be marked as the answer. If you kill individual processes then they spawn back again. The only way is it to kill all of them in one go Dec 20, 2019 at 7:41
21

Add a pidfile to your command:

uwsgi --plugins=python --chdir=/var/www/prjt/src/ --socket=127.0.0.1:8889 --module=prjt.wsgi:application --pidfile /tmp/myapp.pid

Then use

uwsgi --stop /tmp/myapp.pid

to stop the uwsgi instance in a safe way.

If you didn't specify a pidfile when you started the first instance, you can kill it brutally using

kill `pidof uwsgi`
7
  • where should I place this pidfile? Aug 12, 2015 at 16:45
  • Somewhere that is readable and writable by the uwsgi process, and hopefully not writable by other users. Maybe create a directory for pidfiles inside your home directory. Aug 12, 2015 at 16:48
  • I edited my answer to add a more realistic path for your pidfile. Aug 12, 2015 at 16:56
  • Smith it shows error permission denied when I try to place it in /var/run(I am running this command in virtual environment) Aug 12, 2015 at 18:11
  • Place it in the /tmp directory. Every user can create a file here and since /tmp has the sticky bit set, only the user who created the file can delete it. Aug 13, 2015 at 16:00
10

you can get the pid of the uwsgi process here lsof -t -i tcp:8000

and kill it then kill -9 pid

1
  • 1
    If you have more than one process tied to port 8000 kill -KILL $(lsof -t -i tcp:8000) will kill them all.
    – a_Fraley
    Jun 19, 2017 at 17:38
3

I stop my uwsgi instance by command:

kill -INT `cat ${APP_ROOT}/run/uwsgi.pid`

This command sends signal to uwsgi which cause it to stop.

If you do not know PID than you may:

killall -s INT /ve/path/bin/uwsgi

The official documentation

-1

Simliary, I had that issue too. And I tried all the way(answer) that written in this page. BUT Nothing was changed. So I just restart the computer and the problem is gone!!!!!!!!!!!! Try it!

2
  • 2
    Hmm. Maybe in your case restarting solved the issue. But this question is six years old. Don't you think OP has not yet restarted his computer? Sep 8, 2021 at 22:22
  • Please provide additional details in your answer. As it's currently written, it's hard to understand your solution.
    – Community Bot
    Sep 9, 2021 at 5:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.