This repository has been archived by the owner on Sep 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
/
notifications
87 lines (71 loc) · 1.77 KB
/
notifications
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
# NOTE: 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