Skip to content

Instantly share code, notes, and snippets.

@xpepper
Last active October 24, 2024 14:56
Show Gist options
  • Save xpepper/9dd299e2a1699cbde26f7f14209d5b5b to your computer and use it in GitHub Desktop.
Save xpepper/9dd299e2a1699cbde26f7f14209d5b5b to your computer and use it in GitHub Desktop.
Start / stop Rancher Desktop (on macOS)
#!/bin/bash
# Default action is 'start'
ACTION="${1:-start}"
POST_START_COMMAND="$2"
if [ "$ACTION" == "start" ]; then
# Check if Rancher Desktop is already running
if docker ps &> /dev/null; then
echo "Rancher Desktop is already running."
else
# Start Rancher Desktop
rdctl start
# Check if Rancher Desktop is ready
SECONDS_WAITED=0
while true; do
# Run docker ps to see if Docker daemon is running
if docker ps &> /dev/null; then
echo -e "\rRancher Desktop is ready. "
break
else
echo -ne "\rWaiting for Rancher Desktop to be ready... (${SECONDS_WAITED}s)"
SECONDS_WAITED=$((SECONDS_WAITED + 2))
sleep 2
fi
done
# Run post-start command if provided
if [ -n "$POST_START_COMMAND" ]; then
echo "Running post-start command: $POST_START_COMMAND"
eval "$POST_START_COMMAND"
fi
fi
elif [ "$ACTION" == "stop" ]; then
# Shutdown Rancher Desktop
rdctl shutdown
# Check if Rancher Desktop is fully shut down
SECONDS_WAITED=0
while true; do
# Run docker ps to check if Docker daemon is still running
if docker ps &> /dev/null; then
echo -ne "\rWaiting for Rancher Desktop to shut down... (${SECONDS_WAITED}s)"
SECONDS_WAITED=$((SECONDS_WAITED + 2))
sleep 2
else
echo -e "\rRancher Desktop has shut down. "
break
fi
done
else
echo "Invalid action. Please use 'start' or 'stop'."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment