我有多阶段多服务器设置,在我的任务中我需要使用服务器名称,例如在stagin.rb我有:
set :stage, :staging
# Define servers
server 'xxx.xx.xx.xxx', user: 'deploy', roles: %w{app}, name: 'app1'
server 'xxx.xx.xx.yyy', user: 'deploy', roles: %w{app}, name: 'app2'
Run Code Online (Sandbox Code Playgroud)
我想在我的任务中使用"name"变量:
task :configure do
on roles(:app), in: :parallel do
# how do I get server name here?
end
end
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用capistrano(第一次)部署我的rails应用程序.首先要点,我正在使用:
尝试运行时出现以下错误 cap production deploy
DEBUG [679a47be]致命:没有远程配置列出引用.
我的完整cap production deploy
输出包括在下面
INFO [488ba755] Running /usr/bin/env mkdir -p /tmp/AppName/ on sub.example.com
DEBUG [488ba755] Command: /usr/bin/env mkdir -p /tmp/AppName/
INFO [488ba755] Finished in 1.730 seconds with exit status 0 (successful).
DEBUG Uploading /tmp/AppName/git-ssh.sh 0.0%
INFO Uploading /tmp/AppName/git-ssh.sh 100.0%
INFO [c895f068] Running /usr/bin/env chmod +x /tmp/AppName/git-ssh.sh on sub.example.com
DEBUG [c895f068] Command: /usr/bin/env chmod +x /tmp/AppName/git-ssh.sh
INFO [c895f068] Finished in …
Run Code Online (Sandbox Code Playgroud) 我正在使用Capistrano 3:
? webapp git:(rails) ? cap --version
Capistrano Version: 3.1.0 (Rake Version: 10.1.1)
Run Code Online (Sandbox Code Playgroud)
我Capfile
是:
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/rvm'
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/*.cap').each { |r| import r }
Run Code Online (Sandbox Code Playgroud)
而我的deploy.rb
是:
set :rvm_type, :user
set :application, "my_app"
set :scm, :git
set :repo_url, 'git@github.com:nanounanue/my_app.git'
set :scm_passphrase, ""
set :ssh_options, …
Run Code Online (Sandbox Code Playgroud) 在我的ruby on rails项目中,我使用capistrano,unicorn,postgresql和nginx来部署我的项目.当我运行时,cap production git:check
我收到此错误:
Error reading response length from authentication socket.
Run Code Online (Sandbox Code Playgroud)
日志跟踪:
INFO [13522bc0] Running /usr/bin/env mkdir -p /tmp/deploy_test/ as mezbah@192.168.137.130
DEBUG [13522bc0] Command: /usr/bin/env mkdir -p /tmp/deploy_test/
INFO [13522bc0] Finished in 0.291 seconds with exit status 0 (successful).
DEBUG Uploading /tmp/deploy_test/git-ssh.sh 0.0%
INFO Uploading /tmp/deploy_test/git-ssh.sh 100.0%
INFO [3b379ef0] Running /usr/bin/env chmod +x /tmp/deploy_test/git-ssh.sh as mezbah@192.168.137.130
DEBUG [3b379ef0] Command: /usr/bin/env chmod +x /tmp/deploy_test/git-ssh.sh
INFO [3b379ef0] Finished in 0.067 seconds with exit status 0 (successful).
INFO [8355617a] Running …
Run Code Online (Sandbox Code Playgroud) 有人在运行后遇到此错误:
cap production deploy
Run Code Online (Sandbox Code Playgroud)
我正在使用capistrano:Capistrano版本:3.6.1(耙子版本:11.3.0)
这是日志:
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@54.169.99.36: rake exit status: 1
rake stdout: rake aborted!
Don't know how to build task 'assets:precompile' (see --tasks)
/home/deploy/microwave-api/shared/bundle/ruby/2.3.0/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
.
.
.
/home/deploy/.rvm/gems/ruby-2.3.0/gems/bundler-1.13.6/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/home/deploy/.rvm/gems/ruby-2.3.0/gems/bundler-1.13.6/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/home/deploy/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)
rake stderr: Nothing written
SSHKit::Command::Failed: rake exit status: 1
rake stdout: rake aborted!
Don't know how to build task 'assets:precompile' (see --tasks)enter code here
Run Code Online (Sandbox Code Playgroud) 在此之前3.0
有一种方法可以做到这一点:
# ...
set :mysql_password, proc { Capistrano::CLI.password_prompt "Gimme remote database server password. Don't worry, I won't tell anyone: " }
# ...
namespace :db do
desc 'Dump remote database'
task :dump do
run "mysqldump -u #{mysql_user} -p #{mysql_database} > ~/#{mysql_database}.sql" do |channel, stream, data|
if data =~ /^Enter password:/
channel.send_data "#{mysql_password}\n"
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
它提示输入密码,在您键入时不显示密码,并且在日志和输出中不留下任何痕迹.
现在,作为3.0
我发现的唯一方式:
# ...
namespace :db do
desc 'Dump remote database'
task :dump do
ask :mysql_password, nil
on roles(:db) do …
Run Code Online (Sandbox Code Playgroud) 我在命名空间中有一个命名空间和几个任务,在deploy:updated之后运行.这是一个例子:
namespace :myservice do
task :start do
on roles(:app) do
sudo :start, "my/application"
end
end
end
Run Code Online (Sandbox Code Playgroud)
我喜欢这些任务中的一个只能在特定环境或主机属性上运行.我怎么能做到这一点?
我希望能够过滤环境,例如:
namespace :myservice do
task :start do
on roles(:app), env(:vagrant) do
sudo :start, "my/application"
end
end
end
Run Code Online (Sandbox Code Playgroud)
完成此任务的最佳方法是什么?
在Capistrano 2中,你可以这样做:
set :default_environment, {
'PATH' => '$PATH:/opt/rubies/ruby-2.1.1/bin'
}
Run Code Online (Sandbox Code Playgroud)
是否有上限3的等价物?
我有以下capistrano 3任务:
desc 'Add root scheduled tasks'
task :root_schedules do
on roles(:all) do
within release_path do
execute :sudo, :bundle, 'exec whenever -w config/root_schedule.rb -u root'
end
end
end
Run Code Online (Sandbox Code Playgroud)
我需要使用sudo权限运行此任务,因为我需要以更高权限运行计划任务.这些是后端计划的服务器任务.问题是我每次运行此命令时都会得到以下信息:
DEBUG [46d3800c] [sudo] password for [user]
Run Code Online (Sandbox Code Playgroud)
输入密码后按Enter键,它永远不会完成任何操作.完全没有回应.有答案吗?
本地操作系统:Windows 10 Pro(使用 Git Bash 作为我的终端)
暂存服务器操作系统:Ubuntu 16.04 LTS
我一直在努力让基本的 Capistrano 部署在我的登台服务器上工作。我按照本指南设置了 Capistrano。
git:check
由于据称无权访问我在 GitLab上的存储库,部署过程总是在舞台上失败。我确信我的 SSH 代理转发工作正常,因为我能够通过 SSH 连接到我的服务器并使用我的 SSH 密钥访问 GitLab。SSH 密钥未存储在我服务器上的任何位置:
$ ssh deploy@myserver.com
deploy@MyServer:~$ ssh -T git@gitlab.com
debug1: client_input_channel_open: ctype auth-agent@openssh.com rchan 2 win 65536 max 16384
debug1: channel 1: new [authentication agent connection]
debug1: confirm auth-agent@openssh.com
Welcome to GitLab, Alexander!debug1: channel 1: FORCE input drain
Run Code Online (Sandbox Code Playgroud)
到目前为止,关于这个问题的所有问题都没有对我有用。
这是我的部署文件:
部署文件
set :application, "myapp"
set :branch, "master"
set :repo_url, "git@gitlab.com:MyApp/myapp.git"
# Defaults to false
# Skip …
Run Code Online (Sandbox Code Playgroud)