Last active
March 20, 2025 11:03
-
-
Save rwunsch/7cc4e299221e4dbf6a7cfb466a8b9f09 to your computer and use it in GitHub Desktop.
AEM Cloud Services SDK - Local Stop Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Define the AEM role (set this to "author" or "publish") | |
| aem_role="author" | |
| # Default behavior for repository deletion (unset when no parameter is given) | |
| delete_repo="" | |
| # Check for parameter input | |
| if [ $# -gt 0 ]; then | |
| if [[ "$1" == "y" || "$1" == "Y" ]]; then | |
| delete_repo="y" | |
| elif [[ "$1" == "n" || "$1" == "N" ]]; then | |
| delete_repo="n" | |
| else | |
| echo "Invalid parameter. Use 'y' for yes or 'n' for no." | |
| exit 1 | |
| fi | |
| fi | |
| # Check for AEM process with the specified role | |
| java_pid=$(ps aux | grep -E -i "java.* -jar .*(aem-.*\.jar|cq-quickstart.*\.jar).* -r$aem_role(,| )" | grep -v "grep" | awk '{print $2}' | head -n 1) | |
| if [ -n "$java_pid" ]; then | |
| kill -15 "$java_pid" | |
| echo "Sent SIGTERM to AEM $aem_role process with PID $java_pid" | |
| # Monitor AEM process shutdown | |
| echo "AEM $aem_role process with PID $java_pid is still running..." | |
| while ps -p "$java_pid" > /dev/null; do | |
| echo -n "." | |
| sleep 1 | |
| done | |
| echo "AEM $aem_role process with PID $java_pid is no longer running." | |
| else | |
| echo "No AEM $aem_role process running." | |
| fi | |
| # Check for glogg process | |
| glogg_pid=$(ps aux | grep -E -i "glogg" | grep -v "grep" | awk '{print $2}' | head -n 1) | |
| if [ -n "$glogg_pid" ]; then | |
| kill -15 "$glogg_pid" | |
| echo "Sent SIGTERM to glogg process with PID $glogg_pid" | |
| while ps -p "$glogg_pid" > /dev/null; do | |
| echo -n "." | |
| sleep 1 | |
| done | |
| echo "glogg process with PID $glogg_pid is no longer running." | |
| else | |
| echo "No glogg process running." | |
| fi | |
| # Function to show countdown timer | |
| countdown_timer() { | |
| for i in {5..1}; do | |
| echo -ne "\rTime remaining: $i seconds... Press 'y' to delete. " | |
| sleep 1 | |
| done | |
| echo -ne "\rTime is up! Proceeding without deletion. \n" | |
| } | |
| # Handle repository deletion with a 5-second countdown | |
| if [ -z "$delete_repo" ]; then | |
| echo "Do you want to delete the 'crx-quickstart' folder? (y to confirm, any other key to cancel)" | |
| # Start the countdown in the background | |
| countdown_timer & | |
| # Read user input with a timeout of 5 seconds | |
| read -t 5 -n 1 response | |
| echo "" # Move to a new line after input | |
| # Kill the countdown if input is received early | |
| kill $! 2>/dev/null | |
| wait $! 2>/dev/null | |
| # Check response | |
| if [[ "$response" == "y" || "$response" == "Y" ]]; then | |
| delete_repo="y" | |
| else | |
| delete_repo="n" | |
| fi | |
| fi | |
| # Delete the repository folder if required | |
| if [[ "$delete_repo" == "y" ]]; then | |
| if [ -d "crx-quickstart" ]; then | |
| rm -rf crx-quickstart | |
| echo "'crx-quickstart' folder deleted." | |
| else | |
| echo "'crx-quickstart' folder does not exist." | |
| fi | |
| else | |
| echo "Folder not deleted." | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment