我意识到有一些关于此的文章,但我正在尝试在Elastic Beanstalk上部署Rails应用程序并在部署过程中启动delayed_job,但我还没有设法让它工作。
我已尝试在.ebextensions文件夹中设置配置文件:
命令: 创造 - -DIR后: 命令:“mkdir / opt / elasticbeanstalk / hooks / appdeploy / post” ignoreErrors:true
文件: “/opt/elasticbeanstalk/hooks/appdeploy/post/restart_delayed_job.sh”: 模式:“000755” 所有者:root group:root 内容:| #!/ 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_APP_PID_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_pid_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)
# Export EB_APP_LOG_DIR so we can access it when running bin/delayed_job below,
# which accesses config/initializers/delayed_job.rb, which uses EB_APP_LOG_DIR.
export EB_APP_LOG_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_log_dir)
# Make sure the delayed_job.log exists and is owned by $EB_APP_USER
touch $EB_APP_LOG_DIR/delayed_job.log
chown $EB_APP_USER:$EB_APP_USER $EB_APP_LOG_DIR/delayed_job.log
# 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
# Now we can do the actual restart of the worker. Make sure to have double quotes when using env vars in the command.
# For Rails 4, replace script/delayed_job with bin/delayed_job
cd $EB_APP_DEPLOY_DIR
su -s /bin/bash -c "bundle exec bin/delayed_job --pid-dir=$EB_APP_PID_DIR restart" $EB_APP_USER
su -s /bin/bash -c "bundle exec bin/delayed_job --pid-dir=$EB_APP_PID_DIR status" $EB_APP_USER
非常感谢任何帮助我们开展此工作!
答案 0 :(得分:1)
在花了很多时间之后,我终于得到了以下的工作。虽然它不适用于delayed_job,但我相信这解决了获取rails环境设置以便捆绑运行的相同问题。
<强> .ebextensions / 01_my_server.config 强>
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_my_servers.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
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_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir)
. $EB_SUPPORT_DIR/envvars
. $EB_SCRIPT_DIR/use-app-ruby.sh
mkdir -p /home/webapp
chown webapp:webapp /home/webapp
mkdir -p /home/webapp/pids
chown webapp:webapp /home/webapp/pids
cd $EB_APP_DEPLOY_DIR
su -m -c "bundle exec bin/my_server.rb --pid-dir=/home/webapp/pids restart" -s /bin/bash webapp
注意事项: