ruby-lxc/README.md

76 lines
1.4 KiB
Markdown
Raw Normal View History

2013-12-06 17:43:19 +01:00
# Ruby-LXC
## 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
bundle install
bundle exec rake compile
2014-03-06 14:28:00 +01:00
gem install pkg/ruby-lxc-1.0.1.gem
2013-12-16 21:29:15 +01:00
```
or just add this to your ```Gemfile```
```ruby
2014-01-09 23:37:17 +01:00
gem "ruby-lxc", github: "lxc/ruby-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
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
```