kill server when port is already used
[myslice.git] / devel / server-loop.sh
index 1ac43e4..31cf0d8 100755 (executable)
@@ -10,6 +10,11 @@ while true; do
     # we use make for convenience
     # but what the static target really does is to invoke manage.py collectstatic 
     make static templates
+
+    # if port is already used, we kill the server
+    pid=$(netstat -putan | awk "\$4 == \"0.0.0.0:$port\" && \$7 != \"-\" {split(\$7,a,\"/\"); print a[1]}")
+    [[ -n "$pid" ]] && kill $pid
+    
     ./manage.py runserver 0.0.0.0:$port
        sleep 1
 done