toft 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +6 -1
- data/Rakefile +93 -4
- data/features/checker.feature +2 -2
- data/features/chef.feature +23 -5
- data/features/command.feature +4 -3
- data/features/node.feature +21 -6
- data/features/step_definitions/chef.rb +11 -3
- data/features/step_definitions/command.rb +1 -3
- data/features/step_definitions/node.rb +19 -3
- data/features/support/env.rb +6 -3
- data/fixtures/chef/attributes.json +9 -0
- data/lib/toft/chef/chef_attributes.rb +2 -2
- data/lib/toft/chef/chef_runner.rb +17 -4
- data/lib/toft/node.rb +64 -20
- data/lib/toft/node_controller.rb +2 -2
- data/lib/toft/version.rb +1 -1
- data/lib/toft.rb +5 -2
- data/scripts/bin/centos/lxc-prepare-host +175 -0
- data/scripts/{ubuntu/bin → bin/share}/install-chef-ubuntu.sh +0 -0
- data/scripts/{ubuntu/bin → bin/share}/install-rvm.sh +0 -0
- data/scripts/{ubuntu/bin → bin/share}/lxc-create-centos-image +6 -5
- data/scripts/{ubuntu/bin → bin/ubuntu}/lxc-create-ubuntu-image +3 -3
- data/scripts/bin/ubuntu/lxc-prepare-host +190 -0
- data/scripts/cookbooks/lxc/recipes/default.rb +8 -14
- data/scripts/{ubuntu/lxc-templates → cookbooks/lxc/templates/default}/lxc-centos-6 +7 -3
- data/scripts/cookbooks/lxc/templates/default/{lxc-lucid-chef → lxc-lucid} +2 -2
- data/scripts/cookbooks/lxc/templates/default/{lxc-natty-chef → lxc-natty} +2 -2
- data/scripts/lxc-templates/files/rc.local +38 -0
- data/scripts/lxc-templates/lxc-centos-6 +279 -0
- data/scripts/{ubuntu/lxc-templates → lxc-templates}/lxc-lucid +3 -12
- data/scripts/{ubuntu/lxc-templates → lxc-templates}/lxc-natty +51 -61
- data/spec/fixtures/illegal_syntax.json +1 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/tuft/chef_attributes_spec.rb +6 -0
- data/spec/tuft/chef_runner_spec.rb +34 -0
- metadata +55 -21
- data/scripts/centos/bin/lxc-prepare-host +0 -39
- data/scripts/cookbooks/lxc/files/default/lxc-create-ubuntu-image +0 -75
- data/scripts/ubuntu/bin/lxc-prepare-host +0 -24
@@ -0,0 +1,175 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
username=`id -nu`
|
4
|
+
if [ ! "$username" = "root" ]; then
|
5
|
+
echo "This command has to be run as root!"
|
6
|
+
exit 1
|
7
|
+
fi
|
8
|
+
|
9
|
+
gateway_ip="192.168.20.1"
|
10
|
+
subnet="192.168.20.0"
|
11
|
+
netmask="255.255.255.0"
|
12
|
+
range="192.168.20.2 192.168.20.254"
|
13
|
+
domain=foo
|
14
|
+
|
15
|
+
|
16
|
+
# intsall lxc
|
17
|
+
if [[ ! -f /usr/bin/lxc-ls ]]; then
|
18
|
+
(cd /tmp && \
|
19
|
+
wget http://lxc.sourceforge.net/download/lxc/lxc-0.7.4.tar.gz && \
|
20
|
+
tar zxf lxc-0.7.4.tar.gz && \
|
21
|
+
cd lxc-0.7.4 && \
|
22
|
+
./configure --prefix=/usr && \
|
23
|
+
make && \
|
24
|
+
make install)
|
25
|
+
fi
|
26
|
+
|
27
|
+
# setup bridge interface
|
28
|
+
if [[ ! `ip link ls dev br0` ]]; then
|
29
|
+
brctl addbr br0
|
30
|
+
ifconfig br0 $gateway_ip netmask $netmask up
|
31
|
+
sysctl -w net.ipv4.ip_forward=1
|
32
|
+
fi
|
33
|
+
|
34
|
+
cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-br0
|
35
|
+
DEVICE=br0
|
36
|
+
ONBOOT=yes
|
37
|
+
BOOTPROTO=static
|
38
|
+
DELAY=0
|
39
|
+
TYPE=Bridge
|
40
|
+
IPADDR=$gateway_ip
|
41
|
+
NETWORK=$subnet
|
42
|
+
NETMASK=$netmask
|
43
|
+
GATEWAY=$gateway_ip
|
44
|
+
MTU=1500
|
45
|
+
IPV6INIT=no
|
46
|
+
USERCTL=no
|
47
|
+
EOF
|
48
|
+
|
49
|
+
# reset iptables
|
50
|
+
cat <<EOF > /etc/sysconfig/iptables
|
51
|
+
*nat
|
52
|
+
:PREROUTING ACCEPT [0:0]
|
53
|
+
:POSTROUTING ACCEPT [28:2070]
|
54
|
+
:OUTPUT ACCEPT [106:10068]
|
55
|
+
-A POSTROUTING -o eth0 -j MASQUERADE
|
56
|
+
COMMIT
|
57
|
+
EOF
|
58
|
+
|
59
|
+
service iptables restart
|
60
|
+
|
61
|
+
# mount cgroup
|
62
|
+
if [[ ! -d /cgroup ]]; then
|
63
|
+
mkdir -p /cgroup
|
64
|
+
fi
|
65
|
+
|
66
|
+
if [[ ! `mount | grep cgroup` ]]; then
|
67
|
+
mount none -t cgroup /cgroup
|
68
|
+
fi
|
69
|
+
|
70
|
+
if [[ ! `grep "/cgroup" /etc/fstab` ]]; then
|
71
|
+
cat <<EOF >> /etc/fstab
|
72
|
+
none /cgroup cgroup defaults 0 0
|
73
|
+
EOF
|
74
|
+
fi
|
75
|
+
|
76
|
+
# setup nameserver
|
77
|
+
cat <<EOF > /var/named/named.foo
|
78
|
+
\$ORIGIN $domain.
|
79
|
+
\$TTL 7200 ; 2 hours
|
80
|
+
@ IN SOA ns1.$domain. hostmaster.$domain. (
|
81
|
+
3641625943 ; serial
|
82
|
+
36000 ; refresh (10 hours)
|
83
|
+
900 ; retry (15 minutes)
|
84
|
+
36000 ; expire (10 hours)
|
85
|
+
7200 ; minimum (2 hours)
|
86
|
+
)
|
87
|
+
NS ns1.$domain.
|
88
|
+
ns1 A $gateway_ip
|
89
|
+
EOF
|
90
|
+
|
91
|
+
## set bind to forward original nameservers
|
92
|
+
original_nameservers=`grep nameserver /etc/resolv.conf | cut -d " " -f2 | sed s/$gateway_ip//`
|
93
|
+
bind_forward_options=''
|
94
|
+
if [[ -n `echo $original_nameservers | tr -d ' \n\t\r'` ]]; then
|
95
|
+
bind_forward_options="forwarders {
|
96
|
+
`echo $original_nameservers | xargs -n 1 | awk '{ print $1";" }'`
|
97
|
+
};
|
98
|
+
forward first;"
|
99
|
+
fi
|
100
|
+
|
101
|
+
mv /etc/named.conf /etc/named.conf.old
|
102
|
+
cat <<EOF > /etc/named.conf
|
103
|
+
options {
|
104
|
+
directory "/var/named";
|
105
|
+
dump-file "/var/named/data/cache_dump.db";
|
106
|
+
statistics-file "/var/named/data/named_stats.txt";
|
107
|
+
memstatistics-file "/var/named/data/named_mem_stats.txt";
|
108
|
+
$bind_forward_options
|
109
|
+
};
|
110
|
+
|
111
|
+
logging {
|
112
|
+
channel default_debug {
|
113
|
+
file "data/named.run";
|
114
|
+
severity dynamic;
|
115
|
+
};
|
116
|
+
};
|
117
|
+
|
118
|
+
zone "." IN {
|
119
|
+
type hint;
|
120
|
+
file "named.ca";
|
121
|
+
};
|
122
|
+
|
123
|
+
include "/etc/named.rfc1912.zones";
|
124
|
+
|
125
|
+
zone "$domain" in {
|
126
|
+
type master;
|
127
|
+
file "named.foo";
|
128
|
+
allow-update {any;};
|
129
|
+
};
|
130
|
+
EOF
|
131
|
+
|
132
|
+
# disable selinux to make it happy for bind to creating jnl file
|
133
|
+
echo 0 >/selinux/enforce
|
134
|
+
|
135
|
+
# fix the dir owner to grant bind to generate jnl
|
136
|
+
chown named:named /var/named
|
137
|
+
|
138
|
+
service named restart
|
139
|
+
|
140
|
+
# add our nameserver into /etc/resolv.conf
|
141
|
+
if [[ ! `grep "nameserver $gateway_ip" /etc/resolv.conf` ]]; then
|
142
|
+
cp /etc/resolv.conf /etc/resolv.conf.old
|
143
|
+
cat <<EOF > /etc/resolv.conf
|
144
|
+
nameserver $gateway_ip
|
145
|
+
`cat /etc/resolv.conf`
|
146
|
+
EOF
|
147
|
+
fi
|
148
|
+
|
149
|
+
# setup dhcp3 server
|
150
|
+
cat <<EOF > /etc/dhcp/dhcpd.conf
|
151
|
+
ddns-updates on;
|
152
|
+
ddns-update-style interim;
|
153
|
+
|
154
|
+
ddns-domainname "$domain.";
|
155
|
+
option domain-name "$domain.";
|
156
|
+
option domain-name-servers $gateway_ip;
|
157
|
+
|
158
|
+
option ntp-servers $gateway_ip;
|
159
|
+
default-lease-time 600;
|
160
|
+
max-lease-time 7200;
|
161
|
+
|
162
|
+
authoritative;
|
163
|
+
log-facility local7;
|
164
|
+
|
165
|
+
zone $domain. {
|
166
|
+
primary localhost;
|
167
|
+
}
|
168
|
+
|
169
|
+
subnet $subnet netmask $netmask {
|
170
|
+
range $range;
|
171
|
+
option routers $gateway_ip;
|
172
|
+
}
|
173
|
+
EOF
|
174
|
+
service dhcpd restart
|
175
|
+
|
File without changes
|
File without changes
|
@@ -11,10 +11,14 @@ if [ ! "$username" = "root" ]; then
|
|
11
11
|
exit 1
|
12
12
|
fi
|
13
13
|
|
14
|
-
cache="/var/cache/lxc
|
14
|
+
cache="/var/cache/lxc"
|
15
15
|
suite=$1
|
16
16
|
|
17
17
|
arch=$(arch)
|
18
|
+
if [ "$arch" == "x86_64" ]; then
|
19
|
+
arch=amd64
|
20
|
+
fi
|
21
|
+
|
18
22
|
if [ "$arch" == "i686" ]; then
|
19
23
|
arch=i386
|
20
24
|
fi
|
@@ -34,13 +38,10 @@ if [[ ! `type rinse` ]]; then
|
|
34
38
|
make install)
|
35
39
|
fi
|
36
40
|
|
37
|
-
# install rpm
|
38
|
-
apt-get install -y rpm
|
39
|
-
|
40
41
|
# create centos image using rinse
|
41
42
|
cat <<EOF > /tmp/after_post_install
|
42
43
|
chroot $cache/$suite-$arch rpm -Uvh http://rbel.co/rbel6
|
43
|
-
chroot $cache/$suite-$arch yum -y install man sudo openssh-server openssh-clients rubygem-chef
|
44
|
+
chroot $cache/$suite-$arch yum -y install tar man sudo bind-utils openssh-server openssh-clients rubygem-chef
|
44
45
|
EOF
|
45
46
|
chmod +x /tmp/after_post_install
|
46
47
|
|
@@ -11,7 +11,7 @@ if [ ! "$username" = "root" ]; then
|
|
11
11
|
exit 1
|
12
12
|
fi
|
13
13
|
|
14
|
-
cache="/var/cache/lxc
|
14
|
+
cache="/var/cache/lxc"
|
15
15
|
suite=$1
|
16
16
|
|
17
17
|
arch=$(arch)
|
@@ -28,8 +28,8 @@ if [ -e "$cache/$suite-$arch.tar.gz" ]; then
|
|
28
28
|
exit 0
|
29
29
|
fi
|
30
30
|
|
31
|
-
lucid_packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,dhcp3-client,ssh,lsb-release,wget,gpgv,gnupg,sudo,ruby,rubygems1.8,ruby-dev,libopenssl-ruby,build-essential,ssl-cert
|
32
|
-
natty_packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,isc-dhcp-client,isc-dhcp-common,ssh,lsb-release,gnupg,netbase,lxcguest,sudo,ruby,rubygems1.8,ruby-dev,libruby,build-essential,wget,ssl-cert
|
31
|
+
lucid_packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,dnsutils,dhcp3-client,ssh,lsb-release,wget,gpgv,gnupg,sudo,ruby,rubygems1.8,ruby-dev,libopenssl-ruby,build-essential,ssl-cert
|
32
|
+
natty_packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,dnsutils,isc-dhcp-client,isc-dhcp-common,ssh,lsb-release,gnupg,netbase,lxcguest,sudo,ruby,rubygems1.8,ruby-dev,libruby,build-essential,wget,ssl-cert
|
33
33
|
# check the mini ubuntu was not already downloaded
|
34
34
|
rm -rf "$cache/$suite-$arch"
|
35
35
|
mkdir -p "$cache/$suite-$arch"
|
@@ -0,0 +1,190 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
username=`id -nu`
|
4
|
+
if [ ! "$username" = "root" ]; then
|
5
|
+
echo "This command has to be run as root!"
|
6
|
+
exit 1
|
7
|
+
fi
|
8
|
+
|
9
|
+
OS=`cat /etc/issue | cut -f 1 -d " " -s`
|
10
|
+
|
11
|
+
|
12
|
+
gateway_ip="192.168.20.1"
|
13
|
+
subnet="192.168.20.0"
|
14
|
+
netmask="255.255.255.0"
|
15
|
+
range="192.168.20.2 192.168.20.254"
|
16
|
+
domain=foo
|
17
|
+
|
18
|
+
# setup bridge and nat
|
19
|
+
if [[ ! `ip link ls dev br0` ]]; then
|
20
|
+
brctl addbr br0
|
21
|
+
ifconfig br0 $gateway_ip netmask $netmask up
|
22
|
+
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
|
23
|
+
sysctl -w net.ipv4.ip_forward=1
|
24
|
+
fi
|
25
|
+
|
26
|
+
if [[ ! `grep "auto br0" /etc/network/interfaces` ]]; then
|
27
|
+
cat <<EOF >> /etc/network/interfaces
|
28
|
+
auto br0
|
29
|
+
iface br0 inet static
|
30
|
+
address $gateway_ip
|
31
|
+
netmask $netmask
|
32
|
+
bridge_stp off
|
33
|
+
bridge_maxwait 5
|
34
|
+
pre-up brctl addbr br0
|
35
|
+
post-up /usr/sbin/brctl setfd br0 0
|
36
|
+
EOF
|
37
|
+
fi
|
38
|
+
|
39
|
+
iptables-save > /etc/firewall.conf
|
40
|
+
echo "#!/bin/sh" > /etc/network/if-up.d/iptables
|
41
|
+
echo "iptables-restore < /etc/firewall.conf" >> /etc/network/if-up.d/iptables
|
42
|
+
chmod +x /etc/network/if-up.d/iptables
|
43
|
+
|
44
|
+
# setup cgroup
|
45
|
+
if [[ ! -d /cgroup ]]; then
|
46
|
+
mkdir -p /cgroup
|
47
|
+
fi
|
48
|
+
|
49
|
+
if [[ ! `mount | grep cgroup` ]]; then
|
50
|
+
mount none -t cgroup /cgroup
|
51
|
+
fi
|
52
|
+
|
53
|
+
if [[ ! `grep "/cgroup" /etc/fstab` ]]; then
|
54
|
+
cat <<EOF >> /etc/fstab
|
55
|
+
none /cgroup cgroup defaults 0 0
|
56
|
+
EOF
|
57
|
+
fi
|
58
|
+
|
59
|
+
# setup nameserver
|
60
|
+
cat <<EOF > /etc/bind/db.foo
|
61
|
+
\$ORIGIN $domain.
|
62
|
+
\$TTL 7200 ; 2 hours
|
63
|
+
@ IN SOA ns1.$domain. hostmaster.$domain. (
|
64
|
+
3641625943 ; serial
|
65
|
+
36000 ; refresh (10 hours)
|
66
|
+
900 ; retry (15 minutes)
|
67
|
+
36000 ; expire (10 hours)
|
68
|
+
7200 ; minimum (2 hours)
|
69
|
+
)
|
70
|
+
NS ns1.$domain.
|
71
|
+
ns1 A $gateway_ip
|
72
|
+
EOF
|
73
|
+
|
74
|
+
cat <<EOF > /etc/bind/named.conf.$domain
|
75
|
+
zone "$domain" in{
|
76
|
+
type master;
|
77
|
+
file "/etc/bind/db.$domain";
|
78
|
+
allow-update {any;};
|
79
|
+
};
|
80
|
+
EOF
|
81
|
+
|
82
|
+
## set bind to forward original nameservers
|
83
|
+
original_nameservers=`grep nameserver /etc/resolv.conf | cut -d " " -f2 | sed s/$gateway_ip//`
|
84
|
+
bind_forward_options=''
|
85
|
+
if [[ -n `echo $original_nameservers | tr -d ' \n\t\r'` ]]; then
|
86
|
+
bind_forward_options="forwarders {
|
87
|
+
`echo $original_nameservers | xargs -n 1 | awk '{ print $1";" }'`
|
88
|
+
};
|
89
|
+
forward first;"
|
90
|
+
fi
|
91
|
+
|
92
|
+
cat <<EOF > /etc/bind/named.conf.options.foo
|
93
|
+
options {
|
94
|
+
directory "/var/cache/bind";
|
95
|
+
$bind_forward_options
|
96
|
+
auth-nxdomain no; # conform to RFC1035
|
97
|
+
listen-on-v6 { any; };
|
98
|
+
};
|
99
|
+
EOF
|
100
|
+
|
101
|
+
# debian bind9 package does not have this default-zones file
|
102
|
+
# add this file to make it consistent between debian and ubuntu
|
103
|
+
cat <<EOF > /etc/bind/named.conf.default-zones
|
104
|
+
// prime the server with knowledge of the root servers
|
105
|
+
zone "." {
|
106
|
+
type hint;
|
107
|
+
file "/etc/bind/db.root";
|
108
|
+
};
|
109
|
+
|
110
|
+
// be authoritative for the localhost forward and reverse zones, and for
|
111
|
+
// broadcast zones as per RFC 1912
|
112
|
+
|
113
|
+
zone "localhost" {
|
114
|
+
type master;
|
115
|
+
file "/etc/bind/db.local";
|
116
|
+
};
|
117
|
+
|
118
|
+
zone "127.in-addr.arpa" {
|
119
|
+
type master;
|
120
|
+
file "/etc/bind/db.127";
|
121
|
+
};
|
122
|
+
|
123
|
+
zone "0.in-addr.arpa" {
|
124
|
+
type master;
|
125
|
+
file "/etc/bind/db.0";
|
126
|
+
};
|
127
|
+
|
128
|
+
zone "255.in-addr.arpa" {
|
129
|
+
type master;
|
130
|
+
file "/etc/bind/db.255";
|
131
|
+
};
|
132
|
+
EOF
|
133
|
+
|
134
|
+
mv /etc/bind/named.conf /etc/bind/named.conf.old
|
135
|
+
cat <<EOF > /etc/bind/named.conf
|
136
|
+
include "/etc/bind/named.conf.options.foo";
|
137
|
+
include "/etc/bind/named.conf.local";
|
138
|
+
include "/etc/bind/named.conf.default-zones";
|
139
|
+
include "/etc/bind/named.conf.$domain";
|
140
|
+
EOF
|
141
|
+
|
142
|
+
sudo chmod 775 /etc/bind
|
143
|
+
|
144
|
+
/etc/init.d/bind9 restart
|
145
|
+
|
146
|
+
# add our nameserver into /etc/resolv.conf
|
147
|
+
if [[ ! `grep "nameserver $gateway_ip" /etc/resolv.conf` ]]; then
|
148
|
+
cp /etc/resolv.conf /etc/resolv.conf.old
|
149
|
+
cat <<EOF > /etc/resolv.conf
|
150
|
+
nameserver $gateway_ip
|
151
|
+
`cat /etc/resolv.conf`
|
152
|
+
EOF
|
153
|
+
fi
|
154
|
+
|
155
|
+
# setup dhcp server
|
156
|
+
if [[ $OS = "Ubuntu" ]]; then
|
157
|
+
dhcp_conf_dir=dhcp
|
158
|
+
dhcp_daemon=isc-dhcp-server
|
159
|
+
else
|
160
|
+
dhcp_conf_dir=dhcp3
|
161
|
+
dhcp_daemon=dhcp3-server
|
162
|
+
fi
|
163
|
+
|
164
|
+
mv /etc/$dhcp_conf_dir/dhcpd.conf /etc/$dhcp_conf_dir/dhcpd.conf.old
|
165
|
+
cat <<EOF > /etc/$dhcp_conf_dir/dhcpd.conf
|
166
|
+
ddns-updates on;
|
167
|
+
ddns-update-style interim;
|
168
|
+
|
169
|
+
ddns-domainname "$domain.";
|
170
|
+
option domain-name "$domain.";
|
171
|
+
option domain-name-servers $gateway_ip;
|
172
|
+
|
173
|
+
option ntp-servers $gateway_ip;
|
174
|
+
default-lease-time 600;
|
175
|
+
max-lease-time 7200;
|
176
|
+
|
177
|
+
authoritative;
|
178
|
+
log-facility local7;
|
179
|
+
|
180
|
+
zone $domain. {
|
181
|
+
primary localhost;
|
182
|
+
}
|
183
|
+
|
184
|
+
subnet $subnet netmask $netmask {
|
185
|
+
range $range;
|
186
|
+
option routers $gateway_ip;
|
187
|
+
}
|
188
|
+
EOF
|
189
|
+
sudo /etc/init.d/$dhcp_daemon restart
|
190
|
+
|
@@ -23,26 +23,20 @@ mount "/cgroup" do
|
|
23
23
|
action [:mount, :enable]
|
24
24
|
end
|
25
25
|
|
26
|
-
template "/usr/lib/lxc/templates/lxc-lucid
|
27
|
-
source "lxc-lucid
|
26
|
+
template "/usr/lib/lxc/templates/lxc-lucid" do
|
27
|
+
source "lxc-lucid"
|
28
28
|
mode "0755"
|
29
29
|
action :create
|
30
30
|
end
|
31
31
|
|
32
|
-
template "/usr/lib/lxc/templates/lxc-natty
|
33
|
-
source "lxc-natty
|
32
|
+
template "/usr/lib/lxc/templates/lxc-natty" do
|
33
|
+
source "lxc-natty"
|
34
34
|
mode "0755"
|
35
35
|
action :create
|
36
36
|
end
|
37
37
|
|
38
|
-
|
39
|
-
source "lxc-
|
38
|
+
template "/usr/lib/lxc/templates/lxc-centos-6" do
|
39
|
+
source "lxc-centos-6"
|
40
40
|
mode "0755"
|
41
|
-
|
42
|
-
|
43
|
-
bash "create ubuntu rootfs image ... this will take a while" do
|
44
|
-
code <<-EOH
|
45
|
-
/usr/local/bin/lxc-create-ubuntu-image natty
|
46
|
-
EOH
|
47
|
-
end
|
48
|
-
|
41
|
+
action :create
|
42
|
+
end
|
@@ -24,7 +24,7 @@ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCguB7XL3ARzLZYLsIMZe4UUO371m+H5C6V8MhtmSl
|
|
24
24
|
# add default route to host
|
25
25
|
cat <<EOF > $rootfs/etc/rc.local
|
26
26
|
#!/bin/sh -e
|
27
|
-
route add default gw
|
27
|
+
route add default gw <%= node.network.gateway_ip %>
|
28
28
|
exit 0
|
29
29
|
EOF
|
30
30
|
|
@@ -97,7 +97,7 @@ copy_centos()
|
|
97
97
|
|
98
98
|
install_centos()
|
99
99
|
{
|
100
|
-
cache="/var/cache/lxc
|
100
|
+
cache="/var/cache/lxc"
|
101
101
|
rootfs=$1
|
102
102
|
mkdir -p /var/lock/subsys/
|
103
103
|
(
|
@@ -108,6 +108,10 @@ install_centos()
|
|
108
108
|
fi
|
109
109
|
|
110
110
|
arch=$(arch)
|
111
|
+
if [ "$arch" == "x86_64" ]; then
|
112
|
+
arch=amd64
|
113
|
+
fi
|
114
|
+
|
111
115
|
if [ "$arch" == "i686" ]; then
|
112
116
|
arch=i386
|
113
117
|
fi
|
@@ -194,7 +198,7 @@ EOF
|
|
194
198
|
|
195
199
|
clean()
|
196
200
|
{
|
197
|
-
cache="/var/cache/lxc
|
201
|
+
cache="/var/cache/lxc"
|
198
202
|
|
199
203
|
if [ ! -e $cache ]; then
|
200
204
|
exit 0
|
@@ -149,7 +149,7 @@ copy_ubuntu()
|
|
149
149
|
|
150
150
|
install_ubuntu()
|
151
151
|
{
|
152
|
-
cache="/var/cache/lxc
|
152
|
+
cache="/var/cache/lxc"
|
153
153
|
rootfs=$1
|
154
154
|
mkdir -p /var/lock/subsys/
|
155
155
|
(
|
@@ -237,7 +237,7 @@ EOF
|
|
237
237
|
|
238
238
|
clean()
|
239
239
|
{
|
240
|
-
cache="/var/cache/lxc
|
240
|
+
cache="/var/cache/lxc"
|
241
241
|
|
242
242
|
if [ ! -e $cache ]; then
|
243
243
|
exit 0
|
@@ -70,7 +70,7 @@ copy_ubuntu()
|
|
70
70
|
|
71
71
|
install_ubuntu()
|
72
72
|
{
|
73
|
-
cache="/var/cache/lxc
|
73
|
+
cache="/var/cache/lxc"
|
74
74
|
rootfs=$1
|
75
75
|
mkdir -p /var/lock/subsys/
|
76
76
|
(
|
@@ -158,7 +158,7 @@ EOF
|
|
158
158
|
|
159
159
|
clean()
|
160
160
|
{
|
161
|
-
cache="/var/cache/lxc
|
161
|
+
cache="/var/cache/lxc"
|
162
162
|
|
163
163
|
if [ ! -e $cache ]; then
|
164
164
|
exit 0
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
hostname=`hostname`
|
4
|
+
gateway_ip="192.168.20.1"
|
5
|
+
domain=foo
|
6
|
+
|
7
|
+
function get_ip {
|
8
|
+
echo `ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
|
9
|
+
}
|
10
|
+
|
11
|
+
function update_ns {
|
12
|
+
ip=`get_ip`
|
13
|
+
# add default route to host and update ns
|
14
|
+
cat <<END > /tmp/nsupdate.txt
|
15
|
+
server $gateway_ip
|
16
|
+
update delete ${hostname}.$domain
|
17
|
+
update add ${hostname}.$domain 86400 A $ip
|
18
|
+
send
|
19
|
+
END
|
20
|
+
|
21
|
+
route add default gw $gateway_ip
|
22
|
+
nsupdate /tmp/nsupdate.txt
|
23
|
+
}
|
24
|
+
|
25
|
+
if [[ -n `get_ip` ]] ; then # if manually set ip address
|
26
|
+
# use host dns server
|
27
|
+
rm /etc/resolv.conf
|
28
|
+
cat <<END > /etc/resolv.conf
|
29
|
+
nameserver $gateway_ip
|
30
|
+
domain $domain
|
31
|
+
search $domain
|
32
|
+
END
|
33
|
+
else # if ip not set, use dhcp
|
34
|
+
/sbin/dhclient eth0
|
35
|
+
fi
|
36
|
+
|
37
|
+
update_ns
|
38
|
+
exit 0
|