我正在尝试为我的网站设置Capistrano部署,我已经部署了工作,所有身份验证都很好,但是我使用Media temple进行托管,因此默认符号链接将无法正常运行,因为apache将无法访问为当前指定的路径最新发布的.
我正在尝试创建一个将取消链接当前符号链接的任务,然后使用相对路径重新创建它,但是Capistrano文档严重缺乏,我无法找到任何更多信息,无论如何设置它.
我已经尝试过使用sh,但是这似乎是在我的计算机上而不是在服务器上运行命令,找不到运行命令,我尝试执行但无法找到正确的格式来执行rm,或ln等操作. .
目前我正在尝试以下方法:
namespace :deploy do desc "Change HTML Symlink to relative path" task :create_symlink do #latest_release_relative = relative_path(deploy_to,release_path + '/html') #sh "rm -f #{current_path} && ln -s #{latest_release_relative} #{current_path}" #sh "echo #{File.basename release_path}" info "echo Modifying symlink to be relative" #run "rm -d #{current_path}" #run "ln releases/#{File.basename release_path} #{current_path}" #execute :rm,'-d',#{current_path} end desc "Create environment file" task :create_env_conf file 'env.conf' do |t| sh "touch env.conf" end end after :deploy,"deploy:create_symlink","deploy:create_env_conf"
解决方法
经过大量的反复试验,我发现问题就是这样;
>需要在cap v3中使用execute
>需要使用&&和cd然后链命令用于运行目录特定的命令
> Capistrano需要更多文档……
这就是我的工作方式,我认为有更好的方法可以使用Capistrano 3,但我找不到足够的文档描述如何在任何地方.
#config valid only for Capistrano 3.1 lock '3.1.0' set :application,'prism-credentials' set :repo_url,'REPO URL' # Default deploy_to directory is /var/www/my_app set :deploy_to,'DEPLOY FOLDER' # Default value for keep_releases is 5 set :keep_releases,5 set :branch,"master" if ENV['branch'] set :branch,ENV['branch'] end namespace :deploy do desc "Change HTML Symlink to relative path" task :create_symlink do on roles(:app) do #execute "ls -l" info "Modifying symlink to be relative" execute "rm -d #{current_path}" info "Deleted current symlink" execute "cd ../DEPLOY FOLDER && ln -s ./releases/#{File.basename release_path} current" info "Created relative current symlink" execute "cd ~/../DEPLOY FOLDER && touch env.conf && echo 'live' >> env.conf" info "Created environment file" end end end after :deploy,"deploy:create_symlink"