使用AWS用户数据运行Capistrano部署任务

时间:2016-06-18 22:26:47

标签: ubuntu amazon-web-services capistrano3

我的方案:我有一个带有deploy/文件夹的AMI,其中包含我用于在localhost上部署生产应用程序的capistrano文件

我计划使用来自Autoscaling组的用户数据脚本,每次组扩展并生成新计算机时部署最新版本的服务器

该脚本必须以用户ubuntu

运行

这是我的用户数据

cd /home/ubuntu/
aws s3 cp s3://mybucket-config/production/rails/startup_script.sh ./startup_script.sh --region my-region
chmod +x ./startup_script.sh
chown ubuntu:ubuntu ./startup_script.sh
su - ubuntu -c "./startup_script.sh"

此启动脚本包含

cd /home/ubuntu/deploy/
git pull
git checkout production
cap aws_localhost_production deploy

我在cap deploy期间遇到了一个奇怪的错误消息,我在谷歌上找不到关于这个的很多参考

  

NoMethodError:未定义的方法`winsize'为零:NilClass

这是完整的堆栈

The deploy has failed with an error: undefined method `winsize' for nil:NilClass
/home/ubuntu/.rvm/gems/ruby-2.3.0/gems/airbrussh-1.0.1/lib/airbrussh/console.rb:61:in `console_width': undefined method `winsize' for nil:NilClass (NoMethodError)
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/airbrussh-1.0.1/lib/airbrussh/console.rb:26:in `print_line'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/airbrussh-1.0.1/lib/airbrussh/capistrano/tasks.rb:77:in `each_line'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/airbrussh-1.0.1/lib/airbrussh/capistrano/tasks.rb:77:in `error_line'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/airbrussh-1.0.1/lib/airbrussh/capistrano/tasks.rb:42:in `deploy_failed'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/airbrussh-1.0.1/lib/airbrussh/capistrano.rb:15:in `block (2 levels) in <top (required)>'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/rake-11.1.2/lib/rake/task.rb:248:in `block in execute'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/rake-11.1.2/lib/rake/task.rb:243:in `each'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/rake-11.1.2/lib/rake/task.rb:243:in `execute'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/airbrussh-1.0.1/lib/airbrussh/rake/context.rb:55:in `execute'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/rake-11.1.2/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
        from /usr/share/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/rake-11.1.2/lib/rake/task.rb:180:in `invoke_with_call_chain'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/rake-11.1.2/lib/rake/task.rb:173:in `invoke'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/capistrano-3.5.0/lib/capistrano/dsl.rb:15:in `invoke'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/capistrano-3.5.0/lib/capistrano/dsl/task_enhancements.rb:56:in `exit_deploy_because_of_exception'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/capistrano-3.5.0/lib/capistrano/application.rb:73:in `exit_because_of_exception'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/rake-11.1.2/lib/rake/application.rb:186:in `rescue in standard_exception_handling'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/rake-11.1.2/lib/rake/application.rb:176:in `standard_exception_handling'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/rake-11.1.2/lib/rake/application.rb:75:in `run'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/capistrano-3.5.0/lib/capistrano/application.rb:14:in `run'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/capistrano-3.5.0/bin/cap:3:in `<top (required)>'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/bin/cap:23:in `load'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/bin/cap:23:in `<main>'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
        from /home/ubuntu/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'

1 个答案:

答案 0 :(得分:5)

我猜测winsize涉及检测运行应用程序的shell窗口的大小。尝试将set :format, :pretty添加到config/deploy.rb。它将告诉它停止使用Airbrusshed格式化程序并默认使用更详细的选项。