/[pdpsoft]/trunk/userspace-package-management/write-lock-test.sh
ViewVC logotype

Annotation of /trunk/userspace-package-management/write-lock-test.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1904 - (hide annotations) (download) (as text)
Tue Aug 31 12:32:09 2010 UTC (12 years, 1 month ago) by dennisvd
File MIME type: application/x-shellscript
File size: 1515 byte(s)
initial checkin of scripts

1 dennisvd 1904 #!/bin/sh
2    
3    
4     vo_sw_dir=${HOME}/vosw
5    
6     error() {
7     echo $@
8     exit 1
9     }
10    
11     log() {
12     echo LOG: $@
13     }
14    
15     get_write_lock() {
16     log "Checking if the vo software area is writable."
17     if [ -z $vo_sw_dir ] ; then
18     error "\$$vo_sw_dir_var not set."
19     fi
20    
21     if [ ! -w $vo_sw_dir ] ; then
22     error "\$$vo_sw_dir_var ($vo_sw_dir) is not writable. (Check your proxy: are you the VO software manager?)"
23     fi
24     log "$vo_sw_dir writable OK."
25     # now do the lockfile shuffle
26     lockfile=$vo_sw_dir/pkgsrc-lock
27     log "checking lockfile $lockfile"
28     if [ -f $lockfile ]; then
29     log "lockfile exists."
30     ls -l $lockfile
31     if [ -z `find $lockfile -mmin -30` ]; then
32     log "stale lockfile ($lockfile is older than 30 minutes)"
33     rm -f $lockfile || error "could not remove $lockfile. Call help."
34     else
35     log "lockfile is still fresh."
36     return 1
37     fi
38     else
39     log "no lockfile found. Setting lock"
40     fi
41     # At this point, we've concluded we should try and set the lockfile.
42     # be careful to avoid race conditions (although rare).
43     log "attempting to get lock."
44     a=`mktemp $vo_sw_dir/pkgsrc-lock.XXXXXXXXXX` || error "mktemp failed"
45     ln $a $lockfile
46     if [ $? -ne 0 ]; then
47     log "failed to obtain lock"
48     rm $a
49     return 1
50     fi
51     log "lock set"
52     rm $a
53     unset a
54     trap "rm -f $lockfile" INT TERM EXIT
55     return 0
56     }
57    
58     echo "try 1:"
59     get_write_lock
60     if [ $? -ne 0 ]; then
61     echo fail
62     else
63     echo ok
64     fi
65    
66     echo "try 2:"
67     get_write_lock
68     if [ $? -ne 0 ]; then
69     echo fail
70     else
71     echo ok
72     fi

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28