2008-11-04 01:25:14 +02:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
# sync.sh
|
|
|
|
|
#
|
|
|
|
|
# this script is written to syncronize the lkd planet..
|
2008-11-04 01:44:20 +02:00
|
|
|
|
#
|
|
|
|
|
# author: Alper KANAT <alper.kanat@linux.org.tr>
|
2008-11-04 01:25:14 +02:00
|
|
|
|
|
2008-11-04 01:44:20 +02:00
|
|
|
|
PLANET_DIR="${HOME}/public_html/gezegen"
|
2008-11-05 01:19:37 +02:00
|
|
|
|
LOG_DIR="$PLANET_DIR/logs"
|
|
|
|
|
LOG_FILE="planet-$(date +"%d.%m.%Y").log"
|
2008-11-04 01:44:20 +02:00
|
|
|
|
LOCK_FILE="planet-sync.lck"
|
2008-11-06 02:36:00 +02:00
|
|
|
|
VERBOSE=0
|
2008-11-04 01:44:20 +02:00
|
|
|
|
|
2008-11-05 01:19:37 +02:00
|
|
|
|
usage() {
|
|
|
|
|
cat << EOF
|
|
|
|
|
Synchronizes the planet by invoking the necessary commands and logges everything.
|
|
|
|
|
|
|
|
|
|
Options:
|
|
|
|
|
-h, --help this help
|
|
|
|
|
-p, --planetdir useful if the planet dir is somewhere else than the
|
|
|
|
|
default one
|
2008-11-06 02:36:00 +02:00
|
|
|
|
-v, --verbose print the log instead of writing it to the log file..
|
2008-11-05 01:19:37 +02:00
|
|
|
|
|
|
|
|
|
Usage: $(basename $0) [--help] [--planetdir /path/to/planet]
|
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (( $# > 0 )); do
|
|
|
|
|
case "$1" in
|
|
|
|
|
--help|-h)
|
|
|
|
|
usage
|
|
|
|
|
shift
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
--planetdir|-p)
|
|
|
|
|
case "$2" in
|
|
|
|
|
[a-zA-Z0-9\/]*)
|
|
|
|
|
PLANET_DIR="$2"
|
|
|
|
|
LOG_DIR="$PLANET_DIR/logs"
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
*)
|
|
|
|
|
usage
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
|
2008-11-06 02:36:00 +02:00
|
|
|
|
--verbose|-v)
|
|
|
|
|
VERBOSE=1
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
|
2008-11-05 01:19:37 +02:00
|
|
|
|
-*)
|
|
|
|
|
usage
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
?*)
|
|
|
|
|
usage
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# checking planet dir
|
|
|
|
|
if [[ ! -d "$PLANET_DIR" ]]; then
|
|
|
|
|
echo "invalid planet directory.. please specify the correct planet dir with --planetdir /path/to/planet"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# checking if the log file created for the current date
|
|
|
|
|
if [[ ! -f "$LOG_DIR/$LOG_FILE" ]]; then
|
|
|
|
|
touch "$LOG_DIR/$LOG_FILE"
|
|
|
|
|
fi
|
|
|
|
|
|
2008-11-04 01:44:20 +02:00
|
|
|
|
if [[ -f "$PLANET_DIR/$LOCK_FILE" ]]; then
|
2010-05-25 12:32:45 +03:00
|
|
|
|
|
|
|
|
|
cur_date=`date +%Y%m%d%H%M`
|
|
|
|
|
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
|
2008-11-04 01:44:20 +02:00
|
|
|
|
touch "$PLANET_DIR/$LOCK_FILE"
|
2008-11-06 03:24:32 +02:00
|
|
|
|
|
2010-05-25 12:32:45 +03:00
|
|
|
|
# lets add the runtime of the script to the lock file
|
|
|
|
|
echo "$(date +"%Y%m%d%H%M")" > "$PLANET_DIR/$LOCK_FILE"
|
|
|
|
|
|
2008-11-06 03:24:32 +02:00
|
|
|
|
cd "$PLANET_DIR"
|
|
|
|
|
|
2008-11-06 02:36:00 +02:00
|
|
|
|
if (( $VERBOSE == 0 )); then
|
|
|
|
|
echo >> "$LOG_DIR/$LOG_FILE" 2>&1
|
|
|
|
|
echo "starting new sync ($(date +"%d.%m.%Y, %H:%M"))" >> "$LOG_DIR/$LOG_FILE" 2>&1
|
|
|
|
|
echo "-----------------------------------------------------------" >> "$LOG_DIR/$LOG_FILE" 2>&1
|
|
|
|
|
"$PLANET_DIR/planet.py" "$PLANET_DIR/gezegen/config.ini" >> "$LOG_DIR/$LOG_FILE" 2>&1
|
|
|
|
|
echo "-----------------------------------------------------------" >> "$LOG_DIR/$LOG_FILE" 2>&1
|
|
|
|
|
else
|
|
|
|
|
echo
|
|
|
|
|
echo "starting new sync ($(date +"%d.%m.%Y, %H:%M"))"
|
|
|
|
|
echo "-----------------------------------------------------------"
|
|
|
|
|
"$PLANET_DIR/planet.py" "$PLANET_DIR/gezegen/config.ini"
|
|
|
|
|
echo "-----------------------------------------------------------"
|
|
|
|
|
fi
|
2008-11-05 01:19:37 +02:00
|
|
|
|
|
|
|
|
|
# if ended successfully delete the lock file
|
|
|
|
|
rm "$PLANET_DIR/$LOCK_FILE"
|