少しはまったのでメモ
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