The project is in a healthy, maintained state
BlackStack Nodes is a simple library to managing a computer remotely via SSH, and perform some common operations. This library is used and extended by many others like: - [BlackStack Deployer](https://github.com/leandrosardi/blackstack-deployer) - [Pampa](https://github.com/leandrosardi/pampa) - [Simple Proxies Monitoring](https://github.com/leandrosardi/simple_proxies_deploying) - [Simple Hosts Monitoring](https://github.com/leandrosardi/simple_host_monitoring)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

blackstack-nodes

BlackStack Nodes is a simple library to managing a computer remotely via SSH, and perform some common operations.

This library is used and extended by many others like:

Outline

  1. Installation
  2. Getting Started
  3. Using Private-Keys
  4. Rebooting Nodes
  5. Logging
  6. Resources Monitoring
  7. Logs Monitoring

1. Installation

Install the gem.

gem install blackstack-nodes

2. Getting Started

require 'simple_cloud_logging'

n = BlackStack::Infrastructure::Node.new({
    :ip => '81.28.96.103',  
    :ssh_username => 'root',
    :ssh_port => 22,
    :ssh_password => '****',
})
# => BlackStack::Infrastructure::Node

n.connect
# => n.ssh

puts n.exec('hostname')
# => 'dev1'

n.disconnect
# => nil

3. Using Private-Keys

require 'simple_cloud_logging'

n = BlackStack::Infrastructure::Node.new({
    :ip => '54.160.137.218',  
    :ssh_username => 'ubuntu',
    :ssh_port => 22,
    :ssh_private_key_file => './plank.pem',
})
# => BlackStack::Infrastructure::Node

n.connect
# => n.ssh

puts n.exec('hostname')
# => 'dev1'

n.disconnect
# => nil

4. Rebooting Nodes

Use the reboot method for not only reboot the node, but wait for it to get back too.

require 'simple_cloud_logging'

n = BlackStack::Infrastructure::Node.new({
    :ip => '54.160.137.218',  
    :ssh_username => 'ubuntu',
    :ssh_port => 22,
    :ssh_private_key_file => './plank.pem',
})
# => BlackStack::Infrastructure::RemoteNode

n.connect
# => n.ssh

puts n.reboot # your code will remiains here until the node is get again.
# => nil

n.disconnect
# => nil

5. Logging

You can integrate blackstack-nodes our other simple_cloud_logging gem.

Example:

require 'simple_cloud_logging'

logger = BlackStack::LocalLogger.new('./example.log')

n = BlackStack::Infrastructure::Node.new({
    :ip => '54.160.137.218',  
    :ssh_username => 'ubuntu',
    :ssh_port => 22,
    :ssh_private_key_file => './plank.pem',
}, logger)
# => BlackStack::Infrastructure::RemoteNode

n.connect
# => n.ssh

puts n.reboot # your code will remiains here until the node is get again.
# => nil

n.disconnect
# => nil

The log of this command will be something like this:

2022-05-30 15:37:26: Connecting to node... done
2022-05-30 15:37:28: Rebooting node...
2022-05-30 15:37:28:  > reboot... done
2022-05-30 15:37:30:  > wait 10 seconds... done
2022-05-30 15:37:40:  > connecting (try 1)... Net::SSH::ConnectionTimeout
2022-05-30 15:38:01:  > wait 10 seconds... done
2022-05-30 15:38:11:  > connecting (try 2)... No se puede establecer una conexi¾n ya que el equipo de destino deneg¾ expresamente dicha conexi¾n. - connect(2) for 81.28.96.103:22
2022-05-30 15:38:19:  > wait 10 seconds... done
2022-05-30 15:38:29:  > connecting (try 3)... done

6. Resources Monitoring

You can remotely monitor the usage of memory, CPU and disk space of a node.

require 'simple_cloud_logging'

n = BlackStack::Infrastructure::Node.new({
    :ip => '54.160.137.218',  
    :ssh_username => 'ubuntu',
    :ssh_port => 22,
    :ssh_private_key_file => './plank.pem',
})
# => BlackStack::Infrastructure::RemoteNode

n.connect
# => n.ssh

puts n.usage
# => { :gb_total_memory => ..., :gb_free_memory => ..., ... }

n.disconnect
# => nil

7. Logs Monitoring

You can remotely watch a log file of a node.

require 'simple_cloud_logging'

n = BlackStack::Infrastructure::Node.new({
    :ip => '54.160.137.218',  
    :ssh_username => 'ubuntu',
    :ssh_port => 22,
    :ssh_private_key_file => './plank.pem',
})
# => BlackStack::Infrastructure::RemoteNode

n.connect
# => n.ssh

# show the latest n lines of the log
puts n.tail('/home/ubuntu/process.log', n)
# => ...

n.disconnect
# => nil

Versioning

We use SemVer for versioning. For the versions available, see the last ruby gem.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Further Work

Nothing yet.