Class: Webbynode::Taps

Inherits:
Object show all
Defined in:
lib/webbynode/taps.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database, database_password, io, remote_executor) ⇒ Taps

Returns a new instance of Taps.



14
15
16
17
18
19
# File 'lib/webbynode/taps.rb', line 14

def initialize(database, database_password, io, remote_executor)
  @database = database
  @database_password = database_password
  @io = io
  @remote_executor = remote_executor
end

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



7
8
9
# File 'lib/webbynode/taps.rb', line 7

def database
  @database
end

#database_passwordObject (readonly)

Returns the value of attribute database_password.



7
8
9
# File 'lib/webbynode/taps.rb', line 7

def database_password
  @database_password
end

#debugObject

Returns the value of attribute debug.



12
13
14
# File 'lib/webbynode/taps.rb', line 12

def debug
  @debug
end

#ioObject (readonly)

Returns the value of attribute io.



8
9
10
# File 'lib/webbynode/taps.rb', line 8

def io
  @io
end

#passwordObject (readonly)

Returns the value of attribute password.



9
10
11
# File 'lib/webbynode/taps.rb', line 9

def password
  @password
end

#pidObject (readonly)

Returns the value of attribute pid.



10
11
12
# File 'lib/webbynode/taps.rb', line 10

def pid
  @pid
end

#remote_executorObject (readonly)

Returns the value of attribute remote_executor.



8
9
10
# File 'lib/webbynode/taps.rb', line 8

def remote_executor
  @remote_executor
end

#userObject (readonly)

Returns the value of attribute user.



9
10
11
# File 'lib/webbynode/taps.rb', line 9

def user
  @user
end

Instance Method Details

#check_and_install(*gems) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/webbynode/taps.rb', line 25

def check_and_install(*gems)
  gems.each do |g| 
    if g.is_a?(Array)
      gemd = *g
    else
      gemd = [g]
    end
    
    remote_executor.install_gem *gemd unless remote_executor.gem_installed?(*gemd)
  end
end

#ensure_gems!Object



21
22
23
# File 'lib/webbynode/taps.rb', line 21

def ensure_gems!
  check_and_install ['taps', '0.3.23'], 'mysql'
end

#finishObject



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/webbynode/taps.rb', line 64

def finish
  raise "Taps server was not started" unless user
  
  command = "kill -9 #{pid}"
  
  io.log "Executing: #{command}" if debug

  result = remote_executor.exec command
  
  io.log "Result: #{result}\n" if debug
end

#pull(options) ⇒ Object



56
57
58
# File 'lib/webbynode/taps.rb', line 56

def pull(options)
  execute "pull", options
end

#push(options) ⇒ Object



60
61
62
# File 'lib/webbynode/taps.rb', line 60

def push(options)
  execute "push", options
end

#startObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/webbynode/taps.rb', line 37

def start
  @user = io.random_password
  @password = io.random_password
  
  command = "bash -c 'nohup taps server mysql://#{database}:#{database_password}@localhost/#{database} #{@user} #{@password} > /dev/null 2>&1 &\necho $!'"
  
  io.log "Executing: #{command}" if debug
  
  result = remote_executor.exec(command)
  result.strip! if result
  
  io.log "Result: #{result}" if debug
  io.log "" if debug
  
  raise "Could not start taps on remote server" unless result =~ /^[0-9]+$/

  @pid = result
end