我需要增加在 Passenger 上运行的 Rails 应用程序的 Passenger_max_pool_size。我已使用 Elastic beanstalk 进行部署。有什么想法吗?如何操作?是否有选项设置或容器命令可以执行此操作
答案1
我知道这是一篇旧帖子,但尚未得到答复。
最佳选择是使用项目根目录中的 .ebextensions 目录,并添加一个配置文件来配置乘客。我已经.ebextensions/01_passenger.config
在我的项目中创建了一个文件。
对于此文件的内容部分,您可能需要复制位于此处的现有乘客初始化文件/opt/elasticbeanstalk/support/conf/passenger
我对其进行了轻微修改,以将其包含--max-pool-size=${PASSENGER_MAX_POOL_SIZE:-6}
在启动选项中。您可以使用 Beanstalk 环境变量来覆盖池大小的默认值 6。
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"
答案2
如果你使用,你可以通过在 rails 根目录中passenger-standalone
添加一个包含以下内容的文件来简化该过程:passenger-standalone.json
{
"max_pool_size": 16
}
确保文件被调用passenger-standalone.json
而不是Passengerfile.json
。
验证配置
sudo -i passenger-status
看:
https://www.phusionpassenger.com/library/config/standalone/reference/
和:
http://hwcode111.blogspot.com/2013/02/rails-elastic-beanstalk-passenger.html