elecksee 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/elecksee/ephemeral.rb +70 -1
- data/lib/elecksee/lxc.rb +15 -12
- data/lib/elecksee/version.rb +1 -1
- data/lib/elecksee.rb +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5338c94533fdfa6461fca82ac7ae057eb78156e8
|
4
|
+
data.tar.gz: 1a456de0c3e90b671e861cb944b4a9573e0b7e80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7dd9c7ae904a7c815fbc9fc8c216b64a2daf41c3f7eb651cbe5c3232d3b49ffb9999a3f92997292316f072c6eb077c211361a15b666cddb22ee71af03509126
|
7
|
+
data.tar.gz: f933cd9cad68730ec0dccb2f53bbe78477837bb087edd9d7c642de8a5106d6843e163ae2cbe606da533d4514a1cb456ae2444617a111d7dd6d5f569528390f66
|
data/CHANGELOG.md
CHANGED
data/lib/elecksee/ephemeral.rb
CHANGED
@@ -2,6 +2,7 @@ require 'elecksee'
|
|
2
2
|
require 'securerandom'
|
3
3
|
require 'fileutils'
|
4
4
|
require 'tmpdir'
|
5
|
+
require 'tempfile'
|
5
6
|
require 'etc'
|
6
7
|
|
7
8
|
class Lxc
|
@@ -117,23 +118,91 @@ class Lxc
|
|
117
118
|
# @return [TrueClass]
|
118
119
|
# @note use :fork to fork startup
|
119
120
|
def start!(*args)
|
120
|
-
register_traps
|
121
121
|
setup
|
122
122
|
if(daemon)
|
123
123
|
if(args.include?(:fork))
|
124
|
+
register_traps
|
124
125
|
fork do
|
125
126
|
start_action
|
126
127
|
end
|
128
|
+
elsif(args.include?(:detach))
|
129
|
+
cmd = [sudo, shell_wrapper.path].compact.map(&:strip)
|
130
|
+
process = ChildProcess.build(*cmd)
|
131
|
+
process.detach = true
|
132
|
+
process.start
|
133
|
+
shell_wrapper.delete
|
127
134
|
else
|
135
|
+
register_traps
|
128
136
|
Process.daemon
|
129
137
|
start_action
|
130
138
|
end
|
131
139
|
else
|
140
|
+
register_traps
|
132
141
|
start_action
|
133
142
|
end
|
134
143
|
true
|
135
144
|
end
|
136
145
|
|
146
|
+
# Bash based wrapper script to start ephemeral and clean up
|
147
|
+
# ephemeral resources on exit
|
148
|
+
#
|
149
|
+
# @return [Tempfile] wrapper script
|
150
|
+
def shell_wrapper
|
151
|
+
content = ['#!/bin/bash']
|
152
|
+
content << 'scrub()' << '{'
|
153
|
+
content << "umount #{ephemeral_overlay.target}"
|
154
|
+
ephemeral_binds.map do |bind|
|
155
|
+
unless(bind.device_path == :none)
|
156
|
+
if(File.file?(bind.device_path))
|
157
|
+
content << "rm #{bind.device_path}"
|
158
|
+
elsif(File.directory?(bind.device_path))
|
159
|
+
content << "rm -rf #{bind.device_path}"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
unless(bind.mount_path == :none)
|
163
|
+
if(File.directory?(bind.mount_path))
|
164
|
+
content << "rmdir #{bind.mount_path}"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
case ephemeral_device
|
169
|
+
when Storage::OverlayDirectory
|
170
|
+
if(File.directory?(ephemeral_device.overlay_path))
|
171
|
+
content << "rm -rf #{ephemeral_device.overlay_path}"
|
172
|
+
end
|
173
|
+
when Storage::VirtualDevice
|
174
|
+
if(ephemeral_device.mounted?)
|
175
|
+
content << "umount #{ephemeral_device.mount_path}"
|
176
|
+
end
|
177
|
+
unless(ephemeral_device.device_path == :none)
|
178
|
+
if(File.file?(ephemeral_device.device_path))
|
179
|
+
content << "rm #{ephemeral_device.device_path}"
|
180
|
+
elsif(File.directory?(ephemeral_device.device_path))
|
181
|
+
content << "rm -rf #{ephemeral_device.device_path}"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
unless(ephemeral_device.mount_path == :none)
|
185
|
+
if(File.directory?(ephemeral_device.mount_path))
|
186
|
+
content << "rmdir #{ephemeral_device.mount_path}"
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
if(lxc.path.to_path.split('/').size > 1)
|
191
|
+
content << "rm -rf #{lxc.path.to_path}"
|
192
|
+
end
|
193
|
+
content << '}'
|
194
|
+
content << 'trap scrub SIGTERM SIGINT SIGQUIT'
|
195
|
+
content << "lxc-start -n #{lxc.name} -d"
|
196
|
+
content << 'sleep 1'
|
197
|
+
content << "lxc-wait -n #{lxc.name} -s STOPPED"
|
198
|
+
content << 'scrub'
|
199
|
+
tmp = Tempfile.new('elecksee')
|
200
|
+
tmp.chmod(0700)
|
201
|
+
tmp.puts content.join("\n")
|
202
|
+
tmp.close
|
203
|
+
tmp
|
204
|
+
end
|
205
|
+
|
137
206
|
# Stop container and cleanup ephemeral items
|
138
207
|
#
|
139
208
|
# @return [TrueClass, FalseClass]
|
data/lib/elecksee/lxc.rb
CHANGED
@@ -456,6 +456,20 @@ class Lxc
|
|
456
456
|
end
|
457
457
|
end
|
458
458
|
|
459
|
+
# Provide connection to running container
|
460
|
+
#
|
461
|
+
# @return [Rye::Box]
|
462
|
+
def connection(args={})
|
463
|
+
Rye::Box.new(args.fetch(:ip, container_ip(3)),
|
464
|
+
:user => ssh_user,
|
465
|
+
:password => ssh_password,
|
466
|
+
:password_prompt => false,
|
467
|
+
:keys => [ssh_key],
|
468
|
+
:safe => false,
|
469
|
+
:paranoid => false
|
470
|
+
)
|
471
|
+
end
|
472
|
+
|
459
473
|
# Execute command within running container
|
460
474
|
#
|
461
475
|
# @param command [String]
|
@@ -466,16 +480,7 @@ class Lxc
|
|
466
480
|
# @return [CommandResult]
|
467
481
|
def direct_container_command(command, args={})
|
468
482
|
begin
|
469
|
-
|
470
|
-
args.fetch(:ip, container_ip(3)),
|
471
|
-
:user => ssh_user,
|
472
|
-
:password => ssh_password,
|
473
|
-
:password_prompt => false,
|
474
|
-
:keys => [ssh_key],
|
475
|
-
:safe => false,
|
476
|
-
:paranoid => false
|
477
|
-
)
|
478
|
-
result = box.execute command
|
483
|
+
result = connection(args).execute command
|
479
484
|
CommandResult.new(result)
|
480
485
|
rescue Rye::Err => e
|
481
486
|
if(args[:raise_on_failure])
|
@@ -571,7 +576,5 @@ EOS
|
|
571
576
|
|
572
577
|
end
|
573
578
|
|
574
|
-
# Make default settings
|
575
|
-
Lxc.shellout_helper = :mixlib_shellout
|
576
579
|
Lxc.default_ssh_key = '/opt/hw-lxc-config/id_rsa'
|
577
580
|
Lxc.default_ssh_user = 'root'
|
data/lib/elecksee/version.rb
CHANGED
data/lib/elecksee.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elecksee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Roberts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: childprocess
|