X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=discourse-setup;h=45c769670f3a091e589af822d3b18c3b102b87a3;hb=12fa363b246e310b7265226427513e90200f1e3c;hp=9526330af99d733b348cb86a94b462ce0f366eb6;hpb=b6c9911650c5d15c56a57fefa0e98ca08420ebc8;p=discourse_docker.git diff --git a/discourse-setup b/discourse-setup index 9526330..45c7696 100755 --- a/discourse-setup +++ b/discourse-setup @@ -10,12 +10,57 @@ check_root() { fi } + +## +## Do we have docker? +## +check_and_install_docker () { + docker_path=`which docker.io || which docker` + if [ -z $docker_path ]; then + read -p "Docker not installed. Enter to install from https://get.docker.com/ or Ctrl+C to exit" + curl https://get.docker.com/ | sh + fi + docker_path=`which docker.io || which docker` + if [ -z $docker_path ]; then + echo Docker install failed. Quitting. + exit + fi +} + +## +## What are we running on +## +check_OS() { + echo `uname -s` +} + +## +## OS X available memory +## +check_osx_memory() { + echo `top -l 1 | awk '/PhysMem:/ {print $2}' | sed s/G//` +} + +## +## Linux available memory +## +check_linux_memory() { + echo `free -g --si | awk ' /Mem:/ {print $2} '` +} + ## ## Do we have enough memory and disk space for Discourse? ## check_disk_and_memory() { - avail_mem=`free -g --si | awk ' /Mem:/ {print $2} '` + os_type=$(check_OS) + avail_mem=0 + if [ $os_type == "Darwin" ]; then + avail_mem=$(check_osx_memory) + else + avail_mem=$(check_linux_memory) + fi + if [ "$avail_mem" -lt 1 ]; then echo "WARNING: Discourse requires 1GB RAM to run. This system does not appear" echo "to have sufficient memory." @@ -25,11 +70,11 @@ check_disk_and_memory() { exit 1 fi - if [ "$avail_mem" -lt 2 ]; then + if [ "$avail_mem" -le 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 "WARNING: Discourse requires at least 2GB of swap when running with 2GB of RAM" + echo "or less. 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." @@ -82,8 +127,16 @@ scale_ram_and_cpu() { local changelog=/tmp/changelog.$PPID # grab info about total system ram and physical (NOT LOGICAL!) CPU cores - avail_gb="$(LANG=C free -g --si | grep '^Mem:' | awk '{print $2}')" - avail_cores=`cat /proc/cpuinfo | grep "cpu cores" | uniq | awk '{print $4}'` + avail_gb=0 + avail_cores=0 + os_type=$(check_OS) + if [ $os_type == "Darwin" ]; then + avail_gb=$(check_osx_memory) + avail_cores=`sysctl hw.ncpu | awk '/hw.ncpu:/ {print $2}'` + else + avail_gb=$(check_linux_memory) + avail_cores=$((`awk '/cpu cores/ {print $4;exit}' /proc/cpuinfo`*`sort /proc/cpuinfo | uniq | grep -c "physical id"`)) + fi echo "Found ${avail_gb}GB of memory and $avail_cores physical CPU cores" # db_shared_buffers: 128MB for 1GB, 256MB for 2GB, or 256MB * GB, max 4096MB @@ -426,6 +479,7 @@ changelog=/tmp/changelog ## Check requirements before creating a copy of a config file we won't edit ## check_root +check_and_install_docker check_disk_and_memory check_ports