5

I need to increase the passenger_max_pool_size for my Rails application running on passenger. I have used Elastic beanstalk for deployment. Any idea, how to go about this? Is there an optionsetting or container command to do this

2 Answers2

4

I realize that this is an old post, however it is unanswered.

Best option is to use .ebextensions dir in the root of your project, and add a config file to configure passenger. I've created an .ebextensions/01_passenger.config file in my project.

For the content section of this file you will probably want to copy your existing passenger init file located here /opt/elasticbeanstalk/support/conf/passenger

I've slightly modified it to include --max-pool-size=${PASSENGER_MAX_POOL_SIZE:-6} in the start options. You can use the Beanstalk Environment variables to override the default of 6 for the pool size.

files:
  "/tmp/passenger.config":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      #
      # chkconfig: 2345 80 20
      # description: Passenger
      #

      EB_HTTP_PORT=$(/opt/elasticbeanstalk/bin/get-config container -k http_port)
      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_APP_PID_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_pid_dir)
      EB_APP_LOG_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_log_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)
      EB_NGINX_VERSION=$(/opt/elasticbeanstalk/bin/get-config container -k nginx_version)

      . $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

      # fixes http://code.google.com/p/phusion-passenger/issues/detail?id=614
      export HOME=/tmp
      export PASSENGER_DOWNLOAD_NATIVE_SUPPORT_BINARY=0

      if [ -d /etc/healthd ]; then
          STARTOPTS="--nginx-version $EB_NGINX_VERSION --nginx-config-template $EB_SUPPORT_DIR/conf/nginx_config_healthd.erb"
      else
          STARTOPTS="--nginx-version $EB_NGINX_VERSION --nginx-config-template $EB_SUPPORT_DIR/conf/nginx_config.erb"
      fi

      ENV_STAGE=${RACK_ENV:-$RAILS_ENV}    # Read from $RAILS_ENV if $RACK_ENV is empty
      if [ ${ENV_STAGE,,} = "production" ]; then    # Convert $ENV_STAGE to lower case and compare to "production"
        # Disable passenger friendly page for production stage
        STARTOPTS="$STARTOPTS --no-friendly-error-pages"
      fi

      #Add custom max-pool size
      STARTOPTS="$STARTOPTS  --max-pool-size=${PASSENGER_MAX_POOL_SIZE:-6}"

      GENERALOPTS="-p $EB_HTTP_PORT --pid-file $EB_APP_PID_DIR/passenger.pid"

      function start() {
        touch $EB_APP_LOG_DIR/passenger.log

        if [ -d /etc/healthd ]; then
          mkdir -p $EB_APP_LOG_DIR/healthd
          chown -R $EB_APP_USER:$EB_APP_USER $EB_APP_LOG_DIR/healthd
        fi

        chown $EB_APP_USER:$EB_APP_USER \
          $EB_APP_LOG_DIR/passenger.log
        passenger start $EB_APP_DEPLOY_DIR $STARTOPTS $GENERALOPTS \
          -d -e ${RACK_ENV:-$RAILS_ENV} --user $EB_APP_USER \
          --log-file $EB_APP_LOG_DIR/passenger.log
      }

      function stop() {
        passenger stop $GENERALOPTS
      }

      function status() {
        passenger status $GENERALOPTS
      }

      case "$1" in
        start)
          start
          ;;
        stop)
          stop
          ;;
        status)
          status
          ;;
        restart|graceful)
          stop
          start
          ;;
        reload)
          su -s /bin/bash -c "touch $EB_APP_DEPLOY_DIR/tmp/restart.txt" $EB_APP_USER
          ;;
        *)
          echo "Usage: $0 {start|stop|restart|reload|status}"
          exit 1
          ;;
      esac

      exit 0

container_commands:
  01_config_passenger:
    command: "cp /tmp/passenger.config /opt/elasticbeanstalk/support/conf/passenger"
Justin Fortier
  • 750
  • 5
  • 9
  • I followed this setup by it does not seem to work. @Justin is there anything I might miss? – channa ly Feb 08 '19 at 02:36
  • 1
    @channaly have you defined PASSENGER_MAX_POOL_SIZE in your Beanstalk environment variables? I just noticed I put `.conf` but I EB config files should be `.config` so perhaps that's why it's not working for you (will fix). Also you will want to make sure your file is valid YAML 1.1 format as per AWS EBextensions docs. – Justin Fortier Feb 08 '19 at 19:08
  • @channaly also be sure to take a look at your eb logs and see if there's a reason the config was not loaded, or perhaps why it failed to execute. – Justin Fortier Feb 08 '19 at 19:20
  • I have it .conf. Yes It is valid Yaml. I will try to deploy run it again. BTW how to check if the extension file get run in the log? – channa ly Feb 09 '19 at 00:33
  • 1
    it works!. your explanations hit the points. I had .conf instead of .config and my yaml was not valid even it could be parsed by eb. eg. I had duplicated keys command twice ( 2 command nodes under same name in container_command section ). I wish you answered will be ticked to shed light to other. – channa ly Feb 09 '19 at 02:58
  • @channaly glad it all worked for you. Have fun. :) – Justin Fortier Feb 11 '19 at 15:45
  • For some reason was failing to me, maybe due to different version of passenger, not sure, and I got solved per https://stackoverflow.com/a/56490650/2992786 – emaxi Jun 07 '19 at 08:30
  • @emaxi thanks, I will move it to the start ops, that makes more sense. – Justin Fortier Jun 10 '19 at 14:23
1

if you use passenger-standalone you can simplify the process by adding a passenger-standalone.json file in the rails root dir with the content:

{
  "max_pool_size": 16
}

make sure the file is called passenger-standalone.json and not Passengerfile.json.

validate config with

sudo -i passenger-status

see:

https://www.phusionpassenger.com/library/config/standalone/reference/

and:

http://hwcode111.blogspot.com/2013/02/rails-elastic-beanstalk-passenger.html

fluxsaas
  • 121
  • 2