Keep the runtime of the snyc script at the lock file and compare whether the passed time is above 15 minutes if so remove the lock file

This commit is contained in:
Oğuz Yarımtepe 2010-05-25 09:32:45 +00:00
parent 2fec8c3202
commit f701d0cdf5
5 changed files with 76 additions and 16 deletions

20
sync
View File

@ -77,11 +77,24 @@ if [[ ! -f "$LOG_DIR/$LOG_FILE" ]]; then
fi fi
if [[ -f "$PLANET_DIR/$LOCK_FILE" ]]; then if [[ -f "$PLANET_DIR/$LOCK_FILE" ]]; then
echo "there's a sync process running behind, please try again later.."
exit 1 cur_date=`date +%Y%m%d%H%M`
else file_date=`cat "$PLANET_DIR/$LOCK_FILE"`
sub=$((cur_date - file_date))
#if the difference is bigger than the 10 minutes interval of cron job, that means we have lock file that requires delete
if [ $sub -gt 15 ]; then
echo "Removing the lock file" >> "$LOG_DIR/$LOG_FILE" 2>&1
rm -f "$PLANET_DIR/$LOCK_FILE"
else
echo "there's a sync process running behind, please try again later.."
exit 1
fi
fi
touch "$PLANET_DIR/$LOCK_FILE" touch "$PLANET_DIR/$LOCK_FILE"
# lets add the runtime of the script to the lock file
echo "$(date +"%Y%m%d%H%M")" > "$PLANET_DIR/$LOCK_FILE"
cd "$PLANET_DIR" cd "$PLANET_DIR"
if (( $VERBOSE == 0 )); then if (( $VERBOSE == 0 )); then
@ -97,7 +110,6 @@ else
"$PLANET_DIR/planet.py" "$PLANET_DIR/gezegen/config.ini" "$PLANET_DIR/planet.py" "$PLANET_DIR/gezegen/config.ini"
echo "-----------------------------------------------------------" echo "-----------------------------------------------------------"
fi fi
fi
# if ended successfully delete the lock file # if ended successfully delete the lock file
rm "$PLANET_DIR/$LOCK_FILE" rm "$PLANET_DIR/$LOCK_FILE"

View File

@ -77,11 +77,23 @@ if [[ ! -f "$LOG_DIR/$LOG_FILE" ]]; then
fi fi
if [[ -f "$PLANET_DIR/$LOCK_FILE" ]]; then if [[ -f "$PLANET_DIR/$LOCK_FILE" ]]; then
echo "there's a sync process running behind, please try again later.." cur_date=`date +%Y%m%d%H%M`
exit 1 file_date=`cat "$PLANET_DIR/$LOCK_FILE"`
else sub=$((cur_date - file_date))
#if the difference is bigger than the 10 minutes interval of cron job, that means we have lock file that requires delete
if [ $sub -gt 15 ]; then
echo "Removing the lock file" >> "$LOG_DIR/$LOG_FILE" 2>&1
rm -f "$PLANET_DIR/$LOCK_FILE"
else
echo "there's a sync process running behind, please try again later.."
exit 1
fi
touch "$PLANET_DIR/$LOCK_FILE" touch "$PLANET_DIR/$LOCK_FILE"
# lets add the runtime of the script to the lock file
echo "$(date +"%Y%m%d%H%M")" > "$PLANET_DIR/$LOCK_FILE"
cd "$PLANET_DIR" cd "$PLANET_DIR"
if (( $VERBOSE == 0 )); then if (( $VERBOSE == 0 )); then

View File

@ -77,11 +77,23 @@ if [[ ! -f "$LOG_DIR/$LOG_FILE" ]]; then
fi fi
if [[ -f "$PLANET_DIR/$LOCK_FILE" ]]; then if [[ -f "$PLANET_DIR/$LOCK_FILE" ]]; then
echo "there's a sync process running behind, please try again later.." cur_date=`date +%Y%m%d%H%M`
exit 1 file_date=`cat "$PLANET_DIR/$LOCK_FILE"`
else sub=$((cur_date - file_date))
#if the difference is bigger than the 10 minutes interval of cron job, that means we have lock file that requires delete
if [ $sub -gt 15 ]; then
echo "Removing the lock file" >> "$LOG_DIR/$LOG_FILE" 2>&1
rm -f "$PLANET_DIR/$LOCK_FILE"
else
echo "there's a sync process running behind, please try again later.."
exit 1
fi
touch "$PLANET_DIR/$LOCK_FILE" touch "$PLANET_DIR/$LOCK_FILE"
# lets add the runtime of the script to the lock file
echo "$(date +"%Y%m%d%H%M")" > "$PLANET_DIR/$LOCK_FILE"
cd "$PLANET_DIR" cd "$PLANET_DIR"
if (( $VERBOSE == 0 )); then if (( $VERBOSE == 0 )); then

View File

@ -77,11 +77,23 @@ if [[ ! -f "$LOG_DIR/$LOG_FILE" ]]; then
fi fi
if [[ -f "$PLANET_DIR/$LOCK_FILE" ]]; then if [[ -f "$PLANET_DIR/$LOCK_FILE" ]]; then
echo "there's a sync process running behind, please try again later.." cur_date=`date +%Y%m%d%H%M`
exit 1 file_date=`cat "$PLANET_DIR/$LOCK_FILE"`
else sub=$((cur_date - file_date))
#if the difference is bigger than the 10 minutes interval of cron job, that means we have lock file that requires delete
if [ $sub -gt 15 ]; then
echo "Removing the lock file" >> "$LOG_DIR/$LOG_FILE" 2>&1
rm -f "$PLANET_DIR/$LOCK_FILE"
else
echo "there's a sync process running behind, please try again later.."
exit 1
fi
touch "$PLANET_DIR/$LOCK_FILE" touch "$PLANET_DIR/$LOCK_FILE"
# lets add the runtime of the script to the lock file
echo "$(date +"%Y%m%d%H%M")" > "$PLANET_DIR/$LOCK_FILE"
cd "$PLANET_DIR" cd "$PLANET_DIR"
if (( $VERBOSE == 0 )); then if (( $VERBOSE == 0 )); then

View File

@ -77,11 +77,23 @@ if [[ ! -f "$LOG_DIR/$LOG_FILE" ]]; then
fi fi
if [[ -f "$PLANET_DIR/$LOCK_FILE" ]]; then if [[ -f "$PLANET_DIR/$LOCK_FILE" ]]; then
echo "there's a sync process running behind, please try again later.." cur_date=`date +%Y%m%d%H%M`
exit 1 file_date=`cat "$PLANET_DIR/$LOCK_FILE"`
else sub=$((cur_date - file_date))
#if the difference is bigger than the 10 minutes interval of cron job, that means we have lock file that requires delete
if [ $sub -gt 15 ]; then
echo "Removing the lock file" >> "$LOG_DIR/$LOG_FILE" 2>&1
rm -f "$PLANET_DIR/$LOCK_FILE"
else
echo "there's a sync process running behind, please try again later.."
exit 1
fi
touch "$PLANET_DIR/$LOCK_FILE" touch "$PLANET_DIR/$LOCK_FILE"
# lets add the runtime of the script to the lock file
echo "$(date +"%Y%m%d%H%M")" > "$PLANET_DIR/$LOCK_FILE"
cd "$PLANET_DIR" cd "$PLANET_DIR"
if (( $VERBOSE == 0 )); then if (( $VERBOSE == 0 )); then