I'm trying to move a Sinatra App that uses Thin server from Heroku to AWS Elastic Beanstalk. The issue at the moment is that Nginx is looking for a Puma server instead of Thin:
connect() to unix:///var/run/puma/my_app.sock failed (2: No such file or directory)
Is it possible to use Thin AWS Elastic Beanstalk?
I was able to get Thin server running on AWS Elastic Beanstalk with the files below. Turning off Puma server is not yet working.
.ebextensions\01_nginx.config
commands:
create_post_dir:
command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
ignoreErrors: true
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/00_set_permissions.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
EB_APP_USER=$(/opt/elasticbeanstalk/bin/get-config container -k app_user)
su -s /bin/bash -c "mkdir -p /var/run/thin"
su -s /bin/bash -c "mkdir -p /var/log/thin"
chown -R $EB_APP_USER:$EB_APP_USER /var/run/thin
chown -R $EB_APP_USER:$EB_APP_USER /var/log/thin
"/etc/nginx/conf.d/02_app_server.conf":
mode: "000644"
owner: root
group: root
content: |
# The content of this file is based on the content of /etc/nginx/conf.d/webapp_healthd.conf
upstream my_app_new {
least_conn;
server unix:///var/run/thin/thin.0.sock;
server unix:///var/run/thin/thin.1.sock;
}
log_format healthd_new '$msec"$uri"'
'$status"$request_time"$upstream_response_time"'
'$http_x_forwarded_for';
server {
listen 80;
server_name _ localhost; # need to listen to localhost for worker tier
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
set $hour $4;
}
access_log /var/log/nginx/access.log main;
access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd_new;
location / {
proxy_pass http://my_app_new; # match the name of upstream directive which is defined above
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /assets {
alias /var/app/current/public/assets;
gzip_static on;
gzip on;
expires max;
add_header Cache-Control public;
}
location /public {
alias /var/app/current/public;
gzip_static on;
gzip on;
expires max;
add_header Cache-Control public;
}
client_max_body_size 0;
}
"/opt/elasticbeanstalk/support/conf/pumaconf.rb":
mode: "000644"
owner: root
group: root
content: |
directory '/var/app/current'
threads 0
workers 0
bind 'unix:///var/run/puma/my_app.sock'
pidfile '/var/run/puma/puma.pid'
stdout_redirect '/var/log/puma/puma.log', '/var/log/puma/puma.log', true
daemonize false
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_start_rhoconnect.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
# Loading environment data
EB_APP_USER=$(/opt/elasticbeanstalk/bin/get-config container -k app_user)
EB_APP_DEPLOY_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir)
EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir)
# Setting up correct environment and ruby version so that bundle can load all gems
. $EB_SUPPORT_DIR/envvars
. $EB_SCRIPT_DIR/use-app-ruby.sh
# Stop Puma
# su -s /bin/bash -c "pumactl -P /var/run/puma/puma.pid stop" $EB_APP_USER
# Now we can do the actual restart of the server. Make sure to have double quotes when using env vars in the command.
cd $EB_APP_DEPLOY_DIR
FILE=/var/run/thin/thin.pid
if [ -f "$FILE" ]; then
su -s /bin/bash -c "RACK_ENV=production bundle exec thin restart -R config.ru -e production -p 9292 -C config/thin.yml" $EB_APP_USER
else
su -s /bin/bash -c "RACK_ENV=production bundle exec thin start -R config.ru -e production -p 9292 -C config/thin.yml" $EB_APP_USER
fi
container_commands:
01_reload_nginx:
command: "sudo service nginx reload"
02_remove_webapp_healthd:
command: "rm -f /opt/elasticbeanstalk/support/conf/webapp_healthd.conf /etc/nginx/conf.d/webapp_healthd.conf"
config\thin.yml:
---
chdir: /var/app/current
environment: production
address: 0.0.0.0
port: 3000
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: 2
.ebextensions\tail-logs.config
files:
"/opt/elasticbeanstalk/tasks/taillogs.d/cloud-init.conf" :
mode: "000755"
owner: root
group: root
content: |
/var/log/thin/thin.0.log
/var/log/thin/thin.1.log