0

我正在为我的 rails 应用程序编写 cap/deploy 脚本。在我的服务器上,我使用 RVM 来管理我的 ruby​​ 安装。

我看到的问题是,即使我已将 runner/user/group 设置为正确的用户,我在尝试安装 gems 时却遇到权限错误。

这是我看到的错误:

** loading stage recipe 'deploy'
** loading stage recipe 'init_config'
** loading stage recipe 'nginx'
executing locally: "git ls-remote ############################### ec2"
command finished in 1113ms
* executing `deploy:setup'
triggering before callbacks for `deploy:setup'
* executing `init_config'
* executing "whoami"
servers: ["ec2-23-23-24-42.compute-1.amazonaws.com"]
[ec2-23-23-24-42.compute-1.amazonaws.com] executing command
** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] ubuntu
command finished in 529ms
* executing "gem install bundler"
servers: ["ec2-23-23-24-42.compute-1.amazonaws.com"]
[ec2-23-23-24-42.compute-1.amazonaws.com] executing command
** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] ERROR:  While executing gem ... (Gem::FilePermissionError)
** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] You don't have write permissions into the /home/ubuntu/.rvm/gems/ruby-1.9.2-p290 directory.
command finished in 1026ms
*** failed: "bash --login -c 'gem install bundler'" on ec2-23-23-24-42.compute-1.amazonaws.com

这是我的出口上限文件:

load 'deploy'

# ================================================================
# ROLES
# ================================================================


role :app, "ec2-23-23-24-42.compute-1.amazonaws.com"


# ================================================================
# VARIABLES
# ================================================================

# Webistrano defaults
    set :webistrano_project, "sweet_high"
    set :webistrano_stage, "staging"


    set :application, ""

    set :branch, "ec2"

    set :bundle_disable_shared_gems, "\"1\""

    set :bundle_path, "vendor/bundler_gems"

    set :default_shell, "bash --login"

    set :deploy_to, "/data/\#{application}"

    set :deploy_via, :remote_cache

    set :domain, ""

    set :environment, "staging"

    set :group, "ubuntu"

    set :nginx_conf_path, "/etc/nginx/sites-enabled"

    set :password, "deployment_user(SSH user) password"

    set :rails_env, "staging"

    set :repository, "t"

    set :runner, "ubuntu"

    set :rvm_bin_path, "/home/#{user}/.rvm/bin/rvm"

    set :rvm_type, :user

    set :scm, :git

    set :scm_password, "your_SVN_password"

    set :scm_username, "your_SVN_user"

    set :ssh_options, {:forward_agent => true,:paranoid => false,:keys => ["/home/#{user}/.ssh/rails_app_server.pem"]}

    set :use_sudo, true

    set :user, "ubuntu"




# ================================================================
# TEMPLATE TASKS
# ================================================================

    # allocate a pty by default as some systems have problems without
    default_run_options[:pty] = true

    # set Net::SSH ssh options through normal variables
    # at the moment only one SSH key is supported as arrays are not
    # parsed correctly by Webistrano::Deployer.type_cast (they end up as strings)
    [:ssh_port, :ssh_keys].each do |ssh_opt|
      if exists? ssh_opt
        logger.important("SSH options: setting #{ssh_opt} to: #{fetch(ssh_opt)}")
        ssh_options[ssh_opt.to_s.gsub(/ssh_/, '').to_sym] = fetch(ssh_opt)
      end
    end



# ================================================================
# CUSTOM RECIPES
# ================================================================


before "deploy:setup", :init_config
after "deploy:setup", :setup_cleanup
namespace :init_config do
    desc <<-DESC
       Created directory structure, changes ownership, etc...
    DESC

    task :default do
        run "gem install bundler"
        run "sudo mkdir -p #{deploy_to}"
        run "sudo chown -R #{user}:#{group} #{deploy_to}"
        run "mkdir -p #{shared_path}/config"
        run "mkdir -p #{shared_path}/config"
        File.open("/home/#{user}/.ssh/id_rsa", "rb").each_line{ |line|
            run "echo #{line} >> ~/.ssh/id_rsa"
        }
        run "chown #{user}:#{group} ~/.ssh/id_rsa"
       run "chmod 600 ~/.ssh/id_rsa"    
    end
end
4

1 回答 1

1

您的任务init_config:default需要少量补充:

    run "sudo chown -R #{user}:#{group} /home/#{user}/.rvm"
    run "gem install bundler"
于 2012-08-03T01:34:55.477 回答