gpt4 book ai didi

ruby-on-rails - Capistrano 无法创建符号链接(symbolic link) : file exist

转载 作者:行者123 更新时间:2023-12-02 21:21:50 27 4
gpt4 key购买 nike

我有 Rails 4 应用程序和 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>'
}

没关系,但我在创建符号链接(symbolic link)时遇到问题。它返回“文件存在”,但我没有在存储库中创建 application.yml 或 public/system forlder,仅在共享文件夹中创建。日志:

 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

编辑:更好的日志

最佳答案

我发现这是因为我有重复的角色定义,因此它运行了符号链接(symbolic link)命令两次。

检查您是否没有重复的 role 行,或者除了一体化的 server 配置之外,您还有 role 行线。

关于ruby-on-rails - Capistrano 无法创建符号链接(symbolic link) : file exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27107347/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com