#!/bin/sh

COMMAND=$(basename $0 .sh)

# lock to avoid concurrent updates
LOCK=/var/run/univnautes-sp-$COMMAND.lock
if [ -r $LOCK ]
then
	PID=`cat $LOCK`
	echo "$COMMAND locked by $LOCK"
	ps waux | grep "$PID" | grep $COMMAND | grep -vq grep && exit
	echo "... but PID $PID is not a $COMMAND, continue"
fi
unlock() {
	rm -f $LOCK
	exit
}
trap unlock INT TERM EXIT
echo $$ > $LOCK

cd /usr/local/univnautes/sp
./manage.py $COMMAND

