ruby-lxc/README.md

82 lines
1.6 KiB
Markdown
Raw Permalink Normal View History

2013-12-06 17:43:19 +01:00
# Ruby-LXC
2014-06-16 19:17:40 +02:00
[![Build Status](https://travis-ci.org/lxc/ruby-lxc.svg?branch=master)](https://travis-ci.org/lxc/ruby-lxc)
2013-12-06 17:43:19 +01:00
## Introduction
Ruby-LXC is a Ruby binding for liblxc. It allows the creation and management
of Linux Containers from Ruby scripts.
## Build and installation
Assuming a current installation of LXC is available, to install Ruby-LXC
simply run the commands below
2013-12-06 17:43:19 +01:00
2013-12-16 21:29:15 +01:00
```sh
sudo apt-get install ruby-dev lxc-dev
2013-12-16 21:29:15 +01:00
bundle install
bundle exec rake compile
2014-05-24 06:42:20 +02:00
bundle exec rake gem
2014-06-13 19:38:05 +02:00
gem install pkg/ruby-lxc-1.2.0.gem
2013-12-16 21:29:15 +01:00
```
or just add this to your ```Gemfile```
```ruby
2014-05-24 06:49:54 +02:00
gem "ruby-lxc", github: "lxc/ruby-lxc", require: "lxc"
2013-12-16 21:29:15 +01:00
```
2013-12-06 17:43:19 +01:00
## Usage
2013-12-16 21:29:15 +01:00
- Container lifecycle management (create, start, stop and destroy containers)
```ruby
require 'lxc'
2013-12-16 21:29:15 +01:00
c = LXC::Container.new('foo')
c.create('ubuntu') # create a container named foo with ubuntu template
c.start
# attach to a running container
c.attach do
LXC.run_command('ifconfig eth0')
end
2013-12-16 21:29:15 +01:00
c.stop
c.destroy
```
- Container inspection
```ruby
c.name
c.config_path
c.config_item('lxc.cap.drop')
c.cgroup_item('memory.limit_in_bytes')
c.init_pid
c.interfaces
c.ip_addresses
c.state
```
- Additional state changing operations (freezing, unfreezing and cloning
containers)
2013-12-16 21:29:15 +01:00
```ruby
c.freeze
c.unfreeze
c.reboot
c.shutdown
```
- Clone a container
```ruby
# clone foo into bar. Parent container has to be frozen or stopped.
clone = c.clone('bar')
2013-12-16 21:29:15 +01:00
```
- Wait for a state change
```ruby
# wait until container goes to STOPPED state, else timeout after 10 seconds
c.wait(:stopped, 10)
2013-12-16 21:29:15 +01:00
```
Check the provided rdoc documentation for a full list of methods. You can
generate it running
```sh
rake rdoc
```