Skip to content

Instantly share code, notes, and snippets.

@lbland94
Last active September 14, 2020 21:06
Show Gist options
  • Select an option

  • Save lbland94/f7d9d362d67fdc71e2251f4ce47d4d89 to your computer and use it in GitHub Desktop.

Select an option

Save lbland94/f7d9d362d67fdc71e2251f4ce47d4d89 to your computer and use it in GitHub Desktop.
Scripts to make launching AEM server easier.

Instructions

  1. Install AEM and place the crx-quickstart folder, AEM_X.X_Quickstart.jar file, and license.properties file in /usr/local/bin/aem.
  2. Place the aem-server file in /usr/local/bin/ (or anywhere included in your PATH).
  3. Add the following line to your .bashrc: complete -W 'quickstart log stop start status install restart cleanup' 'aem-server'

You should now be able to run aem-server with a start, stop, log, install, or quickstart command with autocomplete.

#!/bin/bash
## Ensure that java 8 is being used
export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"
export PATH=$JAVA_HOME/bin:$PATH
function timeout() {
perl -e 'alarm shift; exec @ARGV' "$@"
}
function returnsCode() {
local url=${1:-http://localhost:4502}
local code=${2:-500}
local status=$(curl --head --location --connect-timeout 5 --write-out %{http_code} --silent --output /dev/null ${url})
[[ $status == ${code} ]]
}
export -f returnsCode
if [ "$1" == "quickstart" ]; then
/usr/local/bin/aem/crx-quickstart/bin/quickstart > /dev/null 2>&1 & disown
fi
if [ "$1" == "stop" ]; then
/usr/local/bin/aem/crx-quickstart/bin/stop
timeout 60 bash -c 'until returnsCode http://localhost:4502 000; do sleep 0.5; done'
fi
if [ "$1" == "start" ]; then
/usr/local/bin/aem/crx-quickstart/bin/start
timeout 60 bash -c 'until returnsCode http://localhost:4502 401; do sleep 0.5; done'
fi
if [ "$1" == "status" ]; then
/usr/local/bin/aem/crx-quickstart/bin/status
fi
if [ "$1" == "log" ]; then
tail -f /usr/local/bin/aem/crx-quickstart/logs/error.log
fi
if [ "$1" == "install" ]; then
cp "${@:2}" /usr/local/bin/aem/crx-quickstart/install/
fi
if [ "$1" == "restart" ]; then
/usr/local/bin/aem/crx-quickstart/bin/stop
timeout 60 bash -c 'until returnsCode http://localhost:4502 000; do sleep 0.5; done'
/usr/local/bin/aem/crx-quickstart/bin/start
timeout 60 bash -c 'until returnsCode http://localhost:4502 401; do sleep 0.5; done'
fi
if [ "$1" == "cleanup" ]; then
/usr/local/bin/aem/crx-quickstart/bin/stop
timeout 60 bash -c 'until returnsCode http://localhost:4502 000; do sleep 0.5; done'
java -jar /usr/local/bin/aem/oak-run-1.6.6.jar checkpoints /usr/local/bin/aem/crx-quickstart/repository/segmentstore
java -jar /usr/local/bin/aem/oak-run-1.6.6.jar checkpoints /usr/local/bin/aem/crx-quickstart/repository/segmentstore rm-unreferenced
java -jar /usr/local/bin/aem/oak-run-1.6.6.jar compact /usr/local/bin/aem/crx-quickstart/repository/segmentstore
/usr/local/bin/aem/crx-quickstart/bin/start
timeout 60 bash -c 'until returnsCode http://localhost:4502 401; do sleep 0.5; done'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment