Class: EY::Server

Inherits:
Struct show all
Includes:
LoggedOutput
Defined in:
lib/ey-deploy/server.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LoggedOutput

#debug, #info, logfile, logfile=, #logged_system, verbose=, verbose?, #verbose?

Methods inherited from Struct

json_create, #to_json

Constructor Details

#initialize(*fields) ⇒ Server

Returns a new instance of Server.



8
9
10
11
# File 'lib/ey-deploy/server.rb', line 8

def initialize(*fields)
  super
  self.role = self.role.to_sym
end

Instance Attribute Details

#default_task=(value) ⇒ Object (writeonly)

Sets the attribute default_task

Parameters:

  • value

    the value to set the attribute default_task to.



21
22
23
# File 'lib/ey-deploy/server.rb', line 21

def default_task=(value)
  @default_task = value
end

#hostnameObject

Returns the value of attribute hostname

Returns:

  • (Object)

    the current value of hostname



5
6
7
# File 'lib/ey-deploy/server.rb', line 5

def hostname
  @hostname
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



5
6
7
# File 'lib/ey-deploy/server.rb', line 5

def name
  @name
end

#roleObject

Returns the value of attribute role

Returns:

  • (Object)

    the current value of role



5
6
7
# File 'lib/ey-deploy/server.rb', line 5

def role
  @role
end

Class Method Details

.allObject



36
37
38
# File 'lib/ey-deploy/server.rb', line 36

def self.all
  @all
end

.all=(server_hashes) ⇒ Object



40
41
42
# File 'lib/ey-deploy/server.rb', line 40

def self.all=(server_hashes)
  @all = server_hashes.map { |s| from_hash(s) }
end

.config=(config) ⇒ Object



13
14
15
# File 'lib/ey-deploy/server.rb', line 13

def self.config=(config)
  @@config = config
end

.currentObject



44
45
46
# File 'lib/ey-deploy/server.rb', line 44

def self.current
  all.find {|s| s.local? }
end

.from_hash(h) ⇒ Object



32
33
34
# File 'lib/ey-deploy/server.rb', line 32

def self.from_hash(h)
  new(h[:hostname], h[:role], h[:name])
end

.from_roles(*roles) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/ey-deploy/server.rb', line 23

def self.from_roles(*roles)
  roles = roles.flatten.compact
  return all if !roles || roles.include?(:all) || roles.empty?

  all.select do |s|
    roles.include?(s.role) || roles.include?(s.name)
  end
end

Instance Method Details

#configObject



17
18
19
# File 'lib/ey-deploy/server.rb', line 17

def config
  @@config
end

#local?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/ey-deploy/server.rb', line 48

def local?
  [:app_master, :solo].include?(role)
end

#push_codeObject



52
53
54
55
56
# File 'lib/ey-deploy/server.rb', line 52

def push_code
  return if local?
  run "mkdir -p #{config.repository_cache}"
  logged_system(%|rsync --delete -aq -e "#{ssh_command}" #{config.repository_cache}/ #{config.user}@#{hostname}:#{config.repository_cache}|)
end

#run(command) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/ey-deploy/server.rb', line 58

def run(command)
  if local?
    logged_system(command)
  else
    logged_system(ssh_command + " " + Escape.shell_command(["#{config.user}@#{hostname}", command]))
  end
end

#ssh_commandObject



66
67
68
# File 'lib/ey-deploy/server.rb', line 66

def ssh_command
  "ssh -i #{ENV['HOME']}/.ssh/internal -o StrictHostKeyChecking=no -o PasswordAuthentication=no"
end