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
Returns a new instance of Server.
7 8 9 10 11 12 |
# File 'lib/foreplay/engine/server.rb', line 7 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.
5 6 7 |
# File 'lib/foreplay/engine/server.rb', line 5 def environment @environment end |
#instructions ⇒ Object (readonly)
Returns the value of attribute instructions.
5 6 7 |
# File 'lib/foreplay/engine/server.rb', line 5 def instructions @instructions end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
5 6 7 |
# File 'lib/foreplay/engine/server.rb', line 5 def mode @mode end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
5 6 7 |
# File 'lib/foreplay/engine/server.rb', line 5 def server @server end |
Instance Method Details
#current_port ⇒ Object
71 72 73 |
# File 'lib/foreplay/engine/server.rb', line 71 def current_port @current_port ||= port_details[:current_port] end |
#current_port_file ⇒ Object
87 88 89 |
# File 'lib/foreplay/engine/server.rb', line 87 def current_port_file @current_port_file ||= ".foreplay/#{name}/current_port" end |
#current_service ⇒ Object
75 76 77 |
# File 'lib/foreplay/engine/server.rb', line 75 def current_service @current_service ||= port_details[:current_service] end |
#execute ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/foreplay/engine/server.rb', line 14 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 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
79 80 81 |
# File 'lib/foreplay/engine/server.rb', line 79 def former_port @former_port ||= port_details[:former_port] end |
#former_service ⇒ Object
83 84 85 |
# File 'lib/foreplay/engine/server.rb', line 83 def former_service @former_service ||= port_details[:former_service] end |
#host ⇒ Object
55 56 57 58 59 |
# File 'lib/foreplay/engine/server.rb', line 55 def host return @host if @host @host, _ = server.split(':') # Parse host + port @host end |
#name ⇒ Object
42 43 44 |
# File 'lib/foreplay/engine/server.rb', line 42 def name @name ||= instructions[:name] end |
#path ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/foreplay/engine/server.rb', line 46 def path return @path if @path @path = instructions[:path] @path.gsub! '%u', user @path.gsub! '%a', name @path end |
#port_details ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/foreplay/engine/server.rb', line 100 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
91 92 93 94 95 96 97 98 |
# File 'lib/foreplay/engine/server.rb', line 91 def port_steps @port_steps ||= [ { 'command' => "mkdir -p .foreplay/#{name} && touch #{current_port_file} && cat #{current_port_file}", 'silent' => true } ] end |
#role ⇒ Object
34 35 36 |
# File 'lib/foreplay/engine/server.rb', line 34 def role @role ||= instructions[:role] end |
#steps ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/foreplay/engine/server.rb', line 61 def steps @steps ||= YAML.load( ERB.new( File.read( "#{File.dirname(__FILE__)}/steps.yml" ) ).result(binding) ) end |
#user ⇒ Object
38 39 40 |
# File 'lib/foreplay/engine/server.rb', line 38 def user @user ||= instructions[:user] end |