LoginSignup
2
2

More than 5 years have passed since last update.

Elastic Beanstalkのdeploy時にswaponを有効にする

Last updated at Posted at 2014-08-02

EC2インスタンスはデフォルトではswaponが無効でt1.microだとdeployスクリプトの実行時oomで落ちることがあったのでswaponを組み込んでみることにした。
.ebextensions/01_swapon.configにswapon設定を書く。

commands:
  01_swapon:
    command: |
      SWAPFILENAME=/swap.img
      test -e $SWAPFILENAME && exit 0
      MEMSIZE=`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`
      if [ $MEMSIZE -lt 2097152 ]; then
        SIZE=$((MEMSIZE * 2))k
      elif [ $MEMSIZE -lt 8388608 ]; then
        SIZE=${MEMSIZE}k
      elif [ $MEMSIZE -lt 67108864 ]; then
        SIZE=$((MEMSIZE / 2))k
      else
        SIZE=4194304k
      fi
      fallocate -l $SIZE $SWAPFILENAME && mkswap $SWAPFILENAME && chmod 0600 $SWAPFILENAME && swapon $SWAPFILENAME
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2