标签: sshkit

Capistrano日志级别

我已将Capistrano配置的日志级别设置error为阻止详细输出.在deploy.rb我补充说set :log_level, :error.这非常有效.但是,当我运行命令时execute,它不会被打印,因为它是在日志级别下写的DEBUG.如何获得execute要打印的命令输出?我可以使用capture它的组合puts来输出它,但是当我必须流式传输日志时这没有用.

logging capistrano capistrano3 sshkit

11
推荐指数
1
解决办法
9793
查看次数

Capistrano 3/SSHKit写入自定义任务中的文件

我想用我的版本号标记当前部署的目录.

我试过这种方法:

获取本地应用程序版本,将其存储到变量中,并在远程主机上将其存储在文件中.

namespace :deploy do
  desc "Set a release number as the app version"
  task :mark_release do
    release_number = `git describe`
      on roles(:web) do
        execute("echo #{release_number} > #{current_path}/RELEASE")
      end
    end
  end
Run Code Online (Sandbox Code Playgroud)

问题是,当我通过以下方式运行时:

cap deploy:mark_release
Run Code Online (Sandbox Code Playgroud)

命令看起来像这样:

echo v9.3.0-254-g178d1f8; > /foo/bar/current/RELEASE
Run Code Online (Sandbox Code Playgroud)

分号正在制造麻烦.我的RELEASE文件当然是空的.

我认为这是由于SSHKit的一些转义.

有线索吗?

ruby git deployment capistrano3 sshkit

7
推荐指数
1
解决办法
3168
查看次数

Rails 4,Capistrano 3在捆绑exec rake资产期间失败:预编译并返回rake stdout:Nothing

在rake资产期间使用Capistrano进行部署失败:预编译:

/usr/local/rvm/bin/rvm ruby-2.0.0-p353 do bundle exec rake assets:precompile
Run Code Online (Sandbox Code Playgroud)

提示响应此错误:

INFO [b438501f] Running /usr/local/rvm/bin/rvm ruby-2.0.0-p353 do bundle exec rake assets:precompile on 123.123.123.123

cap aborted!
rake stdout: Nothing written
rake stderr: Nothing written
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/sshkit-1.3.0/lib/sshkit/command.rb:94:in `exit_status='
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:142:in `block (4 levels) in _execute'
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:551:in `call'
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:551:in `do_request'
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:561:in `channel_request'
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:205:in `process'
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:269:in `wait'
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:164:in `block (2 levels) in _execute'
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:514:in `call'
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:514:in `do_open_confirmation'
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:545:in `channel_open_confirmation'
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:205:in `process'
/Users/osiris/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails rvm-capistrano ruby-on-rails-4 capistrano3 sshkit

7
推荐指数
1
解决办法
3730
查看次数

如何在脚本失败(错误)时继续并使用Capistrano 3捕获输出

在Capistrano 2.x中你可以简单地添加:on_error =>:像这样继续:

task :bad_script, :on_error => :continue do
    my_error = capture('/path/to/tomcat/shutdown.sh')
end
Run Code Online (Sandbox Code Playgroud)

我没有看到任何方法在Capistrano 3.x或ssh-kit(底层通信)中做到这一点.任何帮助将不胜感激.

task :bad_script do
  server_is_down
    on roles :all do
      begin
        server_is_down = capture('/path/to/tomcat/shutdown.sh')
      rescue
        #do something if server_is_down has the correct text
      end
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

我已尝试在开始/救援块中包围新方法,但这只会阻止它出错,但它不会返回错误的输出.

我仍然想知道如何做到这一点,但我想出了一个方法来解决我的一个案例,那就是如果失败就设置服务器.

task :bad_script do
  server_is_down = false
    on roles :all do
      begin
        execute('/path/to/tomcat/shutdown.sh')
      rescue
        server_is_down = true
      end
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

这假设它只在关闭发生时出错.

ruby deployment capistrano capistrano3 sshkit

5
推荐指数
1
解决办法
2103
查看次数

Capistrano 3.在服务器上设置bash shell而不是csh

当cap3尝试在我的FreeBSD服务器上执行命令时 - 我有错误,我的cap3任务不起作用

DEBUG [0bb99d53] Command: if test ! -d /home/web_server/data/www/capistrano/site/shared/dumps; then echo "Directory does not exist '/home/web_server/data/www/capistrano/site/shared/dumps'" 1>&2; false; fi
DEBUG [0bb99d53]    if: Expression Syntax.
DEBUG [0bb99d53]    fi: Command not found.
Run Code Online (Sandbox Code Playgroud)

我知道为什么 - 因为我的服务器默认使用csh shell

% echo $0
-csh
Run Code Online (Sandbox Code Playgroud)

以下cap3变量对我不起作用

set :shell, '/usr/local/bin/bash'
set :default_shell, '/usr/local/bin/bash'
Run Code Online (Sandbox Code Playgroud)

如何为cap3任务设置shell?

shell capistrano3 sshkit

5
推荐指数
1
解决办法
609
查看次数

Capistrano中执行,测试和捕获命令有什么区别?

SSHkit-Github上它说:

所有后端都支持执行(*args),test(*args)和capture(*args)

SSHkit-Rubydoc,我理解execute实际上是一个别名test吗?

是什么区别test,execute,captureCapistrano酒店/SSHKit以及何时应该使用要么?

ruby capistrano sshkit

5
推荐指数
1
解决办法
1385
查看次数

Capistrano 3:如何抑制状态输出?

我创建了一个 Capistrano 任务来执行 rake 命令。我计划将输出(STDOUT)重定向到文件。例如

\n\n

cap production invoke:rake TASK=mytask > out

\n\n

这可行,但我的输出包括一些额外的 Capistrano 状态输出,例如

\n\n

00:00 invoke:rake\n 01 $HOME/.rbenv/bin/rbenv exec bundle exec rake mytask\n...\n \xe2\x9c\x94 01 ubuntu@mydomain.com 11.399s\n

\n\n

有什么办法可以抑制这种情况吗?

\n

capistrano capistrano3 sshkit

5
推荐指数
1
解决办法
472
查看次数

显示SSHKit调用的rake任务的输出

我希望能够从SSHKit调用的rake任务中输出信息,但是我看不到该怎么做。

说我有以下抽佣任务:

require 'sshkit/dsl'

task :hello => :environment do  
  puts "Hello world"
end

task :sshkit_hello => :environment do  
  run_locally do
    rake "hello"  
  end
end
Run Code Online (Sandbox Code Playgroud)

如果我自己运行:hello任务,我会看到“ hello world”语句。但是,从sshkit任务调用它,我只得到SSHKit信息。如何从SSHKit调用时出现的第一个rake任务中写出信息?

rake hello
=> Hello world

rake sshkit_hello
=> INFO [f0857f14] Running /usr/bin/env rake hello on 
=> INFO [f0857f14] Finished in 6.107 seconds with exit status 0 (successful).
Run Code Online (Sandbox Code Playgroud)

编辑1:

我发现您可以添加以下内容以获得基本的终端输出:

SSHKit.config.output = $stdout 
Run Code Online (Sandbox Code Playgroud)

但是,再次输出的信息是相同的-它告诉您它正在运行“ rake hello”,而不是“ rake hello”的输出。

rake sshkit_hello
=> rake hello
Run Code Online (Sandbox Code Playgroud)

ruby rake ruby-on-rails sshkit

1
推荐指数
1
解决办法
863
查看次数