linux_container 1.6 → 1.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,4 @@
1
+ v1.7. use Process.spawn instead of background shell for ephemeral
1
2
  v1.6. additional ephemeral container naming chars
2
3
  v1.5. match new ephemeral container naming scheme
3
4
  v1.4. parent_container feature
data/README.md CHANGED
@@ -4,8 +4,8 @@ This gem is an easy ruby interface to ubuntu linux containers (LXC). It
4
4
  provides a convenient wrapper for starting Ubuntu Cloud image-based
5
5
  ephemeral containers.
6
6
 
7
- lxc-start-ephemeral uses AUFS overlay filesystem to clone an container using
8
- very little disk space, which then disappears when shut down.
7
+ lxc-start-ephemeral uses "overlay filesystems" to start a cloned container
8
+ that uses little disk space. This container disappears when shut down.
9
9
 
10
10
  $ gem install linux_container
11
11
 
@@ -6,7 +6,7 @@ require 'tempfile'
6
6
  class LinuxContainer
7
7
  attr_accessor :name, :username, :ssh_key_path
8
8
  attr_writer :ip
9
-
9
+
10
10
  def self.all
11
11
  `#{sudo_if_needed} lxc-ls -1`.lines.map(&:strip).uniq.map {|cname| new(name: cname) }
12
12
  end
@@ -132,11 +132,18 @@ class LinuxContainer
132
132
  result
133
133
  end
134
134
 
135
+ class ProcessFailed < Exception ; end
136
+
135
137
  def bg_execute(*cmd)
136
138
  logfile_path = "/tmp/lxc_ephemeral_#{Time.now.to_i.to_s(36)}#{$$}#{rand(0x100000000).to_s(36)}.log"
137
- cmdstring = "( #{self.class.sudo_if_needed} #{cmd.shift} #{Shellwords.join(cmd)} >>#{logfile_path} 2>>#{logfile_path} & )"
138
- system(cmdstring)
139
- raise "command failed: #{cmdstring.inspect}\n" unless $? == 0
139
+ cmdstring = "#{self.class.sudo_if_needed} #{cmd.shift} #{Shellwords.join(cmd)} >>#{logfile_path} 2>>#{logfile_path}"
140
+ pid = spawn(cmdstring, pgroup: true)
141
+ raise ProcessFailed.new("command failed: #{cmdstring.inspect}") unless pid > 0
142
+ Thread.abort_on_exception = true
143
+ Thread.new do
144
+ Process.waitpid pid
145
+ raise ProcessFailed.new("command failed: #{cmdstring.inspect}") unless $? == 0
146
+ end
140
147
  logfile_path
141
148
  end
142
149
 
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "linux_container"
5
- s.version = "1.6"
5
+ s.version = "1.7"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Andrew Snow"]
9
- s.date = "2013-06-20"
9
+ s.date = "2013-06-23"
10
10
  s.description = "Ruby gem for ephemeral LXC linux containers"
11
11
  s.email = "andrew@modulus.org"
12
12
  s.extra_rdoc_files = ["CHANGELOG", "README.md", "lib/linux_container.rb"]
@@ -15,7 +15,16 @@ Gem::Specification.new do |s|
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Linux_container", "--main", "README.md"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = "linux_container"
18
- s.rubygems_version = "2.0.3"
18
+ s.rubygems_version = "1.8.25"
19
19
  s.summary = "Ruby gem for ephemeral LXC linux containers"
20
20
  s.test_files = ["test/test_all.rb"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
21
30
  end
data/test/test_all.rb CHANGED
@@ -66,7 +66,12 @@ class TestLinuxContainer < MiniTest::Unit::TestCase
66
66
  assert($ec.wait_for { !running? }, 'wait_for !running?')
67
67
  end
68
68
 
69
-
69
+ def test_bg_execute_failure
70
+ assert_raises(LinuxContainer::ProcessFailed) do
71
+ $c.bg_execute 'false'
72
+ sleep 5
73
+ end
74
+ end
70
75
 
71
76
  end
72
77
 
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux_container
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.6'
4
+ version: '1.7'
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Andrew Snow
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-06-20 00:00:00.000000000 Z
12
+ date: 2013-06-23 00:00:00.000000000 Z
12
13
  dependencies: []
13
14
  description: Ruby gem for ephemeral LXC linux containers
14
15
  email: andrew@modulus.org
@@ -28,7 +29,6 @@ files:
28
29
  - linux_container.gemspec
29
30
  homepage: https://github.com/andys/linux_container
30
31
  licenses: []
31
- metadata: {}
32
32
  post_install_message:
33
33
  rdoc_options:
34
34
  - --line-numbers
@@ -40,20 +40,22 @@ rdoc_options:
40
40
  require_paths:
41
41
  - lib
42
42
  required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
43
44
  requirements:
44
45
  - - ! '>='
45
46
  - !ruby/object:Gem::Version
46
47
  version: '0'
47
48
  required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
48
50
  requirements:
49
51
  - - ! '>='
50
52
  - !ruby/object:Gem::Version
51
53
  version: '1.2'
52
54
  requirements: []
53
55
  rubyforge_project: linux_container
54
- rubygems_version: 2.0.3
56
+ rubygems_version: 1.8.25
55
57
  signing_key:
56
- specification_version: 4
58
+ specification_version: 3
57
59
  summary: Ruby gem for ephemeral LXC linux containers
58
60
  test_files:
59
61
  - test/test_all.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MDU5NjE1MGQ4YTViMjAwMTNjMGVkZjkxNGM3NjUzZWUwMWU0NzFhZg==
5
- data.tar.gz: !binary |-
6
- ZGZkZjlhMjVhMzBjNzVhMTVlZTgwZjIwYjJjNTYxNTlhMzYxMmMyMw==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NmE0NmYwZGI5Y2M0MWNhODU0NTg5MWNhNjRjZTA4ZTc5ZGQ4ZTVmMTU0NTk1
10
- MTUzODM3YjRhYmMzODg0Nzk0NzUwYTFmY2Q5YmQwMTA0MjkxZDc1MWUyYzhl
11
- Mzg2Yzc3MGNjZTMyNGY4Yjc0MDMxYzdlZWE5ZTU3ODQ0ZDM1Mjc=
12
- data.tar.gz: !binary |-
13
- MzAwMzhiNTNmNDIxZWVhMjg0ZDVlY2YzMDBkZTBhYjc0YmRmYmVjYmZkYmZj
14
- ZTZmM2M4ZjNjYjdiNzA5Nzk2NzkyMmRkY2M1NzI0MjlkNDZmMTU5NDVkMWUx
15
- MzQ3NTIyYjU2M2MwMjZlZDVmMmRlYWY1YTFhNjIzZjA5NDZiYTk=