10
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Elastic Beanstalk でデプロイ後のフックで delayed_job 等を実行する (Ruby 2.1 (Puma))

Last updated at Posted at 2015-01-03

Elastic Beanstalk の Configuration を
64bit Amazon Linux 2014.03 v1.0.9 running Ruby 2.1 (Puma) にした際に
64bit Amazon Linux 2014.02 running Ruby 1.9.3 で使っていた方法ではエラーが出たのでメモ。
(どのバージョンから変更になったのかはわかりません)

従来通り Elastic Beansgtalk 環境の /opt/elasticbeanstalk/hooks/appdeploy/post/ 以下に、
デプロイ後実行されるスクリプトが配置されるように .ebextensions 以下の設定を行うのは同じだが、
以下の点で既存の設定に修正が必要になった。

  • 環境変数は . /opt/elasticbeanstalk/containerfiles/envvars で読み込む
  • source $EB_ROOT/containerfiles/scripts/use-app-ruby.sh でフック内で使用する ruby を設定
.ebextensions/99_delayed_job.config
commands:
  create_post_dir:
    command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
    ignoreErrors: true
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_delayed_job.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      # 以下2行が必要!!!
      . /opt/elasticbeanstalk/containerfiles/envvars 
      source $EB_ROOT/containerfiles/scripts/use-app-ruby.sh
      cd $EB_CONFIG_APP_CURRENT
      su -c "RAILS_ENV=production bin/delayed_job --pid-dir=$EB_CONFIG_APP_SUPPORT/pids restart" $EB_CONFIG_APP_USER

ちなみに 64bit Amazon Linux 2014.02 running Ruby 1.9.3 では、以下のように
envvars のパスが異なり、use-app-ruby.sh も不要でした。 

.ebextensions/99_delayed_job_old.config
commands:
  create_post_dir:
    command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
    ignoreErrors: true
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_delayed_job.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      # envvars のパスが違う
      . /opt/elasticbeanstalk/support/envvars 
      cd $EB_CONFIG_APP_CURRENT
      su -c "RAILS_ENV=production bin/delayed_job --pid-dir=$EB_CONFIG_APP_SUPPORT/pids -n 4 restart" $EB_CONFIG_APP_USER
10
6
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
10
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?