Skip to content

Conversation

@miry
Copy link
Contributor

@miry miry commented Nov 29, 2013

Hi @leehambley

To add ability to run interactive rails console before for capistrano 2 we could do:

desc "Remote console on the production appserver"
task :console, :roles => :app do
  input = ''
  run "cd #{current_path} && ./script/console production" do |channel, stream, data|
    next if data.chomp == input.chomp || data.chomp == ''
    print data
    channel.send_data(input = $stdin.gets) if data =~ /^(>|\?)>/
  end
end

this solution does not work for v3, and I could not find similar.
I have patched a SSHKit to execute interactive rails console:

https://gist.github.com/miry/7196069.

Can you advice me another solution?

Also I think to store the channel and then we can redefine on_data or another callback method, or add block to execute method with same functionality like old run.

@leehambley
Copy link
Member

Thanks @miry I'd be happy to pull a change request if you can figure a sane way to test this, and not break backwards compatibility.

I think tools like expect are better for scripting interactive sessions, but I'm not opposed to exposing this Net::SSH for special cases if it doesn't break anything.

@miry
Copy link
Contributor Author

miry commented Nov 29, 2013

I updated the _execute method for Local and Netssh backends to allow use blocks as callback to on data action.

Example: Remote rails console using the new behavior of the execute

namespace :rails do
  desc 'Execute rails console'
  task :console do
    on roles(:app) do
      within release_path do
        with rails_env: fetch(:rails_env) do
          command = ''
          execute(:rails, :console) do |ch, data|
            next if data.chomp == command.chomp || data.chomp == ''
            print data
            ch.send_data command = $stdin.gets if data =~ /^(>|\?)>/
          end
        end
      end
    end
  end
end

@leehambley
Copy link
Member

I really don't want to merge this. See GNU expect if you need to do
something like this.

Sent from my Nexus 4.
On 30 Nov 2013 00:03, "Michael Nikitochkin" notifications@github.com
wrote:

I updated the _execute method for Local and Netssh backends to allow use
blocks as callback to on data action.

Example: Remote rails console using the new behavior of the execute

namespace :rails do
desc 'Execute rails console'
task :console do
on roles(:app) do
within release_path do
with rails_env: fetch(:rails_env) do
row , command = '', ''
execute(:rails, :console) do |ch, data|
row += data
if data.include?("\n")
print row if command.chomp != row.chomp
row = ''
elsif data.include?('irb(main):')
print row
row = ''
command = $stdin.gets
command = "exit\n" if command == nil
ch.send_data command
end
end
end
end
end
endend


Reply to this email directly or view it on GitHubhttps://github.com//pull/40#issuecomment-29540863
.

@miry
Copy link
Contributor Author

miry commented Nov 30, 2013

@leehambley if I rewrite this with IO#expect, will you merge it?
or can you suggest how I can implement remote rails console without such changes?

@leehambley
Copy link
Member

That's not a valid usecase for remote automation! I'm not bear a computer
right now, bit changing the Api this way massively, massively increases
support requirements as people will start to do stupid things like using
this to enter passwords in things that should be scripted. If there's any
chance of merging this it'll need to be functionally and integration tested
(see the pending vagrant stuff, here or in Capistrano) and have EXTENSIVE
docs and warnings.

Why would you possibly want to use sshkit to script something like this
when you can do it with netssh?

Sent from my Nexus 4.
On 30 Nov 2013 09:46, "Michael Nikitochkin" notifications@github.com
wrote:

@leehambley https://github.com/leehambley if I rewrite this with
IO#expect will you merge it?
or can you suggest how I can implement remote rails console without such
changes?


Reply to this email directly or view it on GitHubhttps://github.com//pull/40#issuecomment-29548467
.

@miry
Copy link
Contributor Author

miry commented Nov 30, 2013

@leehambley I added functional tests. It would not harm any present code. I don't want to duplicate the same logic of execution to use netssh. I also added support for local backend.

I am working on refactoring and readme docs.

@leehambley
Copy link
Member

I still hate the use case. gnu expect is sufficient for scripting short
interactions with interactive programmes. I can't promise I'll merge this
if you do bring it up to scratch. It makes what is supposed to be a
simplification horribly convoluted. And a tool for automation rely on and
encourage human interaction.

Sent from my Nexus 4.
On 30 Nov 2013 10:22, "Michael Nikitochkin" notifications@github.com
wrote:

@leehambley https://github.com/leehambley I added functional tests. It
would not harm any present code. I don't want to duplicate the same logic
of execution to use netssh. I also added support for local backend.

I am working on refactoring and readme docs.


Reply to this email directly or view it on GitHubhttps://github.com//pull/40#issuecomment-29548891
.

@miry
Copy link
Contributor Author

miry commented Nov 30, 2013

@leehambley I have slit this PR to small ones. And the main is #65. As you can see it is quite simple.

@leehambley
Copy link
Member

I really can't see myself merging it, the more I think about it the more it
seems like an awful idea. Either you are connecting to one server, and this
doesn't make sense, or more than one and the idea of "same input
everywhere" makes no sense, finally, what you want to do can be done better
with a terminal multiplexor, or just with netssh. It doesn't belong here.

Sent from my Nexus 4.
On 30 Nov 2013 10:58, "Michael Nikitochkin" notifications@github.com
wrote:

@leehambley https://github.com/leehambley I have slit this PR to small
ones. And the main is #65 #65.
As you can see it is quite simple.


Reply to this email directly or view it on GitHubhttps://github.com//pull/40#issuecomment-29549445
.

@miry miry closed this Nov 30, 2013
@joost
Copy link

joost commented Mar 4, 2014

For future readers that want a rails console in capistrano 3. Check https://gist.github.com/joost/9343156.

@leehambley
Copy link
Member

Thought about packaging this as a Gem? (Cap 3 already includes a
rudimentary console)

Lee Hambley

http://lee.hambley.name/
+49 (0) 170 298 5667

On 4 March 2014 12:09, Joost Hietbrink notifications@github.com wrote:

For future readers that want a rails console in capistrano 3. Check
https://gist.github.com/joost/9343156.


Reply to this email directly or view it on GitHubhttps://github.com//pull/40#issuecomment-36613928
.

@miry
Copy link
Contributor Author

miry commented Mar 4, 2014

:)

https://github.com/jetthoughts/j-cap-recipes/blob/master/lib/j-cap-recipes/tasks/rails.rake

Using SshCommand addon you can run any command interactive.

https://github.com/jetthoughts/j-cap-recipes#sshkit-addon

Cap 3 has console, but it does not interactive.

@afeld
Copy link

afeld commented Jan 2, 2015

I blatantly stole @miry's work and made a standalone gem, SSHKit::Interactive. Would love feedback.

@miry
Copy link
Contributor Author

miry commented Jan 2, 2015

@afeld nice 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants