kill server when port is already used demo
authorAnthony Garcia <anthony.garcia@inria.fr>
Mon, 30 Sep 2013 10:55:32 +0000 (12:55 +0200)
committerAnthony Garcia <anthony.garcia@inria.fr>
Mon, 30 Sep 2013 10:55:32 +0000 (12:55 +0200)
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