问题描述
我刚刚完成了我的capistrano安装。大部分内容都是默认设置,我配置了我的服务器,认证和远程文件夹,以及对我的git仓库的访问。我使用capistrano将php代码部署到我的服务器。
cap staging deploy 和 cap production deploy 他们每次运行两次命令。如果在服务器上执行的任务太快,返回错误代码会导致部署过程停止,有时会导致问题。
运行时的输出示例 cap staging deploy
DEBUG [47ecea59]运行/ usr / bin / env if test! -d〜/ www / test_server / repo;然后回显目录不存在〜/ www / test_server / repo'1& 2;假; fi on ftp.cluster013.ovh.net
DEBUG [47ecea59]命令:if test! -d〜/ www / test_server / repo;然后回显目录不存在〜/ www / test_server / repo'1& 2;假; fi
DEBUG [c450e730]运行/ usr / bin / env如果测试! -d〜/ www / test_server / repo;然后回显目录不存在〜/ www / test_server / repo'1& 2;假; fi on ftp.cluster013.ovh.net
DEBUG [c450e730]命令:if test! -d〜/ www / test_server / repo;然后回显目录不存在〜/ www / test_server / repo'1& 2;假; fi
除了我自己定义的一个以外, rb,我定义了一个:set_distant_server任务,它围绕带有服务器信息的文件移动)
我很确定我在初始配置期间错过了一些东西。 b
这是我的capfile,仍然是默认设置:
#加载DSL和设置Up阶段
需要'capistrano / setup'
#包括默认部署任务
需要'capistrano / deploy'
#包含您的Gemfile中包含的其他宝石的任务
#require'capistrano / rvm'
#require'capistrano / rbenv'
#require'capistrano / chruby'
#require'capistrano / bundler'
#require 'capistrano / rails / assets'
#require'capistrano / rails / migrations'
#如果您有任何定义,从`lib / capistrano / tasks'加载自定义任务。
Dir.glob('lib / capistrano / tasks / *。rake')。each {| r | import b}
紧跟在我的deploy.rb文件中:
#config仅对Capistrano有效3.1
lock'3.2.1'
set:scm,:git
set:application,'应用程序名'
#我使用令牌认证
设置:repo_url,'https:// XXXXXXXXXXX:@ XXXXXXX.git'
设置:角色,'web'
#默认值为:log_level为:debug
set:log_level,:debug
set:tmp_dir,'www / test_server / tmp'
set:keep_releases ,8
角色:deploy_server,XXXuser_name @ XXXX_server
任务:set_distant对角色执行
(:deploy_server)
执行'echo ------------ ******* STAGING ******* ------------'
执行'cp 〜/ www / test_server / current / access_distant.php〜/ www / test_server / current / access.php'
执行'cp〜/ www / test_server / current / session_distant.php〜/ www / test_server / current / session .php'
结束
结束
在deploy:finished之后,::set_distant
这是我的staging.rb,更短:
服务器'XXX_server',用户:'XXXuser_name',角色:%w {web},端口:22,密码:'XXXpassword'
set:deploy_to,'〜/ www / test_server'
set:branch,'staging'
和我的production.rb非常相似:
server'XXX_server',user:' XXXuser_name',角色:%w {web},端口:22,密码:'XXXpassword'
set:deploy_to,'〜/ www / beta /'
我很确定我错过了所有先决条件中的一步,使其运行良好。我对红宝石,宝石很陌生,很久没有使用贝壳。
有人知道为什么这些命令运行了两次,而我该如何修复它?
非常感谢。
其他信息:
Ruby版本:ruby -v
ruby 2.1.2p95(2014-05-08修订版)45877 [
Capistrano版本:cap -V
Capistrano版本:3.2.1(Rake版本:10.1.0)
我没有创建Gemfile或设置它,我知道它在Capistrano 3中不需要。无论如何,我不知道如何去做。
我遇到了同样的问题,并且意识到我不需要两者。 code>角色:web
和
server'< server>'
摆脱角色:网络,并摆脱了第二次执行。
I just completed my capistrano installation for the first time. Most of everything is left to default settings, I configured my server, its authentification, and the remote folder, as well as the access to my git repository.
I use capistrano to deploy php code to my server.
cap staging deploy and cap production deploy function, but they run every command twice. It sometimes causes problems when those tasks are executed too quickly on the server, returning error codes, which stops the deploying process.
an example of my output when running cap staging deploy
DEBUG[47ecea59] Running /usr/bin/env if test ! -d ~/www/test_server/repo; then echo "Directory does not exist '~/www/test_server/repo'" 1>&2; false; fi on ftp.cluster013.ovh.net
DEBUG[47ecea59] Command: if test ! -d ~/www/test_server/repo; then echo "Directory does not exist '~/www/test_server/repo'" 1>&2; false; fi
DEBUG[c450e730] Running /usr/bin/env if test ! -d ~/www/test_server/repo; then echo "Directory does not exist '~/www/test_server/repo'" 1>&2; false; fi on ftp.cluster013.ovh.net
DEBUG[c450e730] Command: if test ! -d ~/www/test_server/repo; then echo "Directory does not exist '~/www/test_server/repo'" 1>&2; false; fi
It does the same with every single task, except the one I defined myself (in my deploy.rb, I defined a :set_distant_server task that moves around files with server info)
I am pretty sure I missed something during the initial configuration.
Here is my capfile, still to default settings :
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
# Includes tasks from other gems included in your Gemfile
# require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
#require 'capistrano/bundler'
#require 'capistrano/rails/assets'
#require 'capistrano/rails/migrations'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
Followed by my deploy.rb file: # config valid only for Capistrano 3.1 lock '3.2.1'
set :scm, :git
set :application, 'Application name'
# I use token authentification
set :repo_url, 'https://XXXXXXXXXXX:@XXXXXXX.git'
set :role, 'web'
# Default value for :log_level is :debug
set :log_level, :debug
set :tmp_dir, 'www/test_server/tmp'
set :keep_releases, 8
role :deploy_server, "XXXuser_name@XXXX_server"
task :set_distant do
on roles(:deploy_server) do
execute 'echo ------------******* STAGING *******------------'
execute 'cp ~/www/test_server/current/access_distant.php ~/www/test_server/current/access.php'
execute 'cp ~/www/test_server/current/session_distant.php ~/www/test_server/current/session.php'
end
end
after "deploy:finished", :set_distant
Here is my staging.rb, much shorter:
server 'XXX_server', user: 'XXXuser_name', roles: %w{web}, port: 22, password: 'XXXpassword'
set :deploy_to, '~/www/test_server'
set :branch, 'staging'
And my production.rb, very similar:
server 'XXX_server', user: 'XXXuser_name', roles: %w{web}, port: 22, password: 'XXXpassword'
set :deploy_to, '~/www/beta/'
I'm pretty sure I missed a step in all the prerequisites to make it run nicely. I am new to ruby, to gems, and didn't use shell for a very long time.
Does anyone see why those commands are run twice, and how I could fix it?
In advance, many many thanks.
Additional info:Ruby version: ruby -vruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
Capistrano version: cap -VCapistrano Version: 3.2.1 (Rake Version: 10.1.0)
I did not create a Gemfile or set it up, I understood it was not needed in Capistrano 3. Anyway, I would not know how to do it.
I was having this same issue and realized I didn't need both
role :web
and
server '<server>'
I got rid of role :web and that got rid of the 2nd execution.
这篇关于Capistrano 3运行每个命令两次(新安装) - 配置问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!