From 8f70d4502c1d4c11a60531e2ca3e575262517c25 Mon Sep 17 00:00:00 2001 From: Jeff Atwood Date: Wed, 27 Apr 2016 15:47:46 -0700 Subject: [PATCH] add auto swap creation --- discourse-setup | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/discourse-setup b/discourse-setup index 3a49c8f..1adb2eb 100755 --- a/discourse-setup +++ b/discourse-setup @@ -21,10 +21,28 @@ check_disk_and_memory() { echo "WARNING: Discourse requires at least 1GB 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, or future" + echo "Without sufficient swap space, your site may not work properly, and future" echo "upgrades of Discourse may not complete successfully." echo - echo "See https://meta.discourse.org/t/13880" + read -p "Press ENTER to create a 2GB swapfile automatically, or Ctrl-C to exit" + + ## + ## derived from https://meta.discourse.org/t/13880 + ## + install -o root -g root -m 0600 /dev/null /swapfile + dd if=/dev/zero of=/swapfile bs=1k count=2048k + mkswap /swapfile + swapon /swapfile + echo "/swapfile swap swap auto 0 0" | sudo tee -a /etc/fstab + sudo sysctl -w vm.swappiness=10 + echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf + + total_swap="$(LANG=C free -m | grep ^Swap: | awk '{print $2}')" + if [ "$total_swap" -lt 1000 ]; then + echo "Failed to create swap, sorry!" + exit 1 + fi + fi fi @@ -399,4 +417,4 @@ validate_config ## if we reach this point without exiting, OK to proceed ## ./launcher bootstrap $app_name -./launcher start $app_name \ No newline at end of file +./launcher start $app_name -- 2.25.1