-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync_daemon
executable file
·45 lines (41 loc) · 1.31 KB
/
sync_daemon
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
#!/bin/bash
cd $(dirname $0)
export CWD=$(pwd)
export OWD=$(pwd)
export MIRRORROOT=/home/mirror/mirrordata
export LOGROOT=/home/mirror/mirrorlog
export STATUSROOT=/home/mirror/mirrorweb/status/
export WEBROOT=/home/mirror/mirrorweb
export SCRIPTROOT=/home/mirror/scripts
export KVDBROOT=/home/mirror/statuskv
export DISTRO=$1
mkdir -p "$MIRRORROOT/$1"
mkdir -p "$LOGROOT/$1"
NOW=$(date +%s)
NEXT=$(cat "$STATUSROOT/$1.json" | python -c 'import json;p=json.loads(raw_input());print "nextsync" in p and p["nextsync"] or -1')
if [[ "$NEXT" -ge "$NOW" ]]; then
WAIT=$((NEXT-NOW))
sleep $WAIT
fi
while true; do
# for ((i=13;i>=0;i--)); do
# j=$((i+1))
# mv "$LOGROOT/$1/sync_core.log.$i" "$LOGROOT/$1/sync_core.log.$j"
# done
# mv "$LOGROOT/$1/sync_core.log" "$LOGROOT/$1/sync_core.log.0"
# bash -x ./sync_core $1 >& "$LOGROOT/$1/sync_core.log"
bash -x ./sync_core $1 2>&1
if [[ $? != 0 ]]; then
echo "($1) CORE CORRUPTION DETECTED!!! SLEEPING 60 SECONDS..."
sleep 60
continue
fi
NEXTSYNC=$(cat "$STATUSROOT/$1.json" | python -c 'import json;p=json.loads(raw_input());print "nextsync" in p and p["nextsync"] or -1')
NOW=`date +%s`
SLEEPTIME=$((NEXTSYNC-NOW))
if [[ "$SLEEPTIME" -le "0" ]]; then
continue
else
sleep "$SLEEPTIME"
fi
done