kill server when port is already used
[myslice.git] / devel / server-loop.sh
index a108f93..31cf0d8 100755 (executable)
@@ -6,8 +6,15 @@ cd $DIRNAME/..
 hostname | grep -q '^z' && port=8080 || port=80
 [[ -n "$@" ]] && port=$1
 
-make all-static all-templates
 while true; do 
-    ./manage.py runserver 0.0.0.0:$port
+    # 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