LoginSignup
3
2

More than 5 years have passed since last update.

AWS Elastic BeanstalkのRuby環境でsidekiqを起動する場合

Last updated at Posted at 2015-10-20

少しはまったのでメモ

AWS Elastic BeanstalkのRuby環境でsidekiqを起動するupstart scriptを用意してcontainer_commandsから起動させる様にした。
deploy完了後に確認するとlogやpidファイルが/var/app/currentに吐き出されて無かった。
原因を調べてみたらcontainer_commandsが完了してからステージングディレクトリ(/var/app/ondeck)を/var/app/cuurentに置き換えてからpumaの再起動をかけていた。

/var/app/currentに置き換わった後にsidekiqを起動する必要があった。
puma起動は /opt/elasticbeanstalk/hooks/appdeploy/enact/02_restart_app_server.sh で実施していたので、/opt/elasticbeanstalk/hooks/appdeploy/enact/10_start_sidekiq.sh とかを作って対応することにした。

/etc/init/sidekiq.conf

puma.confをぱくった

description "Elastic Beanstalk Sidekiq Upstart Manager"

start on runlevel [2345]
stop on runlevel [!2345]

respawn

script
exec /bin/bash <<"EOF"
  EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
  EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir)
  . $EB_SUPPORT_DIR/envvars
  . $EB_SCRIPT_DIR/use-app-ruby.sh
  if [ -f /etc/elasticbeanstalk/set-ulimit.sh ]; then
    . /etc/elasticbeanstalk/set-ulimit.sh
  fi
  EB_APP_DEPLOY_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir)
  RACK_ENV=$(/opt/elasticbeanstalk/bin/get-config optionsettings -n aws:elasticbeanstalk:application:environment -o RACK_ENV)
  cd $EB_APP_DEPLOY_DIR
  exec su -s /bin/bash -c "bundle exec sidekiq --environment $RACK_ENV --config config/sidekiq.yml" webapp
EOF
end script

/opt/elasticbeanstalk/hooks/appdeploy/enact/10_start_sidekiq.sh

#!/usr/bin/env bash
set -ex
initctl restart sidekiq || initctl start sidekiq
3
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
3
2