mirror of
https://github.com/ceph/ceph
synced 2024-12-28 06:23:08 +00:00
Merge pull request #1020 from ceph/wip-15563-master
Added file locking logic to avoid possible collisions … Reviewed-by: Dan Mick <dmick@redhat.com>
This commit is contained in:
commit
3dc18691a1
@ -9,8 +9,10 @@ fi
|
||||
|
||||
# set permanent $LOG file var
|
||||
LOG="/var/log/crontab-nightlies-log/crontab.log"
|
||||
# set $LOG_LOCKED_ERR in case locking failed
|
||||
LOG_LOCK_ERR="/var/log/crontab-nightlies-log/crontab_lock_problem.$$"
|
||||
|
||||
# temp files to store sdtout and stderr
|
||||
# temp files to store stdout and stderr
|
||||
# named with the PID of this script in their name so they'll be unique
|
||||
STDERR="/var/tmp/stderr.$$"
|
||||
STDOUT="/var/tmp/stdout.$$"
|
||||
@ -18,11 +20,12 @@ STDOUT="/var/tmp/stdout.$$"
|
||||
# $STDOUT and $STDERR are removed when the script exits for any reason
|
||||
trap "rm -f $STDOUT $STDERR" 0
|
||||
|
||||
# log a name of the command about to be run
|
||||
echo "Running command: $@" >> $LOG
|
||||
|
||||
# run a command from this script's argument
|
||||
# redirect stdout to $STDOUT file and redirect stderr to $STDERR file
|
||||
|
||||
DATE=$(date)
|
||||
echo -n "$DATE: " >> $STDOUT
|
||||
echo "Running command: $@" >> $STDOUT
|
||||
"$@" > $STDOUT 2> $STDERR
|
||||
|
||||
# get return code from the command run
|
||||
@ -36,7 +39,12 @@ if [ $code != 0 ] ; then
|
||||
cat $STDERR
|
||||
else
|
||||
# normal exit: just log stdout
|
||||
DATE=$(date)
|
||||
echo -n "$DATE: " >> $LOG
|
||||
cat $STDOUT >> $LOG
|
||||
|
||||
# lock $LOG with file descriptor 200
|
||||
exec 200>>$LOG
|
||||
# if $LOG is locked by other process - wait for 20 sec
|
||||
flock -w 20 200 || LOG=$LOG_LOCK_ERR
|
||||
cat $STDOUT >> $LOG
|
||||
# unlock
|
||||
flock -u 200
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user