-
Notifications
You must be signed in to change notification settings - Fork 8
/
aem-mgr.sh
executable file
·200 lines (179 loc) · 5.13 KB
/
aem-mgr.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
# a script to make it easier for developers to start multiple AEM instances
# Default Settings
instance=default
root=~/dev/aem
publish=
debug="true"
gui=-gui
vmargs="-Xmx2g -XX:MaxPermSize=512m"
debugport=30303
jmxport=9999
port=4502
action="start"
function help
{
usage
echo ""
echo "---Actions---"
echo " compact - compacts the oak repository"
echo " reset - deletes the contents of the crx-quickstart folder"
echo " start - Starts the specified AEM"
echo " stop - stops the specified AEM instance"
echo ""
echo "---Parameters---"
echo "-i | --instance - Sets the AEM instance to use, will be a sub-folder of the root folder"
echo "-vm | --vm-args - Arguments passed to the JVM"
echo "-r | --root - Sets root directory under which the script will look for AEM instances"
echo "--port - Specify the port on which to start AEM"
echo "-p | --publish - Starts publish instances. These instances are assumed to be folders under the root with names like [instance]-publish-[NN] or [instance]-publish"
echo "-ng | --no-gui - Flag for not starting AEM's GUI"
echo "-nd | --no-debug - Flag for not starting AEM in debug mode"
echo "-h | --help - Displays this message"
}
function compact
{
today="$(date +'%d-%m-%Y')"
repodir="$aemdir/crx-quickstart/repository"
oakrun="$aemdir/help/oak-run-*.jar"
logfile="$aemdir/help/logs/compact-$today.log"
mkdir -p $aemdir/help/logs
repospace=$(du -hs $repodir)
echo "Pre-compaction repository size: ${repospace}..."
echo "Finding old checkpoints..."
java -Dtar.memoryMapped=true -Xmx2g -jar $oakrun checkpoints $repodir/segmentstore >> $logfile
echo "Deleting unreferenced checkpoints..."
java -Dtar.memoryMapped=true -Xmx2g -jar $oakrun checkpoints $repodir/segmentstore rm-unreferenced >> $logfile
echo "Running compaction. This may take a while..."
java -Dtar.memoryMapped=true -Xmx2g -jar $oakrun compact $repodir/segmentstore >> $logfile
echo "Compaction complete. Please check the log at: $logfile"
repospace=$(du -hs $repodir)
echo "Post-compaction repository size: ${repospace}..."
}
function resetaem
{
echo "Clearing AEM repository at $aemdir"
rm -rf $aemdir/crx-quickstart
echo "Repository successfully cleared"
}
function startaem
{
aemjar=$(ls $aemdir | grep -m 1 ^.*aem.*\.jar$)
if [ "$aemjar" = "" ]; then
aemjar=$(ls $aemdir | grep -m 1 ^.*cq.*\.jar$)
fi
if [ "$aemjar" = "" ]; then
echo "No AEM JAR found in $aemdir"
exit 1
fi
cd $aemdir
echo "Clearing logs"
rm -f $aemdir/crx-quickstart/logs/*
mkdir -p $aemdir/crx-quickstart/logs
mkdir -p $aemdir/crx-quickstart/conf
echo "Starting AEM instance $instance"
echo "Using JAR $aemjar"
if [ "$debug" = "true" ]; then
echo "Using Debug Port $debugport"
echo "Using JMX Port $jmxport"
java -Xdebug $vmargs -Xrunjdwp:transport=dt_socket,server=y,address=$debugport,suspend=n -Dcom.sun.management.jmxremote.port=$jmxport -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar $aemjar $gui -nofork -port $port &
echo $! > $aemdir/crx-quickstart/conf/cq.pid
else
java $vmargs -jar $aemjar $gui -nofork -port $port &
echo $! > $aemdir/crx-quickstart/conf/cq.pid
fi
echo "AEM Instance $instance Started Successfully!"
}
function stopaem
{
echo "Stopping AEM"
$aemdir/crx-quickstart/bin/stop
echo "AEM Stop Command Issued Successfully"
}
function usage
{
echo "usage: aem-mgr [start|stop|reset|compact] [-i aem-instance] [-r root-path] [-p] [-vm '-Xmx2g'] [-nd]"
}
# Parse the command line arguments from the parameters
while [ "$1" != "" ]; do
case $1 in
-i | --instance ) shift
instance=$1
;;
-vm | --vm-args ) shift
vmargs=$1
;;
-r | --root ) shift
root=$1
;;
-p | --publish ) publish="1"
;;
--port ) shift
port=$1
;;
-ng | --no-gui ) gui=
;;
-nd | --no-debug ) debug="false"
;;
-h | --help ) help
exit
;;
compact ) action="compact"
;;
reset ) action="reset"
;;
start ) action="start"
;;
stop ) action="stop"
;;
* ) usage
exit 1
esac
shift
done
# Perform the actions
if [ "$action" = "compact" ]; then
aemdir=$root/$instance
compact
if [ "$publish" = "1" ]; then
ls $root | grep ^$instance-publish.*$ | while read pub
do
aemdir=$root/$pub
compact
done
fi
elif [ "$action" = "start" ]; then
aemdir=$root/$instance
startaem
if [ "$publish" = "1" ]; then
ls $root | grep ^$instance-publish.*$ | while read pub
do
debugport=$(expr $debugport + 1)
jmxport=$(expr $jmxport + 1)
port=$(expr $port + 1)
jmxport=$(expr $jmxport + 1)
aemdir=$root/$pub
startaem
done
fi
elif [ "$action" = "reset" ] ; then
aemdir=$root/$instance
resetaem
if [ "$publish" = "1" ]; then
ls $root | grep ^$instance-publish.*$ | while read pub
do
aemdir=$root/$pub
resetaem
done
fi
elif [ "$action" = "stop" ] ; then
aemdir=$root/$instance
stopaem
if [ "$publish" = "1" ]; then
ls $root | grep ^$instance-publish.*$ | while read pub
do
aemdir=$root/$pub
stopaem
done
fi
fi