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
- Installation
- Getting Started
- Using Private-Keys
- Rebooting Nodes
- Logging
- Resources Monitoring
- 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
- Leandro Daniel Sardi - Initial work - LeandroSardi
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
Further Work
Nothing yet.