haconiwa 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/chroot.haco +19 -0
- data/exe/haconiwa +11 -0
- data/lib/haconiwa/base.rb +6 -1
- data/lib/haconiwa/cli.rb +15 -0
- data/lib/haconiwa/runners/linux.rb +16 -8
- data/lib/haconiwa/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 767036a1ab66ab117bcfd75c18b56a3636fa7358
|
4
|
+
data.tar.gz: 1d3cee5db594eb27e3f91eb28bedbf67ef94e146
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41d15e175b6f1b2fd6475ac558a138770167e1ed9e2d075fe48ec91f0493ceab08e53c619d6fee79e60d1972373041453117b70c41d40afe5bbb22292066599a
|
7
|
+
data.tar.gz: ad935bf20472c72d34066afc60bcacd682e13d4e489bdc606d4aa6eced14f8e4fff9d07ba24275dbc3b46ea0c86617e696ac347a452fedcc88d5b190b6d9405b
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
Haconiwa.define do |config|
|
3
|
+
config.name = "chroot001" # to be hostname
|
4
|
+
config.init_command = "/bin/sh" # to be first process
|
5
|
+
|
6
|
+
root = Pathname.new("/var/haconiwa/root")
|
7
|
+
config.add_mount_point "/var/haconiwa/rootfs", to: root, readonly: true
|
8
|
+
config.add_mount_point "/lib64", to: root.join("lib64"), readonly: true
|
9
|
+
config.add_mount_point "/usr/bin", to: root.join("usr/bin"), readonly: true
|
10
|
+
config.add_mount_point "tmpfs", to: root.join("tmp"), fs: "tmpfs"
|
11
|
+
config.add_mount_point "/var/haconiwa/user_homes/hakoniwa-test001/home/hakoniwa", to: root.join("home/hakoniwa")
|
12
|
+
config.mount_independent_procfs
|
13
|
+
config.chroot_to root
|
14
|
+
|
15
|
+
config.namespace.unshare "mount"
|
16
|
+
config.namespace.unshare "ipc"
|
17
|
+
config.namespace.unshare "uts"
|
18
|
+
config.namespace.unshare "pid"
|
19
|
+
end
|
data/exe/haconiwa
ADDED
data/lib/haconiwa/base.rb
CHANGED
@@ -8,6 +8,7 @@ require "haconiwa/runners"
|
|
8
8
|
module Haconiwa
|
9
9
|
class Base
|
10
10
|
attr_accessor :name,
|
11
|
+
:init_command,
|
11
12
|
:filesystem,
|
12
13
|
:cgroup,
|
13
14
|
:namespace,
|
@@ -40,12 +41,16 @@ module Haconiwa
|
|
40
41
|
self.filesystem.mount_independent_procfs = true
|
41
42
|
end
|
42
43
|
|
43
|
-
def start(init_command
|
44
|
+
def start(*init_command)
|
44
45
|
Runners::Linux.run(self, init_command)
|
45
46
|
end
|
46
47
|
alias run start
|
47
48
|
end
|
48
49
|
|
50
|
+
def self.define(&b)
|
51
|
+
Base.define(&b)
|
52
|
+
end
|
53
|
+
|
49
54
|
module Utils
|
50
55
|
# $ ausyscall --dump | grep hostname
|
51
56
|
# 170 sethostname
|
data/lib/haconiwa/cli.rb
ADDED
@@ -6,8 +6,12 @@ module Haconiwa::Runners
|
|
6
6
|
# see http://d.hatena.ne.jp/hiboma/20120518/1337337393
|
7
7
|
|
8
8
|
class Linux
|
9
|
-
def self.run(base, init_command)
|
9
|
+
def self.run(base, init_command=[])
|
10
10
|
container = fork {
|
11
|
+
if init_command.empty?
|
12
|
+
init_command = Array(base.init_command)
|
13
|
+
end
|
14
|
+
|
11
15
|
base.namespace.apply!
|
12
16
|
base.cgroup.register_all!(to: base.name)
|
13
17
|
|
@@ -19,12 +23,12 @@ module Haconiwa::Runners
|
|
19
23
|
wrapper = Tempfile.open("haconiwa-wrapper-#{$$}-#{Time.now.to_i}.sh")
|
20
24
|
|
21
25
|
wrapper.puts "#!/bin/bash"
|
22
|
-
wrapper.puts "/bin/bash -c
|
26
|
+
wrapper.puts "/bin/bash -c '"
|
23
27
|
if base.filesystem.mount_independent_procfs
|
24
28
|
wrapper.puts "mount -t proc proc /proc;"
|
25
29
|
end
|
26
|
-
wrapper.puts "exec
|
27
|
-
wrapper.puts "\""
|
30
|
+
wrapper.puts "exec $@;"
|
31
|
+
wrapper.puts "' -- \"$@\""
|
28
32
|
wrapper.close
|
29
33
|
FileUtils.chmod 0700, wrapper.path
|
30
34
|
|
@@ -34,18 +38,22 @@ module Haconiwa::Runners
|
|
34
38
|
|
35
39
|
if base.namespace.use_pid_ns
|
36
40
|
Bundler.with_clean_env {
|
37
|
-
exec "unshare", "--pid", "--", wrapper.path, init_command
|
41
|
+
exec "unshare", "--pid", "--", wrapper.path, *init_command
|
38
42
|
}
|
39
43
|
else
|
40
|
-
Bundler.with_clean_env { exec wrapper.path, init_command }
|
44
|
+
Bundler.with_clean_env { exec wrapper.path, *init_command }
|
41
45
|
end
|
42
46
|
}
|
43
47
|
|
44
48
|
Haconiwa::SmallCgroup.register_at_exit(pid: container, name: base.name, dirs: base.cgroup.to_dirs)
|
45
49
|
puts "New container: PID = #{container}"
|
46
50
|
|
47
|
-
Process.
|
48
|
-
|
51
|
+
res = Process.waitpid2 container
|
52
|
+
if res[1].success?
|
53
|
+
puts "Successfully exit container."
|
54
|
+
else
|
55
|
+
puts "Container exited with status code <#{res[1].to_i}>."
|
56
|
+
end
|
49
57
|
end
|
50
58
|
end
|
51
59
|
end
|
data/lib/haconiwa/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haconiwa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uchio KONDO
|
@@ -111,7 +111,8 @@ dependencies:
|
|
111
111
|
description: Ruby on Container / helper tools with DSL for your handmade linux containers.
|
112
112
|
email:
|
113
113
|
- udzura@udzura.jp
|
114
|
-
executables:
|
114
|
+
executables:
|
115
|
+
- haconiwa
|
115
116
|
extensions: []
|
116
117
|
extra_rdoc_files: []
|
117
118
|
files:
|
@@ -126,14 +127,17 @@ files:
|
|
126
127
|
- Vagrantfile
|
127
128
|
- bin/console
|
128
129
|
- bin/setup
|
130
|
+
- examples/chroot.haco
|
129
131
|
- examples/chroot.rb
|
130
132
|
- examples/cpu.rb
|
131
133
|
- examples/drop_cap_sys_time.rb
|
134
|
+
- exe/haconiwa
|
132
135
|
- haconiwa.gemspec
|
133
136
|
- lib/haconiwa.rb
|
134
137
|
- lib/haconiwa/base.rb
|
135
138
|
- lib/haconiwa/capabilities.rb
|
136
139
|
- lib/haconiwa/cgroup.rb
|
140
|
+
- lib/haconiwa/cli.rb
|
137
141
|
- lib/haconiwa/filesystem.rb
|
138
142
|
- lib/haconiwa/mount_point.rb
|
139
143
|
- lib/haconiwa/namespace.rb
|