Capistrano多级 - 不创建dev / prod符号链接(仅限'当前')

时间:2012-04-13 21:28:16

标签: ruby-on-rails git capistrano multistage

我之前已经设置好了,但现在无法让它工作。我想要一个开发和生产网站。当我进行封面部署时,它会设置一个“当前”的符号链接(不知道我是怎么做的,因为很长一段时间它甚至都不会这样做)。但是如何让它为dev / prod部署和设置必要的符号链接呢?

我的deploy.rb文件:

#require 'bundler/capistrano'
require 'capistrano/ext/multistage'
require 'capistrano_colors'

set :stages, %w(development production)
set :default_stage, 'development'

set :application, "myapp"
set :repository,  "***"

# Target directory on the server
set :deploy_to, "/var/www/#{application}"

set :scm, :git
set :deploy_via, :remote_cache

set :user, '***'
set :use_sudo, false

role :web, "68.225.130.30"                          # Your HTTP server, Apache/etc
role :app, "68.225.130.30"                          # This may be the same as your `Web` server
role :db,  "68.225.130.30", :primary => true # This is where Rails migrations will run

# List of symlinks to be generated. Keys are subdirectories of release_path.
SYMLINKS = { :config => ['database.yml'],
             :public => ['system'] }

namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
    # Not working =/
    #run "touch /var/www/#{current_path}/tmp/restart.txt"
  end

  desc "Set up application symlinks."
  task :app_symlinks do
    SYMLINKS.keys.each do |key|
      dir = key.to_s
      SYMLINKS[key].each do |path|
        run "ln -nfs #{shared_path}/#{dir}/#{path} #{release_path}/#{dir}/#{path}"
      end
    end
  end
end

我的deploy / development.rb文件:

set :deploy_to, "/var/www/#{application}"
set :branch, "master"
unset :rails_env
set :rails_env, "development"

UPDATE /解答:

问题在于current_path变量。自从我尝试使用

以来很奇怪

set:current_path,“development”

set:current_path,“#{application} / development”

它不起作用。看起来我必须设置整个路径,这似乎很奇怪,因为我之前使用过后者。

set :current_path, "/var/www/#{application}/development"

任何人都知道为什么?

1 个答案:

答案 0 :(得分:0)

:current_path由capistrano根据:deploy_to路径+:应用程序名称设置。您只能在命名空间任务中使用:current_path。

换句话说,它是一个便利变量,用于创建符号链接,重新启动服务器和其他任务。