Capistrano无法创建符号链接:文件存在 [英] Capistrano can not create symlinks: file exist

查看:133
本文介绍了Capistrano无法创建符号链接:文件存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Capistrano 3的Rails 4应用程序.

I have Rails 4 app with Capistrano 3.

# deploy.rb
set :application, '<DELETED>'
set :user, '<DELETED>'
set :repo_url, '<DELETED>'
set :branch, 'master'
ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }

set :deploy_to, "/home/#{fetch :user}/apps/#{fetch :application}"
set :scm, :git

set :format, :pretty
set :log_level, :debug
set :pty, true

set :linked_files, %w{config/application.yml}
set :linked_dirs, %w{bin log tmp vendor/bundle public/system public/deploy}

# set :default_env, { path: "/opt/ruby/bin:$PATH" }
set :keep_releases, 5

namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      # execute :touch, release_path.join('tmp/restart.txt')
      within fetch :current_path do
        execute "/etc/init.d/unicorn_#{fetch :application} restart"
      end
    end
  end

  before :restart, 'rvm:hook'

  desc 'Stop application'
  task :stop do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      within fetch :current_path do
        execute "/etc/init.d/unicorn_#{fetch :application} stop"
      end
      # execute :touch, release_path.join('tmp/restart.txt')
    end
  end
  before :stop, 'rvm:hook'

  desc 'Start application'
  task :start do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      within fetch :current_path do
        execute "/etc/init.d/unicorn_#{fetch :application} start"
      end
      # execute :touch, release_path.join('tmp/restart.txt')
    end
  end
  before :start, 'rvm:hook'
  before 'whenever:update_crontab', 'rvm:hook'
  before 'whenever:clear_crontab', 'rvm:hook'

  after :finishing, 'deploy:cleanup'
  after :finished, 'deploy:restart'

  task :add_default_hooks do
    after 'deploy:starting', 'sidekiq:quiet'
    after 'deploy:updated', 'sidekiq:stop'
    after 'deploy:reverted', 'sidekiq:stop'
    after 'deploy:published', 'sidekiq:start'
  end

end

部署生产设置:

# production.rb
set :stage, :production

# Simple Role Syntax
# ==================
# Supports bulk-adding hosts to roles, the primary
# server in each group is considered to be the first
# unless any hosts have the primary property set.
role :app, %w{<DELETED>}
role :web, %w{<DELETED>}
role :db,  %w{<DELETED>}

# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server
# definition into the server list. The second argument
# something that quacks like a hash can be used to set
# extended properties on the server.
server '128.199.148.191', user: 'deployer', roles: %w{web app db} #, my_property: :my_value
set :rvm_type, :system
set :rvm_ruby_version, '2.1.0'
set :rails_env, 'production'
# you can set custom ssh options
# it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options
# you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start)
# set it globally
#  set :ssh_options, {
#    keys: %w(/home/rlisowski/.ssh/id_rsa),
#    forward_agent: false,
#    auth_methods: %w(password)
#  }
# and/or per server
# server 'example.com',
#   user: 'user_name',
#   roles: %w{web app},
#   ssh_options: {
#     user: 'user_name', # overrides user setting above
#     keys: %w(/home/user_name/.ssh/id_rsa),
#     forward_agent: false,
#     auth_methods: %w(publickey password)
#     # password: 'please use keys'
#   }
# setting per server overrides global ssh_options

# fetch(:default_env).merge!(rails_env: :production)
set :ssh_options, {
                    auth_methods: %w(publickey password),
                    user: '<DELETED>'
                }

可以,但是我在创建符号链接时遇到问题.它返回文件存在",但是我没有在存储库中仅在共享文件夹中创建application.yml或public/system forlder.日志:

It was ok, but I have issue with creating symlinks. It returns 'file exists', but I didn't create application.yml or public/system forlder in repository, only in shared folder. Log:

 INFO[3e66cb56] Finished in 0.842 seconds with exit status 0 (successful).
** Invoke deploy:symlink:shared (first_time)
** Execute deploy:symlink:shared
** Invoke deploy:symlink:linked_files (first_time)
** Execute deploy:symlink:linked_files
INFO[146e0a26] Running /usr/bin/env mkdir -p /home/deployer/apps/xxxcoast/releases/20141124144030/config on 128.199.148.191
DEBUG[146e0a26] Command: /usr/bin/env mkdir -p /home/deployer/apps/xxxcoast/releases/20141124144030/config
INFO[a9a9bef0] Running /usr/bin/env mkdir -p /home/deployer/apps/xxxcoast/releases/20141124144030/config on 128.199.148.191
DEBUG[a9a9bef0] Command: /usr/bin/env mkdir -p /home/deployer/apps/xxxcoast/releases/20141124144030/config
INFO[a9a9bef0] Finished in 0.848 seconds with exit status 0 (successful).
INFO[146e0a26] Finished in 0.850 seconds with exit status 0 (successful).
DEBUG[0f26dfb7] Running /usr/bin/env [ -L /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml ] on 128.199.148.191
DEBUG[2d8972f0] Running /usr/bin/env [ -L /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml ] on 128.199.148.191
DEBUG[0f26dfb7] Command: [ -L /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml ]
DEBUG[2d8972f0] Command: [ -L /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml ]
DEBUG[2d8972f0] Finished in 0.822 seconds with exit status 1 (failed).
DEBUG[7858afe7] Running /usr/bin/env [ -f /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml ] on 128.199.148.191
DEBUG[7858afe7] Command: [ -f /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml ]
DEBUG[0f26dfb7] Finished in 0.827 seconds with exit status 1 (failed).
DEBUG[7e5cbc1c] Running /usr/bin/env [ -f /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml ] on 128.199.148.191
DEBUG[7e5cbc1c] Command: [ -f /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml ]
DEBUG[7e5cbc1c] Finished in 0.838 seconds with exit status 1 (failed).
INFO[9cc3b7d0] Running /usr/bin/env ln -s /home/deployer/apps/xxxcoast/shared/config/application.yml /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml on 128.199.148.191
DEBUG[9cc3b7d0] Command: /usr/bin/env ln -s /home/deployer/apps/xxxcoast/shared/config/application.yml /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml
DEBUG[7858afe7] Finished in 0.843 seconds with exit status 1 (failed).
INFO[bcf64145] Running /usr/bin/env ln -s /home/deployer/apps/xxxcoast/shared/config/application.yml /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml on 128.199.148.191
DEBUG[bcf64145] Command: /usr/bin/env ln -s /home/deployer/apps/xxxcoast/shared/config/application.yml /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml
INFO[9cc3b7d0] Finished in 1.032 seconds with exit status 0 (successful).
DEBUG[bcf64145]     ln: failed to create symbolic link ‘/home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml’: File exists
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host 128.199.148.191: ln exit status: 1
ln stdout: Nothing written
ln stderr: Nothing written
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/command.rb:97:in `exit_status='
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:148:in `block (5 levels) in _execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in `call'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in `do_request'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:561:in `channel_request'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:205:in `process'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:269:in `wait'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:170:in `block (3 levels) in _execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:514:in `call'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:514:in `do_open_confirmation'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:545:in `channel_open_confirmation'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:205:in `process'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:172:in `block (2 levels) in _execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:186:in `with_ssh'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:131:in `block in _execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `tap'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `_execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:66:in `execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/bundler/gems/capistrano-52591324f3ae/lib/capistrano/tasks/deploy.rake:129:in `block (5 levels) in <top (required)>'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/bundler/gems/capistrano-52591324f3ae/lib/capistrano/tasks/deploy.rake:122:in `each'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/bundler/gems/capistrano-52591324f3ae/lib/capistrano/tasks/deploy.rake:122:in `block (4 levels) in <top (required)>'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
SSHKit::Command::Failed: ln exit status: 1
ln stdout: Nothing written
ln stderr: Nothing written
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/command.rb:97:in `exit_status='
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:148:in `block (5 levels) in _execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in `call'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in `do_request'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:561:in `channel_request'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:205:in `process'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:269:in `wait'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:170:in `block (3 levels) in _execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:514:in `call'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:514:in `do_open_confirmation'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:545:in `channel_open_confirmation'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:205:in `process'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:172:in `block (2 levels) in _execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:186:in `with_ssh'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:131:in `block in _execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `tap'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `_execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:66:in `execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/bundler/gems/capistrano-52591324f3ae/lib/capistrano/tasks/deploy.rake:129:in `block (5 levels) in <top (required)>'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/bundler/gems/capistrano-52591324f3ae/lib/capistrano/tasks/deploy.rake:122:in `each'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/bundler/gems/capistrano-52591324f3ae/lib/capistrano/tasks/deploy.rake:122:in `block (4 levels) in <top (required)>'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Tasks: TOP => deploy:symlink:linked_files
The deploy has failed with an error: Exception while executing on host 128.199.148.191: ln exit status: 1
ln stdout: Nothing written
ln stderr: Nothing written
** Invoke deploy:failed (first_time)
** Execute deploy:failed

更好的记录

推荐答案

我发现这是因为我有重复的角色定义,所以它两次运行了symlink命令.

I found this was because I had duplicate role definitions, so it was running the symlink command twice.

检查您是否没有重复的 role 行,或者您是否具有 role 行以及一个多合一的 server 配置线.

Check that you don't have duplicate role lines or that you have role lines in addition an all-in-one server configuration line.

这篇关于Capistrano无法创建符号链接:文件存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆