[Fixed]-How to kill Django runserver sub processes from a bash script?

15👍

SOLVED

Thanks to this SO question, I’ve changed my script to this:

#!/bin/bash
SITE=/home/dev/sites/rmx

echo "RMX using siteroot=$SITE"
$SITE/rmx/manage.py runserver &
compass watch $SITE/media/compass/ &
coffee -o $SITE/media/js -cw $SITE/media/coffee &
hamlpy-watcher $SITE/templates/hamlpy $SITE/templates/templates &

trap "kill -TERM -$$" SIGINT

wait

PIDs preceded with the dash operate on the PID group with the kill command, and the $$ references the PID of the bash script itself.

Thanks for the help, me!
No problem, self, and hey — you’re awesome.

👤jjt

1👍

You can execute this to kill or process and servers, you set PORT number:

$ netstat -tulpn | grep PORT | awk '{print $7}' | cut -d/ -f 1 | xargs kill

OR

$ sudo lsof -i tcp:PORT
$ sudo lsof -i tcp:PORT|awk '{print $2}'|cut -d/ -f 1|xargs kill

Leave a comment