Fix memory check to not account for 'free' memory
authorMatt Palmer <mpalmer@hezmatt.org>
Mon, 14 Sep 2015 23:12:01 +0000 (09:12 +1000)
committerMatt Palmer <mpalmer@hezmatt.org>
Mon, 14 Sep 2015 23:12:01 +0000 (09:12 +1000)
Previous, 'clever' check didn't take into account the possibility
of Discourse already running.

launcher

index b0ca3102af1dc5a02be292f53a0500b070773b81..7475cf62c1cff3a26d041b74ada896a75046bd17 100755 (executable)
--- a/launcher
+++ b/launcher
@@ -155,25 +155,21 @@ prereqs() {
   # 6. sufficient available resources
   # 6a. Memory
   #
-  # This was disable cause we always need to minus the memory of running containers from
-  # this total, this is fairly hard to do without docker stat and in particular some patches
-  # to it.
-  #
-  # free_mem="$(LANG=C free -m | grep 'buffers/cache' | awk '{print $4}')"
-  # if [ "$free_mem" -lt 800 ]; then
-  #   echo "You do not appear to have sufficient memory to run Discourse."
-  #   echo
-  #   echo "See https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md#create-new-cloud-server"
-  #   exit 1
-  # elif [ "$free_mem" -lt 1800 ]; then
-  #   total_swap="$(LANG=C free -m | grep ^Swap: | awk '{print $2}')"
-  #   if [ "$total_swap" -lt 1000 ]; then
-  #     echo "You must have at least 1GB of swap when running in a low-memory environment."
-  #     echo
-  #     echo "See https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md#set-up-swap-if-needed"
-  #     exit 1
-  #   fi
-  # fi
+  avail_mem="$(LANG=C free -m | grep '^Mem:' | awk '{print $2}')"
+  if [ "$avail_mem" -lt 1000 ]; then
+    echo "You do not appear to have sufficient memory to run Discourse."
+    echo
+    echo "See https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md#create-new-cloud-server"
+    exit 1
+  elif [ "$avail_mem" -lt 2000 ]; then
+    total_swap="$(LANG=C free -m | grep ^Swap: | awk '{print $2}')"
+    if [ "$total_swap" -lt 1000 ]; then
+      echo "You must have at least 1GB of swap when running with less than 2GB of RAM."
+      echo
+      echo "See https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md#set-up-swap-if-needed"
+      exit 1
+    fi
+  fi
 
   # 6b. Disk space
   free_disk="$(df /var | tail -n 1 | awk '{print $4}')"