Class: EY::Serverside::Server
- Defined in:
- lib/engineyard-serverside/server.rb
Instance Attribute Summary collapse
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#name ⇒ Object
Returns the value of attribute name.
-
#roles ⇒ Object
Returns the value of attribute roles.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
- .from_hash(server_hash) ⇒ Object
-
.known_hosts_file ⇒ Object
Make a known hosts tempfile to absorb host fingerprints so we don't show.
Instance Method Summary collapse
- #authority ⇒ Object
- #command_on_server(prefix, cmd, &block) ⇒ Object
- #local? ⇒ Boolean
- #matches_roles?(set) ⇒ Boolean
- #remote_command(command) ⇒ Object
- #role ⇒ Object
- #run(command) {|local? ? command : remote_command(command)| ... } ⇒ Object
- #ssh_command ⇒ Object
- #sync_directory_command(directory) ⇒ Object
Instance Attribute Details
#hostname ⇒ Object
Returns the value of attribute hostname
6 7 8 |
# File 'lib/engineyard-serverside/server.rb', line 6 def hostname @hostname end |
#name ⇒ Object
Returns the value of attribute name
6 7 8 |
# File 'lib/engineyard-serverside/server.rb', line 6 def name @name end |
#roles ⇒ Object
Returns the value of attribute roles
6 7 8 |
# File 'lib/engineyard-serverside/server.rb', line 6 def roles @roles end |
#user ⇒ Object
Returns the value of attribute user
6 7 8 |
# File 'lib/engineyard-serverside/server.rb', line 6 def user @user end |
Class Method Details
.from_hash(server_hash) ⇒ Object
7 8 9 |
# File 'lib/engineyard-serverside/server.rb', line 7 def self.from_hash(server_hash) new(server_hash[:hostname], Set.new(server_hash[:roles].map{|r|r.to_sym}), server_hash[:name], server_hash[:user]) end |
.known_hosts_file ⇒ Object
Make a known hosts tempfile to absorb host fingerprints so we don't show
Warning: Permanently added 'xxx' (RSA) to the list of known hosts.
for every ssh command. (even with StrictHostKeyChecking=no, the warning output is annoying)
60 61 62 |
# File 'lib/engineyard-serverside/server.rb', line 60 def self.known_hosts_file @known_hosts_file ||= Tempfile.new('ey-ss-known-hosts') end |
Instance Method Details
#authority ⇒ Object
11 12 13 |
# File 'lib/engineyard-serverside/server.rb', line 11 def "#{user}@#{hostname}" end |
#command_on_server(prefix, cmd, &block) ⇒ Object
40 41 42 43 44 |
# File 'lib/engineyard-serverside/server.rb', line 40 def command_on_server(prefix, cmd, &block) command = block ? block.call(self, cmd.dup) : cmd command = "#{prefix} #{Escape.shell_command([command])}" local? ? command : remote_command(command) end |
#local? ⇒ Boolean
28 29 30 |
# File 'lib/engineyard-serverside/server.rb', line 28 def local? hostname == 'localhost' end |
#matches_roles?(set) ⇒ Boolean
19 20 21 |
# File 'lib/engineyard-serverside/server.rb', line 19 def matches_roles?(set) (roles & set).any? end |
#remote_command(command) ⇒ Object
50 51 52 |
# File 'lib/engineyard-serverside/server.rb', line 50 def remote_command(command) ssh_command + Escape.shell_command(["#{user}@#{hostname}", command]) end |
#role ⇒ Object
15 16 17 |
# File 'lib/engineyard-serverside/server.rb', line 15 def role roles.first end |
#run(command) {|local? ? command : remote_command(command)| ... } ⇒ Object
46 47 48 |
# File 'lib/engineyard-serverside/server.rb', line 46 def run(command) yield local? ? command : remote_command(command) end |
#ssh_command ⇒ Object
64 65 66 |
# File 'lib/engineyard-serverside/server.rb', line 64 def ssh_command "ssh -i #{ENV['HOME']}/.ssh/internal -o StrictHostKeyChecking=no -o UserKnownHostsFile=#{self.class.known_hosts_file.path} -o PasswordAuthentication=no " end |
#sync_directory_command(directory) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/engineyard-serverside/server.rb', line 32 def sync_directory_command(directory) return nil if local? [ remote_command("mkdir -p #{directory}"), Escape.shell_command(%w[rsync --delete -aq -e] + [ssh_command, "#{directory}/", "#{user}@#{hostname}:#{directory}"]) ].join(' && ') end |