rye / 0.8.4
| Short description: | Run SSH commands on a bunch of machines safely and in parallel | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Category: | Library/Net | |||||||||||||
| Status: | beta | |||||||||||||
| Created: | 2009-04-05 02:50:24 GMT | |||||||||||||
| Last update: | 2009-07-01 02:41:34 GMT | |||||||||||||
| Owner: | delano (Projects of this owner) | |||||||||||||
| Homepage: | http://github.com/delano/rye | |||||||||||||
| Download: | http://github.com/delano/rye/tarball/latest | |||||||||||||
| License: | BSD-type | |||||||||||||
| Dependency: |
|
|||||||||||||
| Description: | Rye - v0.8Safely run SSH commands on a bunch of machines at the same time (from Ruby). Update 2009-06-30Now supports JRuby 1.3+! OverviewRye is similar to Rush but everything happens over SSH (no HTTP daemon) and the default settings are less powerful (for safety). For example, file globs and the "rm" command are disabled so unless otherwise specified, you can’t do this: rbox.rm(’-rf’, ’/etc/**/*’). InstallationOne of:
$ sudo gem install rye
$ sudo gem install delano-rye --source http://gems.github.com/
$ git clone git://github.com/delano/rye.git
See bin/try for examples! EXAMPLE 1 — SSH AuthorizationDoes it annoy you to manually authorize remote SSH accounts? Rye can help! Enable passwordless logins to HOST1 and HOST2:
$ rye authorize HOST1 HOST2
This will copy your public SSH keys to the ~/.ssh/authorized_keys and ~/.ssh/authorized_keys2 files on the remote machine(s). See rye -h for more info EXAMPLE 2 — Basic Usage
rbox = Rye::Box.new('localhost')
rbox.uptime # => 11:02 up 16:01, 3 users
rbox['/usr/bin'].pwd # => /usr/bin
You can specify environment variables
rbox.setenv(:RYE, "Forty Creek")
rbox.env # => ['HOME=/home/rye', 'RYE=Forty Creek', ...]
EXAMPLE 3a — Accessing Multiple Machines
rset = Rye::Set.new
rbox = Rye::Box.new
rset.add_boxes(rbox, 'localhost') # Add boxes as hostnames or objects
Calling methods on Rye::Set objects is very similar to calling them on Rye::Box objects. In fact, it’s identical:
p rset.uptime # => [[14:19:02 up 32 days, 19:35 ...], [14:19:02 up 30 days, 01:35]]
p rset['/etc'].ls # => [['file1', 'file2', ...], ['life1', 'life2', ...]]
EXAMPLE 3b — Accessing Multiple Machines — In ParallelBy default, Rye:Set connects to each machine sequentially in the order they were added to the set. Commands can also be run in parallel:
rset = Rye::Set.new('set-name', :parallel => true)
OR
rset.parallel = true
EXAMPLE 4 — File Transfers
rbox = Rye::Box.new("localhost", :info => true)
dir_upload = "#{Rye.sysinfo.tmpdir}/rye-upload/"
dir_download = "#{Rye.sysinfo.tmpdir}/rye-download/"
rbox.file_upload("#{RYE_HOME}/README.rdoc", "#{RYE_HOME}/LICENSE.txt", dir_upload)
applejack = StringIO.new("Some in-memory content")
rbox.file_upload(applejack, "#{dir_upload}/applejack.txt")
p rbox.ls(dir_upload) # => [README.rdoc, LICENSE.txt, applejack.txt]
p rbox.cat("#{dir_upload}/applejack.txt") # => "Some in-memory content"
filecontent = StringIO.new
rbox.file_download("#{dir_upload}/applejack.txt", filecontent)
p filecontent.read
EXAMPLE 5 — Local processesFor local processes, you can bypass Rye::Box and execute commands directly with Rye.shell:
Rye.shell :uptime # => 11:02 up 16:01, 3 users
The first argument must be the command name and the remaining arguments are sent directly as arguments to the command. They’re not escaped like with Rye::Box so you can use the asterisk, environment variables, pipes, and redirects etc. Also note that you can specify single character switches as symbols and you can separate arguments or put them into a single String.
Rye.shell :ls, '*'
Rye.shell :ls, '-l $HOME'
Rye.shell :ls, :l, '$HOME > $TMPDIR/crazy.txt'
The return value is a Rye::Rap object (just like with Rye::Box) so you have access to the exit code and STDERR output:
ret = Rye.shell :ls, 'nofile'
ret.exit_code # => 1
ret.stderr # => "sh: nofile: No such file or directory"
ret.class # => Rye::Rap
About Safe-ModeIn safe-mode:
Why? In safe-mode, all command arguments are escaped which turns all arguments into their literal values. Using a Ruby interface to execute shell commands is pretty awesome, particularly to run them on several machines simultaneously. That’s a lot of power and it’s potentially very dangerous. That’s why Rye disables this stuff by default. There’s probably a way to do it safely but it’s not obvious yet (to me). If you have any ideas, I’d love to hear them! Command WhitelistRye permits only a limited number of system commands to be run. This default whitelist is defined in Rye::Cmd but you can add your own commands as you please (see Example 3). Dependencies
Known IssuesThis list will grow. If you find one let me know!
Thanks
More InfoCredits
LicenseSee: LICENSE.txt |
|||||||||||||
| Versions: | [0.8.5 (2009-07-16)] [0.8.4 (2009-07-01)] [0.7.4 (2009-06-04)] [0.6.2 (2009-04-30)] [0.5.0 (2009-04-18)] [0.3.1 (2009-04-05)] | |||||||||||||