-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcompact.sh
73 lines (56 loc) · 1.91 KB
/
compact.sh
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
#Configure the base directory for AEM
aemdir=/opt/aem
## Don't configure past this point
if [ ! -z "$1" ]
then
aemdir=$1
echo "Using $aemdir as base directory..." | tee -a $logfile
fi
today="$(date +'%Y-%m-%d')"
compactdir="$aemdir/help"
crxdir="$aemdir/crx-quickstart"
oakrun="$compactdir/oak-run-*.jar"
logfile="$compactdir/logs/compact-$today.log"
function compact
{
repospace=$(du -hs $crxdir/repository)
echo "Pre-compaction repository size: ${repospace}..." | tee -a $logfile
echo "Finding old checkpoints..." | tee -a $logfile
java -Dtar.memoryMapped=true -Xmx8g -jar $oakrun checkpoints $crxdir/repository/segmentstore >> $logfile
echo "Deleting unreferenced checkpoints..."
java -Dtar.memoryMapped=true -Xmx8g -jar $oakrun checkpoints $crxdir/repository/segmentstore rm-unreferenced >> $logfile
echo "Running compaction. This may take a while..."
java -Dtar.memoryMapped=true -Xmx8g -jar $oakrun compact $crxdir/repository/segmentstore >> $logfile
echo "Compaction complete. Please check the log at: $logfile" | tee -a $logfile
echo "Restarting AEM..." | tee -a $logfile
$crxdir/bin/start
echo "Compaction complete!" | tee -a $logfile
repospace=$(du -hs $crxdir/repository)
echo "Post-compaction repository size: ${repospace}..." | tee -a $logfile
exit 0
}
mkdir -p $compactdir/logs
echo "" > $logfile
echo "Running Compaction on $today" | tee -a $logfile
echo "Stopping AEM..." | tee -a $logfile
$crxdir/bin/stop >> $logfile
COUNTER=0
while [ $COUNTER -lt 30 ]; do
echo "Checking if AEM Running..." | tee -a $logfile
sleep 60
if [ -f $FILE ]; then
if pgrep -F $crxdir/conf/cq.pid > /dev/null 2>&1
then
echo "AEM still running..." | tee -a $logfile
else
echo "AEM Stopped, running compaction." | tee -a $logfile
compact
fi
else
echo "PID file not found, running compaction." | tee -a $logfile
compact
fi
done
echo "AEM Failed to stop in allotted time, exiting..."
exit 1