Class: Webbynode::Taps
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#database_password ⇒ Object
readonly
Returns the value of attribute database_password.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#remote_executor ⇒ Object
readonly
Returns the value of attribute remote_executor.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #check_and_install(*gems) ⇒ Object
- #ensure_gems! ⇒ Object
- #finish ⇒ Object
-
#initialize(database, database_password, io, remote_executor) ⇒ Taps
constructor
A new instance of Taps.
- #pull(options) ⇒ Object
- #push(options) ⇒ Object
- #start ⇒ Object
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
#database ⇒ Object (readonly)
Returns the value of attribute database.
7 8 9 |
# File 'lib/webbynode/taps.rb', line 7 def database @database end |
#database_password ⇒ Object (readonly)
Returns the value of attribute database_password.
7 8 9 |
# File 'lib/webbynode/taps.rb', line 7 def database_password @database_password end |
#debug ⇒ Object
Returns the value of attribute debug.
12 13 14 |
# File 'lib/webbynode/taps.rb', line 12 def debug @debug end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
8 9 10 |
# File 'lib/webbynode/taps.rb', line 8 def io @io end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
9 10 11 |
# File 'lib/webbynode/taps.rb', line 9 def password @password end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
10 11 12 |
# File 'lib/webbynode/taps.rb', line 10 def pid @pid end |
#remote_executor ⇒ Object (readonly)
Returns the value of attribute remote_executor.
8 9 10 |
# File 'lib/webbynode/taps.rb', line 8 def remote_executor @remote_executor end |
#user ⇒ Object (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 |
#finish ⇒ Object
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() execute "pull", end |
#push(options) ⇒ Object
60 61 62 |
# File 'lib/webbynode/taps.rb', line 60 def push() execute "push", end |
#start ⇒ Object
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 |