diff --git a/src/aem-lts/bin/aem-lts b/src/aem-lts/bin/aem-lts index d6455a0..877d021 100644 --- a/src/aem-lts/bin/aem-lts +++ b/src/aem-lts/bin/aem-lts @@ -79,8 +79,10 @@ IS_RUNNING=false case "${action}" in start) - ${IS_RUNNING} && aem_lts_err "AEM ${service} already running" - [[ -f "${PID_FILE}" ]] && sudo rm -f "${PID_FILE}" # remove stale pid file if present + if ! ${INTERACTIVE}; then + ${IS_RUNNING} && aem_lts_err "AEM ${service} already running" + [[ -f "${PID_FILE}" ]] && sudo rm -f "${PID_FILE}" # remove stale pid file if present + fi port=$(get_runmode_port ${service}) jvm_opts="-agentlib:jdwp=transport=dt_socket,address=*:3${port},server=y,suspend=n" @@ -89,7 +91,7 @@ case "${action}" in if ${INTERACTIVE}; then # run in foreground; CTRL+C to stop echo "Running in interactive mode, press CTRL+C to stop..." - ${JAVA_HOME}/bin/java ${jvm_opts} -jar "${jarFileLink}" ${cq_opts} + sudo sh -c "cd '$(dirname "${jarFileLink}")' && exec ${JAVA_HOME}/bin/java ${jvm_opts} -jar '${jarFileLink}' ${cq_opts}" else sudo start-stop-daemon --start --quiet --background --chuid root \ --make-pidfile --pidfile "${PID_FILE}" \ diff --git a/src/aem-lts/devcontainer-feature.json b/src/aem-lts/devcontainer-feature.json index a5f8bd5..83122d3 100644 --- a/src/aem-lts/devcontainer-feature.json +++ b/src/aem-lts/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "aem-lts", - "version": "1.2.0", + "version": "1.2.1", "name": "Adobe Experience Manager LTS", "description": "Setup author and publish services. Requires the AEM LTS quickstart jar and license details.", "options": { diff --git a/test/aem-lts/defaults-with-quickstart.sh b/test/aem-lts/defaults-with-quickstart.sh index cfa147f..a3eeef0 100644 --- a/test/aem-lts/defaults-with-quickstart.sh +++ b/test/aem-lts/defaults-with-quickstart.sh @@ -40,18 +40,27 @@ test_runmode() { check "${service}: no java process should be running" \ [ -z $(pgrep -x java) ] - # Test interactive mode: start in background, capture stdout, verify process runs, then kill it - INTERACTIVE_LOG=$(mktemp) - aem-lts start ${service} -i > ${INTERACTIVE_LOG} & - INTERACTIVE_PID=$! - check "${service}: interactive mode wait for server started on port ${port}" \ - timeout 10 bash -c "until grep -q 'Server started on port ${port}' ${INTERACTIVE_LOG} 2>/dev/null; do sleep 0.5; done" - check "${service}: interactive mode pid matches java process" \ - [ $(pgrep -P ${INTERACTIVE_PID} -x java) -eq $(pgrep -x java) ] - kill $(pgrep -P ${INTERACTIVE_PID} -x java) 2>/dev/null + # Test interactive mode (-i flag): verifies aem-lts starts java in the foreground. + # Since the test itself is non-interactive, we background the process with & and + # simulate a user CTRL+C by killing java and the shell wrapper explicitly. + # set +e is required because killing background jobs causes non-zero exit codes + # which would otherwise abort the test script due to set -e at the top. + set +e + aem-lts start ${service} -i & + INTERACTIVE_BG=$! # pid of the backgrounded aem-lts shell wrapper + check "${service}: interactive mode java process starts" \ + timeout 10 bash -c "until pgrep -x java > /dev/null; do sleep 0.5; done" + # java runs as root via sudo sh -c, so sudo pkill is required to send the signal + # kill INTERACTIVE_BG terminates the shell wrapper after java is gone + sudo pkill -x java 2>/dev/null + kill ${INTERACTIVE_BG} 2>/dev/null + wait ${INTERACTIVE_BG} 2>/dev/null # reap the background job to avoid zombies check "${service}: interactive mode java process stopped after kill" \ timeout 10 bash -c "until ! pgrep -x java > /dev/null; do sleep 0.5; done" - rm -f ${INTERACTIVE_LOG} + # ensures process is fully gone before returning so the next test_runmode call + # starts with a clean state + until ! pgrep -x java > /dev/null; do sleep 0.5; done + set -e } test_runmode author 4502