Class: Foreplay::Engine::Server
- Inherits:
-
Object
- Object
- Foreplay::Engine::Server
- Includes:
- Foreplay
- Defined in:
- lib/foreplay/engine/server.rb
Constant Summary
Constants included from Foreplay
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#instructions ⇒ Object
readonly
Returns the value of attribute instructions.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #current_port ⇒ Object
- #current_port_file ⇒ Object
- #current_service ⇒ Object
- #execute ⇒ Object
- #former_port ⇒ Object
- #former_service ⇒ Object
- #host ⇒ Object
-
#initialize(e, m, i, s) ⇒ Server
constructor
A new instance of Server.
- #name ⇒ Object
- #path ⇒ Object
- #port_details ⇒ Object
- #port_steps ⇒ Object
- #role ⇒ Object
- #steps ⇒ Object
- #user ⇒ Object
Methods included from Foreplay
Constructor Details
#initialize(e, m, i, s) ⇒ Server
5 6 7 8 9 10 |
# File 'lib/foreplay/engine/server.rb', line 5 def initialize(e, m, i, s) @environment = e @mode = m @instructions = i @server = s end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
3 4 5 |
# File 'lib/foreplay/engine/server.rb', line 3 def environment @environment end |
#instructions ⇒ Object (readonly)
Returns the value of attribute instructions.
3 4 5 |
# File 'lib/foreplay/engine/server.rb', line 3 def instructions @instructions end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
3 4 5 |
# File 'lib/foreplay/engine/server.rb', line 3 def mode @mode end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
3 4 5 |
# File 'lib/foreplay/engine/server.rb', line 3 def server @server end |
Instance Method Details
#current_port ⇒ Object
70 71 72 |
# File 'lib/foreplay/engine/server.rb', line 70 def current_port @current_port ||= port_details['current_port'] end |
#current_port_file ⇒ Object
86 87 88 |
# File 'lib/foreplay/engine/server.rb', line 86 def current_port_file @current_port_file ||= ".foreplay/#{name}/current_port" end |
#current_service ⇒ Object
74 75 76 |
# File 'lib/foreplay/engine/server.rb', line 74 def current_service @current_service ||= port_details['current_service'] end |
#execute ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/foreplay/engine/server.rb', line 12 def execute preposition = mode == :deploy ? 'to' : 'for' = "#{mode.capitalize}ing #{name.yellow} #{preposition} #{host.yellow} " += "for the #{role.dup.yellow} role in the #{environment.dup.yellow} environment" puts # Contents of .foreman file instructions['foreman']['app'] = current_service instructions['foreman']['port'] = current_port instructions['foreman']['user'] = user instructions['foreman']['log'] = "$HOME/#{path}/#{current_port}/log" # Contents of .env file instructions['env']['HOME'] = '$HOME' instructions['env']['SHELL'] = '$SHELL' instructions['env']['PATH'] = '$PATH:`which bundle`' Foreplay::Engine::Remote.new(server, steps, instructions).__send__ mode end |
#former_port ⇒ Object
78 79 80 |
# File 'lib/foreplay/engine/server.rb', line 78 def former_port @former_port ||= port_details['former_port'] end |
#former_service ⇒ Object
82 83 84 |
# File 'lib/foreplay/engine/server.rb', line 82 def former_service @former_service ||= port_details['former_service'] end |
#host ⇒ Object
54 55 56 57 58 |
# File 'lib/foreplay/engine/server.rb', line 54 def host return @host if @host @host, _p = server.split(':') # Parse host + port @host end |
#name ⇒ Object
41 42 43 |
# File 'lib/foreplay/engine/server.rb', line 41 def name @name ||= instructions['name'] end |
#path ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/foreplay/engine/server.rb', line 45 def path return @path if @path @path = instructions['path'] @path.gsub! '%u', user @path.gsub! '%a', name @path end |
#port_details ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/foreplay/engine/server.rb', line 99 def port_details return @port_details if @port_details current_port_string = Foreplay::Engine::Remote.new(server, port_steps, instructions).__send__(mode).strip! if current_port_string.blank? puts "#{host}#{INDENT}No instance is currently deployed" else puts "#{host}#{INDENT}Current instance is using port #{current_port_string}" end cp = current_port_string.to_i port = instructions['port'] ports = [port + 1000, port] cp, fp = cp == port ? ports : ports.reverse @port_details = { 'current_port' => cp, 'current_service' => "#{name}-#{cp}", 'former_port' => fp, 'former_service' => "#{name}-#{fp}" } end |
#port_steps ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/foreplay/engine/server.rb', line 90 def port_steps @port_steps ||= [ { 'command' => "mkdir -p .foreplay/#{name} && touch #{current_port_file} && cat #{current_port_file}", 'silent' => true } ] end |
#role ⇒ Object
33 34 35 |
# File 'lib/foreplay/engine/server.rb', line 33 def role @role ||= instructions['role'] end |
#steps ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/foreplay/engine/server.rb', line 60 def steps @steps ||= YAML.load( ERB.new( File.read( "#{File.dirname(__FILE__)}/steps.yml" ) ).result(binding) ) end |
#user ⇒ Object
37 38 39 |
# File 'lib/foreplay/engine/server.rb', line 37 def user @user ||= instructions['user'] end |