3

I have a AWS Elastic beanstalk app with ruby/puma configured. I see this in the instance's /etc/init. A puma.conf file with

$ cat /etc/init/puma.conf
description "Elastic Beanstalk Puma 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 grep -eq 'true' /etc/elasticbeanstalk/has_puma.txt; then
    exec su -s /bin/bash -c "bundle exec puma -C $EB_SUPPORT_DIR/conf/pumaconf.rb" webapp
  else
    exec su -s /bin/bash -c "puma -C $EB_SUPPORT_DIR/conf/pumaconf.rb" webapp
  fi
EOF
end script

Is it just me or is this broken? Running the if condition(grep -eq 'true' /etc/elasticbeanstalk/has_puma.txt;) in the terminal throws an error. As does just running the entire if block. /etc/elasticbeanstalk/has_puma.txt contains one word true.

We discovered this because we were facing subtle app level issues which went away when we used bundle exec.

I was able to fix that by modifying the puma.conf thus,

$ cat /etc/init/puma.conf 
description "Elastic Beanstalk Puma Upstart Manager"
EB_SUPPORT_DIR=/opt/elasticbeanstalk/support
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

  exec su -s /bin/bash -c "cd /var/app/current && bundle exec puma -C $EB_SUPPORT_DIR/conf/pumaconf.rb" webapp
EOF
end script

I had to add the cd for it to work.. not too sure about it.

So is this a bug with the elastic beanstalk system? Is this fix correct or is there a cleaner/better way to achieve this?

Karthik T
  • 31,456
  • 5
  • 68
  • 87

0 Answers0