मैं एक सिनात्रा ऐप को स्थानांतरित करने की कोशिश कर रहा हूं जो हेरोकू से एडब्ल्यूएस लोचदार बीनस्टॉक तक पतले सर्वर का उपयोग करता है। फिलहाल मुद्दा यह है कि Nginx थिन के बजाय प्यूमा सर्वर की तलाश में है:

connect() to unix:///var/run/puma/my_app.sock failed (2: No such file or directory)

क्या पतला एडब्ल्यूएस लोचदार बीनस्टॉक का उपयोग करना संभव है?

0
fnllc 15 अगस्त 2019, 13:32

2 जवाब

सबसे बढ़िया उत्तर

मैं नीचे की फाइलों के साथ एडब्ल्यूएस लोचदार बीनस्टॉक पर पतला सर्वर चलाने में सक्षम था। प्यूमा सर्वर बंद करना अभी काम नहीं कर रहा है।

.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
0
user2666194 18 अगस्त 2019, 20:02

@ User2666194 के उत्कृष्ट उत्तर के अलावा, मैंने पाया कि ईबी आवेदन नहीं चलने के कारण खराब स्थिति में होने की शिकायत करेगा।

ऐसा प्रतीत होता है कि healthd यह सुनिश्चित करने के लिए कि एप्लिकेशन चल रहा है, /var/elasticbeanstalk/healthd/application.pid में सूचीबद्ध pid की जाँच करता है। यह डिफ़ॉल्ट रूप से /var/run/puma/puma.pid से जुड़ा होता है।

इससे निपटने के लिए, मैंने इस पिड को हटाने और बदलने के लिए 01_nginx.config फ़ाइल को संशोधित किया। मैंने प्यूमा को रोकने के लिए initctl कमांड भी जोड़ा। अब हम सही पिड की जाँच कर रहे हैं, ऐसा लगता है कि इसका कोई दुष्प्रभाव नहीं है:

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 {
        least_conn;
        server unix:///var/run/thin/thin.0.sock;
        server unix:///var/run/thin/thin.1.sock;
      }

      log_format healthd '$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;

        location / {
          proxy_pass http://my_app; # 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;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
          # Application is 180, this is overhead
          proxy_read_timeout 200s;
        }

        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_thin.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
      /sbin/initctl stop puma
      # 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
      # Remove the old app pid (puma) and replace it with our one
      rm -f /var/elasticbeanstalk/healthd/application.pid
      ln -s /var/run/thin/thin.0.pid /var/elasticbeanstalk/healthd/application.pid

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"
0
Andrew White 13 जिंदा 2020, 07:33