start 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env bash
  2. set -o errexit
  3. MEM=$(docker info | grep "Total Memory" | cut -d':' -f2 | xargs | sed s/GiB//)
  4. # Docker reports RAM 0.2 less than what it is actually set to
  5. (( $(echo "$MEM < 5.7" | bc -l) )) && echo "There must be at least 6GB of RAM allocated to Docker to continue." && exit
  6. if [ "$1" == "--no-dev" ]; then
  7. bin/docker-compose --no-dev up -d --remove-orphans "${@:2}"
  8. exit $?
  9. fi
  10. # Ref: https://stackoverflow.com/a/51789677/9821321
  11. function parseYaml {
  12. local s
  13. local w
  14. local fs
  15. s='[[:space:]]*'
  16. w='[a-zA-Z0-9_]*'
  17. fs=$(echo @|tr @ '\034')
  18. sed -ne "s|,$s\]$s\$|]|" \
  19. -e "s|^\($s\)\($w\)$s:$s\[$s\(.*\)$s\]|\1\2:\n\1 - \3|;p" "$1" | \
  20. sed -ne "s|,$s}$s\$|}|" \
  21. -e "s|^\($s\)-$s{$s\(.*\)$s}|\1-\n\1 \2|;p" | \
  22. sed -ne "s|^\($s\):|\1|" \
  23. -e "s|^\($s\)-$s{[\"']\(.*\)[\"']}$s\$|\1$fs$fs\2|p" \
  24. -e "s|^\($s\)-$s\(.*\)$s\$|\1$fs$fs\2|p" \
  25. -e "s|^\($s\)\($w\)$s:$s{[\"']\(.*\)[\"']}$s\$|\1$fs\2$fs\3|p" \
  26. -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" | \
  27. awk -F"$fs" '{
  28. indent = length($1)/2;
  29. vname[indent] = $2;
  30. for (i in vname) {if (i > indent) {delete vname[i]; idx[i]=0}}
  31. if (length($2) == 0) {vname[indent] = ++idx[indent] };
  32. if (length($3) > 0) {
  33. vn=""; for (i=0; i<indent; i++) {vn = (vn)(vname[i])("_")}
  34. if ("'"$2"'_" == vn) {
  35. print substr($3 ,1 , match($3,":")-1)
  36. }
  37. }
  38. }'
  39. }
  40. # Check if volume files exist to avoid creating an empty folder
  41. VOLUME_LIST=$(parseYaml compose.dev.yaml services_app_volumes)
  42. IGNORE_LIST="./src/app/code ./src/m2-hotfixes ./src/patches ./src/var/log ./src/var/report ./src"
  43. IS_VALID=true
  44. # Loop through all files missing from the compose.dev.yaml file
  45. for file in $VOLUME_LIST; do
  46. if [[ ! -e $file && " $IGNORE_LIST " != *" $file "* ]]; then
  47. echo "$file: No such file or directory"
  48. IS_VALID=false
  49. fi
  50. done
  51. # Wait to exit until all missing files have been outputted to the user
  52. [ $IS_VALID = false ] && echo "Failed to start docker for missing volume files" && exit
  53. bin/docker-compose up -d --remove-orphans "$@"
  54. ## Blackfire support
  55. ## ------------------
  56. ## First register the blackfire agent with:
  57. #bin/root blackfire-agent --register --server-id={YOUR_SERVER_ID} --server-token={YOUR_SERVER_TOKEN}
  58. ## Then uncomment the below line (and leave uncommented) to start the agent automatically with bin/start:
  59. #bin/root /etc/init.d/blackfire-agent start
  60. # Check if cron was previously enabled and restart it if needed
  61. if bin/cli test -f /var/www/html/var/.cron-enabled; then
  62. echo "Cron was previously enabled, restarting cron service..."
  63. bin/cron start
  64. fi
  65. bin/cache-clean --watch