Anton Evangelatov
Anton Evangelatov

Reputation: 1417

Rails application to run commands on remote machine

I have a Ruby on Rails 3 application, that I would like to control a remote machine via SSH access.

Basically I would like the Rails application to be able to edit files, copy them, move directories, etc. on a remote machine via SSH.

I have already created Capistrano tasks for the functions I would like to execute, but I would like to know:

  1. What is the best practice of running remote shell code from Rails
  2. How can I invoke Capistrano tasks from a Rails application (which would basically achieve 1)

Thanks!

Upvotes: 1

Views: 1648

Answers (1)

corprew
corprew

Reputation: 2001

For #1, ruby has a net-ssh library -- http://net-ssh.rubyforge.org/ -- that includes the functionality you want.

For #2, The accepted answer to this question has the information to run Capistrano tasks from inside of rails -- Is there a better way to run a capistrano task from within rake?

Although the text says rake, it also applies to ruby generally. It should be noted, though, that depending on how your host is configured, you may have trouble with the way that Capistrano creates subshells to execute scripts, so you may need to play around with this for a bit or post a follow-up question

Upvotes: 1

Related Questions