shutdown_nextcloud.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/bash
  2. # Script to shut down a list of Docker containers in non-interactive mode
  3. # Array of container IDs or names (modify this array as needed)
  4. CONTAINERS=(
  5. "nc6"
  6. "nc6_govod"
  7. "nc6_cron"
  8. "nc6_db"
  9. "nc6_es"
  10. "nc6_clamav"
  11. "nc6_onlyoffice"
  12. "nc6_redis"
  13. )
  14. # Function to check if a command was successful
  15. check_status() {
  16. if [ $? -ne 0 ]; then
  17. echo "Error: $1 failed. Exiting."
  18. exit 1
  19. fi
  20. }
  21. # Step 1: Process each container in the array
  22. if [ ${#CONTAINERS[@]} -gt 0 ]; then
  23. echo "Processing specified containers..."
  24. for CONTAINER in "${CONTAINERS[@]}"; do
  25. # Check if the container exists
  26. echo "Checking if container '$CONTAINER' exists..."
  27. docker ps -a --filter "name=$CONTAINER" --format '{{.Names}}' | grep -q "^$CONTAINER$"
  28. if [ $? -ne 0 ]; then
  29. echo "Warning: Container '$CONTAINER' does not exist. Skipping."
  30. continue
  31. fi
  32. # Stop the container
  33. echo "Stopping container '$CONTAINER'..."
  34. docker stop "$CONTAINER"
  35. check_status "Stopping container '$CONTAINER'"
  36. # Remove the container
  37. #echo "Removing container '$CONTAINER'..."
  38. #docker rm "$CONTAINER"
  39. #check_status "Removing container '$CONTAINER'"
  40. done
  41. else
  42. echo "Error: No containers specified in the array. Exiting."
  43. exit 1
  44. fi
  45. echo "All specified containers have been successfully shut down and removed."