rubyamazon-elastic-beanstalksinatrathin

Thin server on Elastic Beanstalk Runy 2.6 on AMI Linux V2


I'm trying to migrate my Sinatra App from the legacy Amazon Linux to V2 on Elastic Beanstalk using the Thin Server. The Thin Server refuses to start on deploy. However, it starts fine and works correctly if I manually start it as the webapp user with the command:

bundle exec thin start -R config.ru -e production -C config/thin.yml -V

Here are my configuration files:

.plaform/hooks/prebuild/02_set_permissioms.sh

#!/usr/bin/env bash

echo "Set permissions"
su -s /bin/bash -c "mkdir -p /var/run/thin"
su -s /bin/bash -c "mkdir -p /var/log/thin"
su -s /bin/bash -c "mkdir -p /var/log/thin/rotated"
chown -R webapp:webapp /var/run/thin
chown -R webapp:webapp /var/log/thin
chown -R webapp:webapp /var/log/thin/rotated

.plaform/hooks/03_symlink_pid.sh

#!/bin/bash

echo "Symlink thin PID to web PID"
set -xe
sudo ln -nsf /var/run/thin/thin.0.0.pid /var/pids/web.pid

.platform/nginx/conf.d/elasticbeanstalk-nginx-ruby-upstream.conf

upstream my_app {
  server unix:///var/run/thin/thin.0.sock;
}

Procfile

web: bundle exec thin start -R config.ru -e production -C config/thin.yml -V

config/thin/yml

---
chdir: /var/app/current
environment: production
address: 0.0.0.0
port: 9292
timeout: 30
log: /var/log/thin/thin.log
pid: /var/run/thin/thin.pid
max_conns: 1024
max_persistent_conns: 512
require: []
wait: 30
threadpool_size: 20
daemonize: true
socket: /var/run/thin/thin.sock
servers: 1

/var/log/messages

Jan 12 12:45:58 ip-adress systemd: Starting This is web daemon...
Jan 12 12:45:58 ip-adress systemd: Started This is web daemon.
Jan 12 12:45:58 ip-adress systemd: Reloading.
Jan 12 12:45:58 ip-adress systemd: Starting The nginx HTTP and reverse proxy server...
Jan 12 12:45:58 ip-adress nginx: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jan 12 12:45:58 ip-adress nginx: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jan 12 12:45:58 ip-adress systemd: Started The nginx HTTP and reverse proxy server.
Jan 12 12:45:58 ip-adress web: NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:45:58 ip-adress web: Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:45:58 ip-adress web: 2022-01-12 12:45:58 +0000 Starting server on /var/run/thin/thin.0.sock ...
Jan 12 12:45:58 ip-adress web: 2022-01-12 12:45:58 +0000 /opt/elasticbeanstalk/.rbenv/versions/2.6.9/bin/thin start --chdir="/var/app/current" --environment="production" --timeout=30 --log="/var/log/thin/thin.0.log" --pid="/var/run/thin/thin.0.pid" --max-conns=1024 --max-persistent-conns=512 --threadpool-size=20 --rackup="config.ru" --trace --daemonize --socket="/var/run/thin/thin.0.sock"
Jan 12 12:45:59 ip-adress healthd: Version 2 of the Ruby SDK will enter maintenance mode as of November 20, 2020. To continue receiving service updates and new features, please upgrade to Version 3. More information can be found here: https://aws.amazon.com/blogs/developer/deprecation-schedule-for-aws-sdk-for-ruby-v2/
Jan 12 12:45:59 ip-adress web: 2022-01-12 12:45:59 +0000 NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:45:59 ip-adress web: 2022-01-12 12:45:59 +0000 Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:45:59 ip-adress systemd: web.service holdoff time over, scheduling restart.
Jan 12 12:45:59 ip-adress systemd: Stopped This is web daemon.
Jan 12 12:45:59 ip-adress systemd: Starting This is web daemon...
Jan 12 12:45:59 ip-adress systemd: Started This is web daemon.
Jan 12 12:46:00 ip-adress web: NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:00 ip-adress web: Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:00 ip-adress web: 2022-01-12 12:46:00 +0000 Starting server on /var/run/thin/thin.0.sock ...
Jan 12 12:46:00 ip-adress web: 2022-01-12 12:46:00 +0000 /opt/elasticbeanstalk/.rbenv/versions/2.6.9/bin/thin start --chdir="/var/app/current" --environment="production" --timeout=30 --log="/var/log/thin/thin.0.log" --pid="/var/run/thin/thin.0.pid" --max-conns=1024 --max-persistent-conns=512 --threadpool-size=20 --rackup="config.ru" --trace --daemonize --socket="/var/run/thin/thin.0.sock"
Jan 12 12:46:00 ip-adress web: 2022-01-12 12:46:00 +0000 NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:00 ip-adress web: 2022-01-12 12:46:00 +0000 Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:01 ip-adress systemd: web.service holdoff time over, scheduling restart.
Jan 12 12:46:01 ip-adress systemd: Stopped This is web daemon.
Jan 12 12:46:01 ip-adress systemd: Starting This is web daemon...
Jan 12 12:46:01 ip-adress systemd: Started This is web daemon.
Jan 12 12:46:01 ip-adress web: NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:01 ip-adress web: Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:01 ip-adress systemd: Created slice User Slice of root.
Jan 12 12:46:01 ip-adress systemd: Started Session 1 of user root.
Jan 12 12:46:01 ip-adress web: 2022-01-12 12:46:01 +0000 Starting server on /var/run/thin/thin.0.sock ...
Jan 12 12:46:01 ip-adress web: 2022-01-12 12:46:01 +0000 /opt/elasticbeanstalk/.rbenv/versions/2.6.9/bin/thin start --chdir="/var/app/current" --environment="production" --timeout=30 --log="/var/log/thin/thin.0.log" --pid="/var/run/thin/thin.0.pid" --max-conns=1024 --max-persistent-conns=512 --threadpool-size=20 --rackup="config.ru" --trace --daemonize --socket="/var/run/thin/thin.0.sock"
Jan 12 12:46:01 ip-adress CloudWatch-PutInstanceData: Cannot obtain instance id from EC2 meta-data.
Jan 12 12:46:01 ip-adress systemd: Removed slice User Slice of root.
Jan 12 12:46:02 ip-adress web: 2022-01-12 12:46:02 +0000 NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:02 ip-adress web: 2022-01-12 12:46:02 +0000 Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:02 ip-adress systemd: web.service holdoff time over, scheduling restart.
Jan 12 12:46:02 ip-adress systemd: Stopped This is web daemon.
Jan 12 12:46:02 ip-adress systemd: Starting This is web daemon...
Jan 12 12:46:02 ip-adress systemd: Started This is web daemon.
Jan 12 12:46:02 ip-adress web: NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:02 ip-adress web: Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:02 ip-adress web: 2022-01-12 12:46:02 +0000 Starting server on /var/run/thin/thin.0.sock ...
Jan 12 12:46:02 ip-adress web: 2022-01-12 12:46:02 +0000 /opt/elasticbeanstalk/.rbenv/versions/2.6.9/bin/thin start --chdir="/var/app/current" --environment="production" --timeout=30 --log="/var/log/thin/thin.0.log" --pid="/var/run/thin/thin.0.pid" --max-conns=1024 --max-persistent-conns=512 --threadpool-size=20 --rackup="config.ru" --trace --daemonize --socket="/var/run/thin/thin.0.sock"
Jan 12 12:46:03 ip-adress web: 2022-01-12 12:46:03 +0000 NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:03 ip-adress web: 2022-01-12 12:46:03 +0000 Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:03 ip-adress systemd: web.service holdoff time over, scheduling restart.
Jan 12 12:46:03 ip-adress systemd: Stopped This is web daemon.
Jan 12 12:46:03 ip-adress systemd: Starting This is web daemon...
Jan 12 12:46:03 ip-adress systemd: Started This is web daemon.
Jan 12 12:46:03 ip-adress web: NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:03 ip-adress web: Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:03 ip-adress web: 2022-01-12 12:46:03 +0000 Starting server on /var/run/thin/thin.0.sock ...
Jan 12 12:46:03 ip-adress web: 2022-01-12 12:46:03 +0000 /opt/elasticbeanstalk/.rbenv/versions/2.6.9/bin/thin start --chdir="/var/app/current" --environment="production" --timeout=30 --log="/var/log/thin/thin.0.log" --pid="/var/run/thin/thin.0.pid" --max-conns=1024 --max-persistent-conns=512 --threadpool-size=20 --rackup="config.ru" --trace --daemonize --socket="/var/run/thin/thin.0.sock"
Jan 12 12:46:04 ip-adress web: 2022-01-12 12:46:04 +0000 NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:04 ip-adress web: 2022-01-12 12:46:04 +0000 Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:04 ip-adress systemd: web.service holdoff time over, scheduling restart.
Jan 12 12:46:04 ip-adress systemd: Stopped This is web daemon.
Jan 12 12:46:04 ip-adress systemd: Starting This is web daemon...
Jan 12 12:46:04 ip-adress systemd: Started This is web daemon.
Jan 12 12:46:04 ip-adress web: NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:04 ip-adress web: Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:04 ip-adress web: 2022-01-12 12:46:04 +0000 Starting server on /var/run/thin/thin.0.sock ...
Jan 12 12:46:04 ip-adress web: 2022-01-12 12:46:04 +0000 /opt/elasticbeanstalk/.rbenv/versions/2.6.9/bin/thin start --chdir="/var/app/current" --environment="production" --timeout=30 --log="/var/log/thin/thin.0.log" --pid="/var/run/thin/thin.0.pid" --max-conns=1024 --max-persistent-conns=512 --threadpool-size=20 --rackup="config.ru" --trace --daemonize --socket="/var/run/thin/thin.0.sock"
Jan 12 12:46:05 ip-adress web: 2022-01-12 12:46:05 +0000 NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:05 ip-adress web: 2022-01-12 12:46:05 +0000 Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:05 ip-adress systemd: web.service holdoff time over, scheduling restart.
Jan 12 12:46:05 ip-adress systemd: Stopped This is web daemon.
Jan 12 12:46:05 ip-adress systemd: start request repeated too quickly for web.service
Jan 12 12:46:05 ip-adress systemd: Failed to start This is web daemon.
Jan 12 12:46:05 ip-adress systemd: Unit web.service entered failed state.
Jan 12 12:46:05 ip-adress systemd: web.service failed.

/var/log/web.stdout.log

Jan 12 12:45:58 ip-ddress web: NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:45:58 ip-ddress web: Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:45:58 ip-ddress web: 2022-01-12 12:45:58 +0000 Starting server on /var/run/thin/thin.0.sock ...
Jan 12 12:45:58 ip-ddress web: 2022-01-12 12:45:58 +0000 /opt/elasticbeanstalk/.rbenv/versions/2.6.9/bin/thin start --chdir="/var/app/current" --environment="production" --timeout=30 --log="/var/log/thin/thin.0.log" --pid="/var/run/thin/thin.0.pid" --max-conns=1024 --max-persistent-conns=512 --threadpool-size=20 --rackup="config.ru" --trace --daemonize --socket="/var/run/thin/thin.0.sock"
Jan 12 12:45:59 ip-ddress web: 2022-01-12 12:45:59 +0000 NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:45:59 ip-ddress web: 2022-01-12 12:45:59 +0000 Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:00 ip-ddress web: NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:00 ip-ddress web: Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:00 ip-ddress web: 2022-01-12 12:46:00 +0000 Starting server on /var/run/thin/thin.0.sock ...
Jan 12 12:46:00 ip-ddress web: 2022-01-12 12:46:00 +0000 /opt/elasticbeanstalk/.rbenv/versions/2.6.9/bin/thin start --chdir="/var/app/current" --environment="production" --timeout=30 --log="/var/log/thin/thin.0.log" --pid="/var/run/thin/thin.0.pid" --max-conns=1024 --max-persistent-conns=512 --threadpool-size=20 --rackup="config.ru" --trace --daemonize --socket="/var/run/thin/thin.0.sock"
Jan 12 12:46:00 ip-ddress web: 2022-01-12 12:46:00 +0000 NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:00 ip-ddress web: 2022-01-12 12:46:00 +0000 Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:01 ip-ddress web: NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:01 ip-ddress web: Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:01 ip-ddress web: 2022-01-12 12:46:01 +0000 Starting server on /var/run/thin/thin.0.sock ...
Jan 12 12:46:01 ip-ddress web: 2022-01-12 12:46:01 +0000 /opt/elasticbeanstalk/.rbenv/versions/2.6.9/bin/thin start --chdir="/var/app/current" --environment="production" --timeout=30 --log="/var/log/thin/thin.0.log" --pid="/var/run/thin/thin.0.pid" --max-conns=1024 --max-persistent-conns=512 --threadpool-size=20 --rackup="config.ru" --trace --daemonize --socket="/var/run/thin/thin.0.sock"
Jan 12 12:46:02 ip-ddress web: 2022-01-12 12:46:02 +0000 NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:02 ip-ddress web: 2022-01-12 12:46:02 +0000 Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:02 ip-ddress web: NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:02 ip-ddress web: Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:02 ip-ddress web: 2022-01-12 12:46:02 +0000 Starting server on /var/run/thin/thin.0.sock ...
Jan 12 12:46:02 ip-ddress web: 2022-01-12 12:46:02 +0000 /opt/elasticbeanstalk/.rbenv/versions/2.6.9/bin/thin start --chdir="/var/app/current" --environment="production" --timeout=30 --log="/var/log/thin/thin.0.log" --pid="/var/run/thin/thin.0.pid" --max-conns=1024 --max-persistent-conns=512 --threadpool-size=20 --rackup="config.ru" --trace --daemonize --socket="/var/run/thin/thin.0.sock"
Jan 12 12:46:03 ip-ddress web: 2022-01-12 12:46:03 +0000 NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:03 ip-ddress web: 2022-01-12 12:46:03 +0000 Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:03 ip-ddress web: NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:03 ip-ddress web: Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:03 ip-ddress web: 2022-01-12 12:46:03 +0000 Starting server on /var/run/thin/thin.0.sock ...
Jan 12 12:46:03 ip-ddress web: 2022-01-12 12:46:03 +0000 /opt/elasticbeanstalk/.rbenv/versions/2.6.9/bin/thin start --chdir="/var/app/current" --environment="production" --timeout=30 --log="/var/log/thin/thin.0.log" --pid="/var/run/thin/thin.0.pid" --max-conns=1024 --max-persistent-conns=512 --threadpool-size=20 --rackup="config.ru" --trace --daemonize --socket="/var/run/thin/thin.0.sock"
Jan 12 12:46:04 ip-ddress web: 2022-01-12 12:46:04 +0000 NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:04 ip-ddress web: 2022-01-12 12:46:04 +0000 Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:04 ip-ddress web: NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:04 ip-ddress web: Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.
Jan 12 12:46:04 ip-ddress web: 2022-01-12 12:46:04 +0000 Starting server on /var/run/thin/thin.0.sock ...
Jan 12 12:46:04 ip-ddress web: 2022-01-12 12:46:04 +0000 /opt/elasticbeanstalk/.rbenv/versions/2.6.9/bin/thin start --chdir="/var/app/current" --environment="production" --timeout=30 --log="/var/log/thin/thin.0.log" --pid="/var/run/thin/thin.0.pid" --max-conns=1024 --max-persistent-conns=512 --threadpool-size=20 --rackup="config.ru" --trace --daemonize --socket="/var/run/thin/thin.0.sock"
Jan 12 12:46:05 ip-ddress web: 2022-01-12 12:46:05 +0000 NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed in Rubygems 4
Jan 12 12:46:05 ip-ddress web: 2022-01-12 12:46:05 +0000 Gem::Specification#has_rdoc= called from /var/app/current/vendor/gems/async-rack/async-rack.gemspec:16.

The Thin log is empty and does not through out any errors.


Solution

  • The solution is to not daemonize the Thin server in config.yml

    daemonize: false