-run_memconfig(){
- if [ "$opt" != "--skip-prereqs" ] ; then
- check_resources
- fi
- if [ -f $config_file ]
- then
- cp $config_file $config_file.bak
- echo "Saving $config_file as $config_file.bak"
- else
- echo "Creating $config_file from $template_path"
- if [ ! -f $template_path ]
- then
- echo "$template_path is missing. Exiting."
- exit 1
- fi
- cp $template_path $config_file
- fi
-
- # get free mem
- avail_mem="$(LANG=C free -m | grep '^Mem:' | awk '{print $2}')"
- avail_gb=`expr $(($avail_mem / 950))`
- avail_cores=`grep -c processor /proc/cpuinfo`
- echo "Found $avail_mem (${avail_gb}GB), of memory and $avail_cores cores."
-
- # set db_shared_buffers: "128MB" (1GB) or 256MB * GB
- if [ "$avail_gb" -eq "1" ]
- then
- db_shared_buffers="128"
- else
- db_shared_buffers=`expr $avail_gb \* 256`
- fi
- echo -e "Setting db_shared_buffers to ${db_shared_buffers}GB\c"
- sed -i -e "s/^ db_shared_buffers:.*/ db_shared_buffers: \"${db_shared_buffers}GB\"/w $changelog" $config_file
- if [ -s $changelog ]
- then
- echo " successfully."
- rm $changelog
- else
- echo -e ". . . oops!\n---> db_shared_buffers not found in $config_file. Retaining defaults."
- fi
-
- # set db_work_mem: "10MB" * GB?
- db_work_mem=`expr $avail_gb \* 10`
- echo -e "Setting db_work_mem to $db_work_mem MB\c"
- sudo sed -i -e "s/^ db_work_mem:.*/ db_work_mem: \"${db_work_mem}MB\"/w $changelog" $config_file
- if [ -s $changelog ]
- then
- echo " successfully."
- rm $changelog
- else
- echo -e ". . . oops!\n---> db_work_mem not found in $config_file. Retaining defaults."
- fi
-
- # set UNICORN_WORKERS: 2*GB or 2*cores (the same on DO)
- if [ "$avail_gb" -le "2" ]
- then
- unicorn_workers=`expr $avail_gb \* 2`
- else
- unicorn_workers=`expr $avail_cores \* 2`
- fi
-
- echo -e "Setting UNICORN_WORKERS to $unicorn_workers\c"
- sed -i -e "s/^ UNICORN_WORKERS:.*/ UNICORN_WORKERS: ${unicorn_workers}/w $changelog" $config_file
- if [ -s $changelog ]
- then
- echo " successfully."
- rm $changelog
- else
- echo -e ". . . oops!\n---> UNICORN_WORKERS not found in $config_file. Retaining defaults.\n"
- fi
-}
-
-run_start(){