Silence lock wrapper if script is still running

Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
This commit is contained in:
Patrick Uiterwijk 2018-05-17 16:30:06 +02:00
parent c29ffd217f
commit 8773b6d931
2 changed files with 0 additions and 43 deletions

View file

@ -22,8 +22,6 @@ if ! mkdir "$LOCKDIR"; then
PID=$(cat "$PIDFILE") PID=$(cat "$PIDFILE")
if [ -n "$PID" ] && /bin/ps $PID > /dev/null if [ -n "$PID" ] && /bin/ps $PID > /dev/null
then then
echo "$PID is still running"
/bin/ps -o user,pid,start,time,comm $PID
exit 1; exit 1;
else else
echo "$LOCKDIR exists but $PID is dead" echo "$LOCKDIR exists but $PID is dead"

View file

@ -1,41 +0,0 @@
#!/bin/bash
if [ $# -lt 2 ]; then
echo "Usage: $0 [name] [script]"
exit 1;
fi
NAME=$1
SCRIPT=$2
LOCKDIR="/var/tmp/$NAME"
PIDFILE="$LOCKDIR/pid"
function cleanup {
rm -rf "$LOCKDIR"
}
RESTORE_UMASK=$(umask -p)
umask 0077
if ! mkdir "$LOCKDIR"; then
echo "$LOCKDIR already exists"
PID=$(cat "$PIDFILE")
if [ -n "$PID" ] && /bin/ps $PID > /dev/null
then
echo "$PID is still running"
/bin/ps -o user,pid,start,time,comm $PID
exit 1;
else
echo "$LOCKDIR exists but $PID is dead"
echo "Removing lockdir and re-running"
/bin/rm -rf $LOCKDIR
mkdir $LOCKDIR || exit
fi
fi
trap cleanup EXIT SIGQUIT SIGHUP SIGTERM
echo $$ > "$PIDFILE"
$RESTORE_UMASK
eval "$SCRIPT"