vagabond 0.2.8 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +16 -0
- data/DEVELOP.md +38 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +33 -0
- data/README.md +55 -21
- data/USAGE.md +28 -3
- data/Vagabondfile.sample +47 -0
- data/Vagrantfile +17 -5
- data/bin/vagabond +5 -0
- data/lib/vagabond/Cheffile +7 -0
- data/lib/vagabond/Cheffile.dev +7 -0
- data/lib/vagabond/actions/cluster.rb +22 -8
- data/lib/vagabond/actions/create.rb +7 -4
- data/lib/vagabond/actions/destroy.rb +24 -14
- data/lib/vagabond/actions/freeze.rb +1 -0
- data/lib/vagabond/actions/init.rb +8 -11
- data/lib/vagabond/actions/provision.rb +16 -8
- data/lib/vagabond/actions/rebuild.rb +4 -9
- data/lib/vagabond/actions/ssh.rb +9 -1
- data/lib/vagabond/actions/start.rb +1 -0
- data/lib/vagabond/actions/status.rb +1 -0
- data/lib/vagabond/actions/thaw.rb +1 -0
- data/lib/vagabond/actions/up.rb +22 -7
- data/lib/vagabond/bootstraps/chef_10_compat_config.erb +62 -0
- data/lib/vagabond/bootstraps/no_lazy_load.erb +63 -0
- data/lib/vagabond/bootstraps/server-zero.erb +1 -8
- data/lib/vagabond/bootstraps/server.erb +9 -6
- data/lib/vagabond/constants.rb +1 -6
- data/lib/vagabond/core.rb +209 -0
- data/lib/vagabond/errors.rb +3 -0
- data/lib/vagabond/helpers.rb +11 -99
- data/lib/vagabond/helpers/base.rb +134 -0
- data/lib/vagabond/helpers/callbacks.rb +47 -0
- data/lib/vagabond/helpers/chains.rb +23 -0
- data/lib/vagabond/helpers/commands.rb +49 -0
- data/lib/vagabond/helpers/knife.rb +47 -0
- data/lib/vagabond/helpers/naming.rb +39 -0
- data/lib/vagabond/helpers/server.rb +30 -0
- data/lib/vagabond/internal_configuration.rb +186 -32
- data/lib/vagabond/kitchen.rb +110 -60
- data/lib/vagabond/knife.rb +5 -1
- data/lib/vagabond/layout.rb +1 -0
- data/lib/vagabond/monkey/kitchen_config.rb +1 -0
- data/lib/vagabond/notify_mash.rb +25 -0
- data/lib/vagabond/server.rb +81 -49
- data/lib/vagabond/settings.rb +17 -0
- data/lib/vagabond/spec.rb +125 -99
- data/lib/vagabond/uploader.rb +4 -1
- data/lib/vagabond/uploader/berkshelf.rb +2 -1
- data/lib/vagabond/uploader/knife.rb +3 -9
- data/lib/vagabond/uploader/librarian.rb +2 -5
- data/lib/vagabond/vagabond.rb +77 -93
- data/lib/vagabond/vagabondfile.rb +73 -9
- data/lib/vagabond/version.rb +2 -1
- data/vagabond.gemspec +7 -5
- metadata +58 -81
- data/lib/vagabond/cookbooks/apt/Berksfile +0 -8
- data/lib/vagabond/cookbooks/apt/CHANGELOG.md +0 -97
- data/lib/vagabond/cookbooks/apt/CONTRIBUTING +0 -29
- data/lib/vagabond/cookbooks/apt/LICENSE +0 -201
- data/lib/vagabond/cookbooks/apt/README.md +0 -243
- data/lib/vagabond/cookbooks/apt/TESTING.md +0 -25
- data/lib/vagabond/cookbooks/apt/attributes/default.rb +0 -4
- data/lib/vagabond/cookbooks/apt/files/default/apt-proxy-v2.conf +0 -50
- data/lib/vagabond/cookbooks/apt/metadata.rb +0 -30
- data/lib/vagabond/cookbooks/apt/providers/preference.rb +0 -61
- data/lib/vagabond/cookbooks/apt/providers/repository.rb +0 -132
- data/lib/vagabond/cookbooks/apt/recipes/cacher-client.rb +0 -59
- data/lib/vagabond/cookbooks/apt/recipes/cacher-ng.rb +0 -40
- data/lib/vagabond/cookbooks/apt/recipes/default.rb +0 -68
- data/lib/vagabond/cookbooks/apt/resources/preference.rb +0 -30
- data/lib/vagabond/cookbooks/apt/resources/repository.rb +0 -40
- data/lib/vagabond/cookbooks/apt/templates/debian-6.0/acng.conf.erb +0 -174
- data/lib/vagabond/cookbooks/apt/templates/default/01proxy.erb +0 -2
- data/lib/vagabond/cookbooks/apt/templates/default/acng.conf.erb +0 -276
- data/lib/vagabond/cookbooks/apt/templates/ubuntu-10.04/acng.conf.erb +0 -270
- data/lib/vagabond/cookbooks/apt/test/cookbooks/apt_test/README.md +0 -1
- data/lib/vagabond/cookbooks/apt/test/cookbooks/apt_test/files/default/tests/minitest/cacher-ng_test.rb +0 -28
- data/lib/vagabond/cookbooks/apt/test/cookbooks/apt_test/files/default/tests/minitest/default_test.rb +0 -28
- data/lib/vagabond/cookbooks/apt/test/cookbooks/apt_test/files/default/tests/minitest/lwrps_test.rb +0 -48
- data/lib/vagabond/cookbooks/apt/test/cookbooks/apt_test/files/default/tests/minitest/support/helpers.rb +0 -29
- data/lib/vagabond/cookbooks/apt/test/cookbooks/apt_test/metadata.rb +0 -6
- data/lib/vagabond/cookbooks/apt/test/cookbooks/apt_test/recipes/cacher-ng.rb +0 -20
- data/lib/vagabond/cookbooks/apt/test/cookbooks/apt_test/recipes/default.rb +0 -20
- data/lib/vagabond/cookbooks/apt/test/cookbooks/apt_test/recipes/lwrps.rb +0 -66
- data/lib/vagabond/cookbooks/lxc/CHANGELOG.md +0 -37
- data/lib/vagabond/cookbooks/lxc/Gemfile +0 -4
- data/lib/vagabond/cookbooks/lxc/Gemfile.lock +0 -41
- data/lib/vagabond/cookbooks/lxc/README.md +0 -112
- data/lib/vagabond/cookbooks/lxc/attributes/default.rb +0 -26
- data/lib/vagabond/cookbooks/lxc/files/default/knife_lxc +0 -228
- data/lib/vagabond/cookbooks/lxc/files/default/lxc-awesome-ephemeral +0 -499
- data/lib/vagabond/cookbooks/lxc/libraries/lxc.rb +0 -477
- data/lib/vagabond/cookbooks/lxc/libraries/lxc_expanded_resources.rb +0 -40
- data/lib/vagabond/cookbooks/lxc/libraries/lxc_file_config.rb +0 -84
- data/lib/vagabond/cookbooks/lxc/libraries/monkey.rb +0 -51
- data/lib/vagabond/cookbooks/lxc/metadata.rb +0 -12
- data/lib/vagabond/cookbooks/lxc/providers/config.rb +0 -75
- data/lib/vagabond/cookbooks/lxc/providers/container.rb +0 -354
- data/lib/vagabond/cookbooks/lxc/providers/default.rb +0 -57
- data/lib/vagabond/cookbooks/lxc/providers/ephemeral.rb +0 -40
- data/lib/vagabond/cookbooks/lxc/providers/fstab.rb +0 -30
- data/lib/vagabond/cookbooks/lxc/providers/interface.rb +0 -45
- data/lib/vagabond/cookbooks/lxc/providers/service.rb +0 -53
- data/lib/vagabond/cookbooks/lxc/recipes/containers.rb +0 -13
- data/lib/vagabond/cookbooks/lxc/recipes/default.rb +0 -58
- data/lib/vagabond/cookbooks/lxc/recipes/install_dependencies.rb +0 -15
- data/lib/vagabond/cookbooks/lxc/recipes/knife.rb +0 -37
- data/lib/vagabond/cookbooks/lxc/resources/config.rb +0 -19
- data/lib/vagabond/cookbooks/lxc/resources/container.rb +0 -54
- data/lib/vagabond/cookbooks/lxc/resources/default.rb +0 -12
- data/lib/vagabond/cookbooks/lxc/resources/ephemeral.rb +0 -13
- data/lib/vagabond/cookbooks/lxc/resources/fstab.rb +0 -12
- data/lib/vagabond/cookbooks/lxc/resources/interface.rb +0 -13
- data/lib/vagabond/cookbooks/lxc/resources/service.rb +0 -5
- data/lib/vagabond/cookbooks/lxc/templates/default/client.rb.erb +0 -13
- data/lib/vagabond/cookbooks/lxc/templates/default/default-lxc.erb +0 -3
- data/lib/vagabond/cookbooks/lxc/templates/default/file_content.erb +0 -2
- data/lib/vagabond/cookbooks/lxc/templates/default/fstab.erb +0 -5
- data/lib/vagabond/cookbooks/lxc/templates/default/interface.erb +0 -27
- data/lib/vagabond/cookbooks/vagabond/README.md +0 -10
- data/lib/vagabond/cookbooks/vagabond/attributes/default.rb +0 -18
- data/lib/vagabond/cookbooks/vagabond/files/default/lxc-centos +0 -460
- data/lib/vagabond/cookbooks/vagabond/libraries/vagabond.rb +0 -10
- data/lib/vagabond/cookbooks/vagabond/metadata.rb +0 -8
- data/lib/vagabond/cookbooks/vagabond/recipes/default.rb +0 -132
- data/lib/vagabond/cookbooks/vagabond/recipes/zero.rb +0 -9
- data/lib/vagabond/helpers/cheffile_loader.rb +0 -20
- data/vagabond-0.2.6.gem +0 -0
@@ -1,13 +0,0 @@
|
|
1
|
-
actions :run
|
2
|
-
default_action :run
|
3
|
-
|
4
|
-
attribute :command, :kind_of => String, :required => true
|
5
|
-
attribute :bind_directory, :kind_of => String
|
6
|
-
attribute :base_container, :kind_of => String, :required => true
|
7
|
-
attribute :background, :kind_of => [TrueClass,FalseClass], :default => false
|
8
|
-
attribute :union_type, :equal_to => %w(aufs overlayfs), :default => 'overlayfs'
|
9
|
-
attribute :user, :kind_of => String, :default => 'root'
|
10
|
-
attribute :key, :kind_of => String, :default => '/opt/hw-lxc-config/id_rsa'
|
11
|
-
attribute :host_rootfs, :kind_of => String
|
12
|
-
attribute :virtual_device, :kind_of => Numeric
|
13
|
-
attribute :stream_output, :kind_of => [TrueClass,FalseClass,IO]
|
@@ -1,12 +0,0 @@
|
|
1
|
-
actions :create, :delete
|
2
|
-
default_action :create
|
3
|
-
|
4
|
-
attribute :container, :kind_of => String, :required => true
|
5
|
-
attribute :file_system, :kind_of => String, :required => true
|
6
|
-
attribute :mount_point, :kind_of => String, :required => true
|
7
|
-
attribute :type, :kind_of => String, :required => true
|
8
|
-
attribute :options, :kind_of => [String, Array]
|
9
|
-
attribute :dump, :kind_of => Numeric, :default => 0
|
10
|
-
attribute :pass, :kind_of => Numeric, :default => 0
|
11
|
-
attribute :auto_join_rootfs_mount, :kind_of => [TrueClass,FalseClass], :default => true
|
12
|
-
attribute :create_mount_point, :kind_of => [TrueClass,FalseClass], :default => true
|
@@ -1,13 +0,0 @@
|
|
1
|
-
actions :create, :delete
|
2
|
-
default_action :create
|
3
|
-
|
4
|
-
attribute :container, :kind_of => String, :required => true
|
5
|
-
attribute :device, :kind_of => String, :required => true
|
6
|
-
attribute :auto, :kind_of => [TrueClass, FalseClass], :default => true
|
7
|
-
attribute :dynamic, :kind_of => [TrueClass, FalseClass], :default => false
|
8
|
-
attribute :address, :kind_of => String
|
9
|
-
attribute :gateway, :kind_of => String
|
10
|
-
attribute :up, :kind_of => String
|
11
|
-
attribute :down, :kind_of => String
|
12
|
-
attribute :netmask, :kind_of => [String,Numeric]
|
13
|
-
attribute :ipv6, :kind_of => [TrueClass,FalseClass], :default => false
|
@@ -1,13 +0,0 @@
|
|
1
|
-
log_level :info
|
2
|
-
log_location "/var/log/chef-client.log"
|
3
|
-
|
4
|
-
chef_server_url '<%= @server_uri %>'
|
5
|
-
validation_client_name '<%= @validation_client %>'
|
6
|
-
node_name '<%= @node_name %>'
|
7
|
-
environment '<%= @chef_environment %>'
|
8
|
-
|
9
|
-
file_backup_path "/var/lib/chef"
|
10
|
-
file_cache_path "/var/cache/chef"
|
11
|
-
|
12
|
-
pid_file "/var/run/chef/client.pid"
|
13
|
-
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# Auto config dropped off by chef!
|
2
|
-
|
3
|
-
# Always setup loopback
|
4
|
-
auto lo
|
5
|
-
iface lo inet loopback
|
6
|
-
|
7
|
-
<% node.run_state[:lxc][:interfaces][@container].each do |net_set| -%>
|
8
|
-
<% if net_set[:auto] -%>
|
9
|
-
auto <%= net_set[:device] %>
|
10
|
-
<% end -%>
|
11
|
-
<% if net_set[:dynamic] -%>
|
12
|
-
iface <%= net_set[:device] %> inet<%= '6' if net_set[:ipv6] %> dhcp
|
13
|
-
<% else -%>
|
14
|
-
iface <%= net_set[:device] %> inet<%= '6' if net_set[:ipv6] %> static
|
15
|
-
address <%= net_set[:address] %>
|
16
|
-
<% if net_set[:gateway] -%>
|
17
|
-
gateway <%= net_set[:gateway] %>
|
18
|
-
<% end -%>
|
19
|
-
netmask <%= net_set[:netmask] %>
|
20
|
-
<% if net_set[:up] -%>
|
21
|
-
up <%= net_set[:up] %>
|
22
|
-
<% end -%>
|
23
|
-
<% if net_set[:down] -%>
|
24
|
-
down <%= net_set[:down] %>
|
25
|
-
<% end -%>
|
26
|
-
<% end -%>
|
27
|
-
<% end %>
|
@@ -1,10 +0,0 @@
|
|
1
|
-
# Vagabond
|
2
|
-
|
3
|
-
This cookbooks is used internally by the vagabond project.
|
4
|
-
It's general intention is to be used in that fashion, but
|
5
|
-
if you want to do something else with it, go nuts.
|
6
|
-
|
7
|
-
## Info
|
8
|
-
|
9
|
-
* Repository: https://github.com/chrisroberts/chef-vagabond
|
10
|
-
* IRC: spox @ Freenode
|
@@ -1,18 +0,0 @@
|
|
1
|
-
default[:vagabond][:bases][:ubuntu_1004][:template] = 'ubuntu'
|
2
|
-
default[:vagabond][:bases][:ubuntu_1004][:template_options] = {'--release' => 'lucid'}
|
3
|
-
default[:vagabond][:bases][:ubuntu_1204][:template] = 'ubuntu'
|
4
|
-
default[:vagabond][:bases][:ubuntu_1204][:template_options] = {'--release' => 'precise'}
|
5
|
-
default[:vagabond][:bases][:ubuntu_1210][:template] = 'ubuntu'
|
6
|
-
default[:vagabond][:bases][:ubuntu_1210][:template_options] = {'--release' => 'quantal'}
|
7
|
-
default[:vagabond][:bases][:centos_58][:template] = 'centos'
|
8
|
-
default[:vagabond][:bases][:centos_58][:template_options] = {'--release' => '5', '--releaseminor' => '8'}
|
9
|
-
default[:vagabond][:bases][:centos_63][:template] = 'centos'
|
10
|
-
default[:vagabond][:bases][:centos_63][:template_options] = {'--release' => '6', '--releaseminor' => '3'}
|
11
|
-
default[:vagabond][:bases][:centos_64][:template] = 'centos'
|
12
|
-
default[:vagabond][:bases][:centos_64][:template_options] = {'--release' => '6', '--releaseminor' => '4'}
|
13
|
-
default[:vagabond][:bases][:debian_6][:template] = 'debian'
|
14
|
-
default[:vagabond][:bases][:debian_6][:create_environment] = {'SUITE' => 'squeeze'}
|
15
|
-
default[:vagabond][:bases][:debian_7][:template] = 'debian'
|
16
|
-
default[:vagabond][:bases][:debian_7][:create_environment] = {'SUITE' => 'wheezy'}
|
17
|
-
default[:vagabond][:customs] = {}
|
18
|
-
default[:vagabond][:server_base] = true
|
@@ -1,460 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
#
|
4
|
-
# template script for generating CentOS container for LXC
|
5
|
-
#
|
6
|
-
|
7
|
-
#
|
8
|
-
# lxc: linux Container library
|
9
|
-
|
10
|
-
# Authors:
|
11
|
-
# Daniel Lezcano <daniel.lezcano@free.fr>
|
12
|
-
# Ramez Hanna <rhanna@informatiq.org>
|
13
|
-
|
14
|
-
# This library is free software; you can redistribute it and/or
|
15
|
-
# modify it under the terms of the GNU Lesser General Public
|
16
|
-
# License as published by the Free Software Foundation; either
|
17
|
-
# version 2.1 of the License, or (at your option) any later version.
|
18
|
-
|
19
|
-
# This library is distributed in the hope that it will be useful,
|
20
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
22
|
-
# Lesser General Public License for more details.
|
23
|
-
|
24
|
-
# You should have received a copy of the GNU Lesser General Public
|
25
|
-
# License along with this library; if not, write to the Free Software
|
26
|
-
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
27
|
-
|
28
|
-
#Configurations
|
29
|
-
arch=$(arch)
|
30
|
-
cache_base=/var/cache/lxc/centos/$arch
|
31
|
-
default_path=/var/lib/lxc
|
32
|
-
root_password=password
|
33
|
-
|
34
|
-
# is this centos?
|
35
|
-
[ -f /etc/redhat-release ] && is_centos=true
|
36
|
-
|
37
|
-
if [ "$arch" = "i686" ]; then
|
38
|
-
arch=i386
|
39
|
-
fi
|
40
|
-
|
41
|
-
configure_centos()
|
42
|
-
{
|
43
|
-
|
44
|
-
# disable selinux in centos
|
45
|
-
mkdir -p $rootfs_path/selinux
|
46
|
-
echo 0 > $rootfs_path/selinux/enforce
|
47
|
-
|
48
|
-
# configure the network using the dhcp
|
49
|
-
cat <<EOF > ${rootfs_path}/etc/sysconfig/network-scripts/ifcfg-eth0
|
50
|
-
DEVICE=eth0
|
51
|
-
BOOTPROTO=dhcp
|
52
|
-
ONBOOT=yes
|
53
|
-
TYPE=Ethernet
|
54
|
-
USERCTL=yes
|
55
|
-
PEERDNS=yes
|
56
|
-
IPV6INIT=no
|
57
|
-
EOF
|
58
|
-
|
59
|
-
# set the dns
|
60
|
-
# TODO: Probably remove this
|
61
|
-
cat > $rootfs_path/etc/resolv.conf << END
|
62
|
-
# Google public DNS
|
63
|
-
nameserver 8.8.8.8
|
64
|
-
nameserver 8.8.4.4
|
65
|
-
END
|
66
|
-
|
67
|
-
|
68
|
-
# set the hostname
|
69
|
-
cat <<EOF > ${rootfs_path}/etc/sysconfig/network
|
70
|
-
NETWORKING=yes
|
71
|
-
HOSTNAME=${name}
|
72
|
-
EOF
|
73
|
-
|
74
|
-
# set minimal hosts
|
75
|
-
cat <<EOF > $rootfs_path/etc/hosts
|
76
|
-
127.0.0.1 localhost $name
|
77
|
-
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
|
78
|
-
EOF
|
79
|
-
|
80
|
-
sed -i 's|.sbin.start_udev||' ${rootfs_path}/etc/rc.sysinit
|
81
|
-
sed -i 's|.sbin.start_udev||' ${rootfs_path}/etc/rc.d/rc.sysinit
|
82
|
-
# don't mount devpts, for pete's sake
|
83
|
-
sed -i 's/^.*dev.pts.*$/#\0/' ${rootfs_path}/etc/rc.sysinit
|
84
|
-
sed -i 's/^.*dev.pts.*$/#\0/' ${rootfs_path}/etc/rc.d/rc.sysinit
|
85
|
-
|
86
|
-
sed -i 's/^.*dev.pts.*$/#\0/' ${rootfs_path}/etc/rc.d/rc.sysinit
|
87
|
-
sed -i 's/^.*dev.pts.*$/#\0/' ${rootfs_path}/etc/rc.d/rc.sysinit
|
88
|
-
sed -i 's/^.*dev.pts.*$/#\0/' ${rootfs_path}/etc/rc.d/rc.sysinit
|
89
|
-
|
90
|
-
sed -i 's/^#baseurl/baseurl/g' ${rootfs_path}/etc/yum.repos.d/CentOS-Base.repo
|
91
|
-
sed -i "s/\$releasever/$release.$releaseminor/g" ${rootfs_path}/etc/yum.repos.d/CentOS-Base.repo
|
92
|
-
sed -i '115,126s/^/#/' ${rootfs_path}/etc/rc.d/init.d/halt
|
93
|
-
|
94
|
-
chroot ${rootfs_path} chkconfig udev-post off
|
95
|
-
chroot ${rootfs_path} chkconfig network on
|
96
|
-
|
97
|
-
dev_path="${rootfs_path}/dev"
|
98
|
-
rm -rf $dev_path
|
99
|
-
mkdir -p $dev_path
|
100
|
-
mknod -m 666 ${dev_path}/null c 1 3
|
101
|
-
mknod -m 666 ${dev_path}/zero c 1 5
|
102
|
-
mknod -m 666 ${dev_path}/random c 1 8
|
103
|
-
mknod -m 666 ${dev_path}/urandom c 1 9
|
104
|
-
mkdir -m 755 ${dev_path}/pts
|
105
|
-
mkdir -m 1777 ${dev_path}/shm
|
106
|
-
mknod -m 666 ${dev_path}/tty c 5 0
|
107
|
-
mknod -m 666 ${dev_path}/tty0 c 4 0
|
108
|
-
mknod -m 666 ${dev_path}/tty1 c 4 1
|
109
|
-
mknod -m 666 ${dev_path}/tty2 c 4 2
|
110
|
-
mknod -m 666 ${dev_path}/tty3 c 4 3
|
111
|
-
mknod -m 666 ${dev_path}/tty4 c 4 4
|
112
|
-
mknod -m 600 ${dev_path}/console c 5 1
|
113
|
-
mknod -m 666 ${dev_path}/full c 1 7
|
114
|
-
mknod -m 600 ${dev_path}/initctl p
|
115
|
-
mknod -m 666 ${dev_path}/ptmx c 5 2
|
116
|
-
|
117
|
-
echo "setting root passwd to $root_password"
|
118
|
-
echo "root:$root_password" | chroot $rootfs_path chpasswd
|
119
|
-
|
120
|
-
# specifying this in the initial packages doesn't always work.
|
121
|
-
# echo "installing centos-release package"
|
122
|
-
# if [ ! -f ${rootfs_path}/etc/resolv.conf ]; then
|
123
|
-
# cp /etc/resolv.conf ${rootfs_path}/etc/resolv.conf
|
124
|
-
# remove_resolv=1
|
125
|
-
# fi
|
126
|
-
# chroot ${rootfs_path} rpm --rebuilddb
|
127
|
-
# chroot ${rootfs_path} yum --releasever=${release} -y install centos-release
|
128
|
-
# if [ ! -z $remove_resolv ]; then
|
129
|
-
# rm ${rootfs_path}/etc/resolv.conf
|
130
|
-
# fi
|
131
|
-
|
132
|
-
# silence some needless startup errors
|
133
|
-
touch ${rootfs_path}/etc/fstab
|
134
|
-
|
135
|
-
# give us a console on /dev/console
|
136
|
-
sed -i 's/ACTIVE_CONSOLES=.*$/ACTIVE_CONSOLES="\/dev\/console \/dev\/tty[1-4]"/' \
|
137
|
-
${rootfs_path}/etc/sysconfig/init
|
138
|
-
|
139
|
-
return 0
|
140
|
-
}
|
141
|
-
|
142
|
-
download_centos()
|
143
|
-
{
|
144
|
-
|
145
|
-
# check the mini centos was not already downloaded
|
146
|
-
INSTALL_ROOT=$cache/partial
|
147
|
-
mkdir -p $INSTALL_ROOT
|
148
|
-
if [ $? -ne 0 ]; then
|
149
|
-
echo "Failed to create '$INSTALL_ROOT' directory"
|
150
|
-
return 1
|
151
|
-
fi
|
152
|
-
|
153
|
-
# download a mini centos into a cache
|
154
|
-
echo "Downloading centos minimal ..."
|
155
|
-
YUM="yum --installroot $INSTALL_ROOT -y --nogpgcheck"
|
156
|
-
PKG_LIST="yum initscripts passwd rsyslog vim-minimal dhclient chkconfig"
|
157
|
-
PKG_LIST="$PKG_LIST rootfiles policycoreutils centos-release openssh-server avahi"
|
158
|
-
MIRRORLIST_URL="http://mirrorlist.centos.org/?release=$release.$releaseminor&arch=$arch&repo=os"
|
159
|
-
|
160
|
-
FOUND_MIRRORS=$(curl -s -S -f "$MIRRORLIST_URL")
|
161
|
-
AVAIL_MIRRORS="${FOUND_MIRRORS} http://vault.centos.org/$release.$releaseminor/os/$arch"
|
162
|
-
|
163
|
-
DOWNLOAD_OK=no
|
164
|
-
for MIRROR_URL in $AVAIL_MIRRORS; do
|
165
|
-
if [ $? -ne 0 ] || [ -z "$MIRROR_URL" ]; then
|
166
|
-
echo "Failed to get a mirror"
|
167
|
-
continue
|
168
|
-
fi
|
169
|
-
if [ $release = "6" ]; then
|
170
|
-
PACKAGE_NAME=`wget -q -O - ${MIRROR_URL}/Packages/ | grep centos-release-${release}.${releaseminor} | sed -r 's/.+rpm">//g' | sed -r 's/<.+//g'`
|
171
|
-
RELEASE_URL="$MIRROR_URL/Packages/${PACKAGE_NAME}"
|
172
|
-
else
|
173
|
-
PACKAGE_NAME=`wget -q -O - ${MIRROR_URL}/CentOS/ | grep centos-release-${release}.${releaseminor} | sed -r 's/.+rpm">//g' | sed -r 's/<.+//g'`
|
174
|
-
RELEASE_URL="$MIRROR_URL/CentOS/${PACKAGE_NAME}"
|
175
|
-
fi
|
176
|
-
echo "Fetching from $RELEASE_URL"
|
177
|
-
curl -f "$RELEASE_URL" > $INSTALL_ROOT/centos-release-$release-$releaseminor.centos.$arch.rpm
|
178
|
-
if [ $? -ne 0 ]; then
|
179
|
-
echo "Failed to download centos release rpm"
|
180
|
-
continue
|
181
|
-
fi
|
182
|
-
DOWNLOAD_OK=yes
|
183
|
-
break
|
184
|
-
done
|
185
|
-
if [ $DOWNLOAD_OK != yes ]; then
|
186
|
-
echo "Aborting"
|
187
|
-
return 1
|
188
|
-
fi
|
189
|
-
|
190
|
-
mkdir -p $INSTALL_ROOT/var/lib/rpm
|
191
|
-
rpm --root $INSTALL_ROOT --initdb
|
192
|
-
rpm --root $INSTALL_ROOT -ivh $INSTALL_ROOT/centos-release-$release-$releaseminor.centos.$arch.rpm
|
193
|
-
$YUM install $PKG_LIST
|
194
|
-
chroot $INSTALL_ROOT rm -f /var/lib/rpm/__*
|
195
|
-
chroot $INSTALL_ROOT rpm --rebuilddb
|
196
|
-
|
197
|
-
if [ $? -ne 0 ]; then
|
198
|
-
echo "Failed to download the rootfs, aborting."
|
199
|
-
return 1
|
200
|
-
fi
|
201
|
-
|
202
|
-
mv "$INSTALL_ROOT" "$cache/rootfs"
|
203
|
-
echo "Download complete."
|
204
|
-
|
205
|
-
return 0
|
206
|
-
}
|
207
|
-
|
208
|
-
copy_centos()
|
209
|
-
{
|
210
|
-
|
211
|
-
# make a local copy of the minicentos
|
212
|
-
echo -n "Copying rootfs to $rootfs_path ..."
|
213
|
-
#cp -a $cache/rootfs-$arch $rootfs_path || return 1
|
214
|
-
# i prefer rsync (no reason really)
|
215
|
-
mkdir -p $rootfs_path
|
216
|
-
rsync -a $cache/rootfs/ $rootfs_path/
|
217
|
-
return 0
|
218
|
-
}
|
219
|
-
|
220
|
-
update_centos()
|
221
|
-
{
|
222
|
-
# chroot $cache/rootfs yum -y update
|
223
|
-
echo "Updates disabled"
|
224
|
-
}
|
225
|
-
|
226
|
-
install_centos()
|
227
|
-
{
|
228
|
-
mkdir -p /var/lock/subsys/
|
229
|
-
(
|
230
|
-
flock -x 200
|
231
|
-
if [ $? -ne 0 ]; then
|
232
|
-
echo "Cache repository is busy."
|
233
|
-
return 1
|
234
|
-
fi
|
235
|
-
|
236
|
-
echo "Checking cache download in $cache/rootfs ... "
|
237
|
-
if [ ! -e "$cache/rootfs" ]; then
|
238
|
-
download_centos
|
239
|
-
if [ $? -ne 0 ]; then
|
240
|
-
echo "Failed to download 'centos base'"
|
241
|
-
return 1
|
242
|
-
fi
|
243
|
-
else
|
244
|
-
echo "Cache found. Updating..."
|
245
|
-
update_centos
|
246
|
-
if [ $? -ne 0 ]; then
|
247
|
-
echo "Failed to update 'centos base', continuing with last known good cache"
|
248
|
-
else
|
249
|
-
echo "Update finished"
|
250
|
-
fi
|
251
|
-
fi
|
252
|
-
|
253
|
-
echo "Copy $cache/rootfs to $rootfs_path ... "
|
254
|
-
copy_centos
|
255
|
-
if [ $? -ne 0 ]; then
|
256
|
-
echo "Failed to copy rootfs"
|
257
|
-
return 1
|
258
|
-
fi
|
259
|
-
|
260
|
-
return 0
|
261
|
-
|
262
|
-
) 200>/var/lock/subsys/lxc
|
263
|
-
|
264
|
-
return $?
|
265
|
-
}
|
266
|
-
|
267
|
-
copy_configuration()
|
268
|
-
{
|
269
|
-
|
270
|
-
mkdir -p $config_path
|
271
|
-
cat <<EOF >> $config_path/config
|
272
|
-
lxc.utsname = $name
|
273
|
-
lxc.tty = 4
|
274
|
-
lxc.pts = 1024
|
275
|
-
lxc.rootfs = $rootfs_path
|
276
|
-
lxc.mount = $config_path/fstab
|
277
|
-
|
278
|
-
# uncomment the next line to run the container unconfined:
|
279
|
-
#lxc.aa_profile = unconfined
|
280
|
-
|
281
|
-
#cgroups
|
282
|
-
lxc.cgroup.devices.deny = a
|
283
|
-
# /dev/null and zero
|
284
|
-
lxc.cgroup.devices.allow = c 1:3 rwm
|
285
|
-
lxc.cgroup.devices.allow = c 1:5 rwm
|
286
|
-
# consoles
|
287
|
-
lxc.cgroup.devices.allow = c 5:1 rwm
|
288
|
-
lxc.cgroup.devices.allow = c 5:0 rwm
|
289
|
-
lxc.cgroup.devices.allow = c 4:0 rwm
|
290
|
-
lxc.cgroup.devices.allow = c 4:1 rwm
|
291
|
-
# /dev/{,u}random
|
292
|
-
lxc.cgroup.devices.allow = c 1:9 rwm
|
293
|
-
lxc.cgroup.devices.allow = c 1:8 rwm
|
294
|
-
lxc.cgroup.devices.allow = c 136:* rwm
|
295
|
-
lxc.cgroup.devices.allow = c 5:2 rwm
|
296
|
-
# rtc
|
297
|
-
lxc.cgroup.devices.allow = c 254:0 rwm
|
298
|
-
EOF
|
299
|
-
|
300
|
-
cat <<EOF > $config_path/fstab
|
301
|
-
proc proc proc nodev,noexec,nosuid 0 0
|
302
|
-
sysfs sys sysfs defaults 0 0
|
303
|
-
EOF
|
304
|
-
if [ $? -ne 0 ]; then
|
305
|
-
echo "Failed to add configuration"
|
306
|
-
return 1
|
307
|
-
fi
|
308
|
-
|
309
|
-
return 0
|
310
|
-
}
|
311
|
-
|
312
|
-
clean()
|
313
|
-
{
|
314
|
-
|
315
|
-
if [ ! -e $cache ]; then
|
316
|
-
exit 0
|
317
|
-
fi
|
318
|
-
|
319
|
-
# lock, so we won't purge while someone is creating a repository
|
320
|
-
(
|
321
|
-
flock -x 200
|
322
|
-
if [ $? != 0 ]; then
|
323
|
-
echo "Cache repository is busy."
|
324
|
-
exit 1
|
325
|
-
fi
|
326
|
-
|
327
|
-
echo -n "Purging the download cache for Centos-$release-$releaseminor..."
|
328
|
-
rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
|
329
|
-
exit 0
|
330
|
-
|
331
|
-
) 200>/var/lock/subsys/lxc
|
332
|
-
}
|
333
|
-
|
334
|
-
usage()
|
335
|
-
{
|
336
|
-
cat <<EOF
|
337
|
-
usage:
|
338
|
-
$1 -n|--name=<container_name>
|
339
|
-
[-p|--path=<path>] [-c|--clean] [-R|--release=<Centos_release>] [-A|--arch=<arch of the container>]
|
340
|
-
[-h|--help]
|
341
|
-
Mandatory args:
|
342
|
-
-n,--name container name, used to as an identifier for that container from now on
|
343
|
-
Optional args:
|
344
|
-
-p,--path path to where the container rootfs will be created, defaults to /var/lib/lxc. The container config will go under /var/lib/lxc in that case
|
345
|
-
-c,--clean clean the cache
|
346
|
-
-R,--release Centos release for the new container. if the host is Fedora, then it will defaultto the host's release.
|
347
|
-
-m,--release-minor Minor release number for the new containar
|
348
|
-
-A,--arch NOT USED YET. Define what arch the container will be [i686,x86_64]
|
349
|
-
-h,--help print this help
|
350
|
-
EOF
|
351
|
-
return 0
|
352
|
-
}
|
353
|
-
|
354
|
-
options=$(getopt -o hp:n:cR:m: -l help,path:,name:,clean,release:,releaseminor: -- "$@")
|
355
|
-
if [ $? -ne 0 ]; then
|
356
|
-
usage $(basename $0)
|
357
|
-
exit 1
|
358
|
-
fi
|
359
|
-
eval set -- "$options"
|
360
|
-
|
361
|
-
while true
|
362
|
-
do
|
363
|
-
case "$1" in
|
364
|
-
-h|--help) usage $0 && exit 0;;
|
365
|
-
-p|--path) path=$2; shift 2;;
|
366
|
-
-n|--name) name=$2; shift 2;;
|
367
|
-
-c|--clean) clean=$2; shift 2;;
|
368
|
-
-R|--release) release=$2; shift 2;;
|
369
|
-
-m|--releaseminor) releaseminor=$2; shift 2;;
|
370
|
-
--) shift 1; break ;;
|
371
|
-
*) break ;;
|
372
|
-
esac
|
373
|
-
done
|
374
|
-
|
375
|
-
if [ ! -z "$clean" -a -z "$path" ]; then
|
376
|
-
clean || exit 1
|
377
|
-
exit 0
|
378
|
-
fi
|
379
|
-
|
380
|
-
needed_pkgs=""
|
381
|
-
type yum >/dev/null 2>&1
|
382
|
-
if [ $? -ne 0 ]; then
|
383
|
-
needed_pkgs="yum $needed_pkgs"
|
384
|
-
fi
|
385
|
-
|
386
|
-
type curl >/dev/null 2>&1
|
387
|
-
if [ $? -ne 0 ]; then
|
388
|
-
needed_pkgs="curl $needed_pkgs"
|
389
|
-
fi
|
390
|
-
|
391
|
-
if [ -n "$needed_pkgs" ]; then
|
392
|
-
echo "Missing commands: $needed_pkgs"
|
393
|
-
echo "Please install these using \"sudo apt-get install $needed_pkgs\""
|
394
|
-
exit 1
|
395
|
-
fi
|
396
|
-
|
397
|
-
if [ -z "$path" ]; then
|
398
|
-
path=$default_path
|
399
|
-
fi
|
400
|
-
|
401
|
-
if [ -z "$release" ]; then
|
402
|
-
if [ "$is_centos" ]; then
|
403
|
-
release=$(cat /etc/centos-release |awk '/^Fedora/ {print $3}')
|
404
|
-
else
|
405
|
-
echo "This is not a centos host and release missing, defaulting to 6.3. use -R|--release to specify release"
|
406
|
-
release=6
|
407
|
-
fi
|
408
|
-
fi
|
409
|
-
|
410
|
-
if [ -z "$releaseminor" ]; then
|
411
|
-
releaseminor=3
|
412
|
-
fi
|
413
|
-
|
414
|
-
if [ "$(id -u)" != "0" ]; then
|
415
|
-
echo "This script should be run as 'root'"
|
416
|
-
exit 1
|
417
|
-
fi
|
418
|
-
|
419
|
-
|
420
|
-
rootfs_path=$path/rootfs
|
421
|
-
config_path=$default_path/$name
|
422
|
-
cache=$cache_base/$release.$releaseminor
|
423
|
-
|
424
|
-
revert()
|
425
|
-
{
|
426
|
-
echo "Interrupted, so cleaning up"
|
427
|
-
lxc-destroy -n $name
|
428
|
-
# maybe was interrupted before copy config
|
429
|
-
rm -rf $path/$name
|
430
|
-
rm -rf $default_path/$name
|
431
|
-
echo "exiting..."
|
432
|
-
exit 1
|
433
|
-
}
|
434
|
-
|
435
|
-
trap revert SIGHUP SIGINT SIGTERM
|
436
|
-
|
437
|
-
copy_configuration
|
438
|
-
if [ $? -ne 0 ]; then
|
439
|
-
echo "failed write configuration file"
|
440
|
-
exit 1
|
441
|
-
fi
|
442
|
-
|
443
|
-
install_centos
|
444
|
-
if [ $? -ne 0 ]; then
|
445
|
-
echo "failed to install centos"
|
446
|
-
exit 1
|
447
|
-
fi
|
448
|
-
|
449
|
-
configure_centos
|
450
|
-
if [ $? -ne 0 ]; then
|
451
|
-
echo "failed to configure centos for a container"
|
452
|
-
exit 1
|
453
|
-
fi
|
454
|
-
|
455
|
-
|
456
|
-
if [ ! -z $clean ]; then
|
457
|
-
clean || exit 1
|
458
|
-
exit 0
|
459
|
-
fi
|
460
|
-
echo "container rootfs and config created"
|