Fix code that tests for RAM and Swap size
[discourse_docker.git] / discourse-setup
index e78de5f549d246a785b2edd0e45e877184cc5c7c..69c5df5808ab434d2a5d44b6e10d1656ec793d1b 100755 (executable)
@@ -15,26 +15,26 @@ check_root() {
 ##
 check_disk_and_memory() {
   
-  avail_mem="$(LANG=C free -m | grep '^Mem:' | awk '{print $2}')"
-  if [ "$avail_mem" -lt 900 ]; then
+  avail_mem=`free -g --si | awk ' /Mem:/  {print $2} '`
+  if [ "$avail_mem" -lt 1 ]; then
     echo "WARNING: Discourse requires 1GB RAM to run. This system does not appear"
     echo "to have sufficient memory."
     echo
     echo "Your site may not work properly, or future upgrades of Discourse may not"
     echo "complete successfully."
-    exit 1
+    echo exit 1
   fi
     
-  if [ "$avail_mem" -lt 1800 ]; then
-    total_swap="$(LANG=C free -m | grep ^Swap: | awk '{print $2}')"
-    if [ "$total_swap" -lt 1000 ]; then
+  if [ "$avail_mem" -lt 2 ]; then
+    total_swap=`free -g --si | awk ' /Swap:/  {print $2} '`
+    if [ "$total_swap" -lt 2 ]; then
       echo "WARNING: Discourse requires at least 2GB of swap when running with less "
       echo "than 2GB of RAM. This system does not appear to have sufficient swap space."
       echo
       echo "Without sufficient swap space, your site may not work properly, and future"
       echo "upgrades of Discourse may not complete successfully."
       echo
-      read -p "ENTER to create a 2GB swapfile now, or Ctrl-C to exit"
+      read -p "ENTER to create a 2GB swapfile now, or Ctrl+C to exit"
       
       ##
       ## derived from https://meta.discourse.org/t/13880
@@ -47,8 +47,8 @@ check_disk_and_memory() {
       sysctl -w vm.swappiness=10
       echo vm.swappiness = 10 | tee -a /etc/sysctl.conf
 
-      total_swap="$(LANG=C free -m | grep ^Swap: | awk '{print $2}')"
-      if [ "$total_swap" -lt 1000 ]; then
+      total_swap=`free -g --si | awk ' /Swap:/ {print $2} '`
+      if [ "$total_swap" -lt 2 ]; then
         echo "Failed to create swap, sorry!"
         exit 1
       fi
@@ -56,6 +56,7 @@ check_disk_and_memory() {
     fi
   fi
 
+
   free_disk="$(df /var | tail -n 1 | awk '{print $4}')"
   if [ "$free_disk" -lt 5000 ]; then
     echo "WARNING: Discourse requires at least 5GB free disk space. This system"
@@ -81,8 +82,7 @@ scale_ram_and_cpu() {
 
   local changelog=/tmp/changelog.$PPID
   # grab info about total system ram and physical (NOT LOGICAL!) CPU cores
-  avail_mem="$(LANG=C free -m | grep '^Mem:' | awk '{print $2}')"
-  avail_gb=$(( $avail_mem / 950 ))
+  avail_gb="$(LANG=C free -g --si | grep '^Mem:' | awk '{print $2}')"
   avail_cores=`cat /proc/cpuinfo | grep "cpu cores" | uniq | awk '{print $4}'`
   echo "Found ${avail_gb}GB of memory and $avail_cores physical CPU cores"
 
@@ -273,7 +273,7 @@ ask_user_for_config() {
     fi
     
     echo ""
-    read -p "ENTER to continue, 'n' to try again, or ^C to exit: " config_ok
+    read -p "ENTER to continue, 'n' to try again, Ctrl+C to exit: " config_ok
   done
 
   sed -i -e "s/^  DISCOURSE_HOSTNAME:.*/  DISCOURSE_HOSTNAME: $hostname/w $changelog" $config_file
@@ -321,7 +321,7 @@ ask_user_for_config() {
     update_ok="n"
   fi
 
-  sed -i -e "s/^  #DISCOURSE_SMTP_PASSWORD:.*/  DISCOURSE_SMTP_PASSWORD: $smtp_password/w $changelog" $config_file
+  sed -i -e "s/^  #DISCOURSE_SMTP_PASSWORD:.*/  DISCOURSE_SMTP_PASSWORD: \"${smtp_password/\//\\/}\"/w $changelog" $config_file
   if [ -s $changelog ]
   then
       rm $changelog