【发布时间】:2015-03-29 00:22:48
【问题描述】:
我正在尝试为我的应用程序组合一个 capistrano 配方,该配方基本上在本地克隆 git 存储库,进行一些构建处理,然后 rsync 到远程服务器。
我有 2 个环境 - dev 和 prod:
deploy.rb
deploy/dev.rb
deploy/prod.rb
我收到此错误:
$ cap dev deploy
(Backtrace restricted to imported tasks)
cap aborted!
Don't know how to build task 'stop_server'
Tasks: TOP => dev
(See full trace by running task with --trace)
如果部署在dev.rb 的同一命名空间(部署)中,为什么部署不知道如何构建任务stop_server?
Capfile
# Load DSL and set up stages
require 'capistrano/setup'
# Include default deployment tasks
#require 'capistrano/deploy' # COMMENTED OUT B/C I'M TRYING TO BUILD LOCALLY INSTEAD OF DOING A GIT CLONE ON THE REMOTE SERVER
# Load custom tasks from `lib/capistrano/tasks' if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
部署.rb
# config valid only for current version of Capistrano
lock '3.3.5'
set :repo_url, 'mygiturl'
# Default value for :pty is false
set :pty, true
set :deploy_dir, Dir.pwd
set :tmp_dir, "#{fetch(:deploy_dir)}/tmp"
set :output_dir, "#{fetch(:deploy_dir)}/output"
namespace :deploy do
desc 'Kick off the deploy'
task :init do
invoke 'deploy:create_tmp_dir'
end
... other tasks...
after :create_tmp_dir, :fetch_code
after :fetch_code, :build
after :build, :move_output
after :move_output, :stop_server
end
desc 'Deploy a new release'
task :deploy do
invoke 'deploy:init'
end
dev.rb
role :app, fetch(:application)
role :web, fetch(:application)
role :db, fetch(:application)
set :application, 'myapp'
set :env, 'dev'
set :ip, '123.456.78.901'
set :user, 'myuser'
set :deploy_to, '/var/www/myapp'
set :ssh_options, {
user: fetch(:user),
keys: %w(~/.ssh/id_rsa),
forward_agent: true,
auth_methods: %w(publickey),
port: 22
}
namespace :deploy do
desc "Stops the node forever server"
task :stop_server do
on roles(:app) do
puts '**** STOPPING THE NODE SERVER *****'
execute 'sudo /etc/init.d/myapp stop; true' # The "; true" ignores any error that may occur if there is no forever process running
end
end
desc "Restarts the forever server"
task :start_server do
on roles(:app) do
puts '**** STARTING THE NODE SERVER *****'
execute 'sudo /etc/init.d/myapp start'
end
end
end
【问题讨论】:
标签: ruby capistrano capistrano3