Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

90 lines (73 sloc) 1.963 kb
#!/bin/bash
# NOTE: using the default HTTP based notification scheme is better, this is
# only here to accomodate backup messages when the service is down.
# Will go away when reliable messaging is introduced.
# This is currently set up to accomodate the scheme where the account used
# to call this script and write information to NOTIFICATION_FILE (the account
# configured in jndi-config.xml) is the same account reading and deleting
# entries from NOTIFICATION_FILE (the service container)
# To accomodate a different scheme, you could use a UNIX group common to the
# service container and the account used for notifications. You would need
# to set this script to chmod 550 instead of 500 and also alter the umask line
# below from 177 to 117, this controls the permissions on NOTIFICATION_FILE
NOTIFICATION_FILE="$0.txt"
TEMPFILE="$0.$$"
LOCKFILE="$0.lock"
set +e
function my_lockfile ()
{
echo $$ > $TEMPFILE || {
echo "You don't have permission to access `dirname $TEMPFILE`"
return 1
}
ln $TEMPFILE $LOCKFILE && {
rm -f $TEMPFILE
return 0
}
rm -f $TEMPFILE
return 1
}
function stale_check ()
{
PID=""
PID=`cat $LOCKFILE`
if [ "X$PID" != "X" ]; then
echo "checking if LOCKFILE pid $PID is stale"
kill -0 $PID
if [ $? != 0 ]; then
echo "pid $PID does not exist, removing lockfile"
rm -f $LOCKFILE
fi
fi
}
# wait for a lock
num=5
until my_lockfile ; do
sleep 0.1
num=`expr $num - 1`
if [ $num = 0 ]; then
stale_check
num=5
fi
done
if test ! -e $NOTIFICATION_FILE ;
then
umask 177
touch $NOTIFICATION_FILE
fi
line=''
if [ "$1" == "readanddelete" ]
then
cat $NOTIFICATION_FILE
rm $NOTIFICATION_FILE
elif [ "$1" == "write" ];
then
shift
for str in $* ;
do
line="$line$str::"
done
line="$line<eon>"
echo $line >> $NOTIFICATION_FILE
fi
rm -f $LOCKFILE
Jump to Line
Something went wrong with that request. Please try again.