toft 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,253 @@
1
+ #!/bin/bash
2
+
3
+ echo "Creating natty node..."
4
+
5
+ configure_ubuntu()
6
+ {
7
+ rootfs=$1
8
+ hostname=$2
9
+
10
+ # disable selinux in ubuntu
11
+ mkdir -p $rootfs/selinux
12
+ echo 0 > $rootfs/selinux/enforce
13
+
14
+ # add host root ssh access
15
+ mkdir $rootfs/root/.ssh
16
+ chmod 0600 $rootfs/root/.ssh
17
+ cat <<-EOF > $rootfs/root/.ssh/authorized_keys
18
+ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCguB7XL3ARzLZYLsIMZe4UUO371m+H5C6V8MhtmSlgXtgHDo7eZhNSm5zCeoyGd32OKeLxuxCCEkXfDDF1aa2a6twcASE3pmWNdnBS7auiOH4P7g+eQ4Aw9v7DdESbIVgHF/NDiAEFFdmApYNM3oCX2FhEVNVKxkkIokUr4axYFJzmJ6Xoi5Sd8JtPC85FZVXqDucZDnHQlOcCkbSo0UOmsWQGwtu8eUHoDeUG0dB8ntb9xlBeLctdrAPhuFYCX8IfFkdcakkzv61ETPbKE6g9wdTDC/TEep7/AHGYmarziRnwKiVOL1jnE1coOJLqy8wOC3dKGmRZy9D4sTc+FRV root insecure public key
19
+ EOF
20
+
21
+ # copy host resolve
22
+ rm $rootfs/etc/resolv.conf
23
+ cp /etc/resolv.conf $rootfs/etc/resolv.conf
24
+
25
+ # add default route to host
26
+ cat <<EOF > $rootfs/etc/rc.local
27
+ #!/bin/sh -e
28
+ route add default gw 192.168.20.1
29
+ exit 0
30
+ EOF
31
+
32
+ # disable selinux in ubuntu
33
+ mkdir -p $rootfs/selinux
34
+ echo 0 > $rootfs/selinux/enforce
35
+
36
+ # set the hostname
37
+ cat <<EOF > $rootfs/etc/hostname
38
+ $hostname
39
+ EOF
40
+ # set minimal hosts
41
+ cat <<EOF > $rootfs/etc/hosts
42
+ 127.0.0.1 localhost $hostname
43
+ EOF
44
+
45
+ # suppress log level output for udev
46
+ sed -i "s/=\"err\"/=0/" $rootfs/etc/udev/udev.conf
47
+
48
+ # remove jobs for consoles 5 and 6 since we only create 4 consoles in
49
+ # this template
50
+ rm -f $rootfs/etc/init/tty{5,6}.conf
51
+
52
+ echo "Set root password to 'root'"
53
+ echo "root:root" | chroot $rootfs chpasswd
54
+
55
+ return 0
56
+ }
57
+
58
+ copy_ubuntu()
59
+ {
60
+ cache=$1
61
+ arch=$2
62
+ rootfs=$3
63
+
64
+ # make a local copy of the miniubuntu
65
+ echo "Extracting rootfs image to $rootfs ..."
66
+ mkdir $rootfs
67
+ tar zxf $cache/natty-$arch.tar.gz -C $rootfs || return 1
68
+ return 0
69
+ }
70
+
71
+ install_ubuntu()
72
+ {
73
+ cache="/var/cache/lxc/ubuntu"
74
+ rootfs=$1
75
+ mkdir -p /var/lock/subsys/
76
+ (
77
+ flock -n -x 200
78
+ if [ $? -ne 0 ]; then
79
+ echo "Cache repository is busy."
80
+ return 1
81
+ fi
82
+
83
+ arch=$(arch)
84
+ if [ "$arch" == "x86_64" ]; then
85
+ arch=amd64
86
+ fi
87
+
88
+ if [ "$arch" == "i686" ]; then
89
+ arch=i386
90
+ fi
91
+
92
+ echo "Checking image cache in $cache/rootfs-$arch ... "
93
+ if [ ! -e "$cache/rootfs-$arch" ]; then
94
+ if [ $? -ne 0 ]; then
95
+ echo "Failed to download 'ubuntu base'"
96
+ return 1
97
+ fi
98
+ fi
99
+
100
+ copy_ubuntu $cache $arch $rootfs
101
+ if [ $? -ne 0 ]; then
102
+ echo "Failed to copy rootfs"
103
+ return 1
104
+ fi
105
+
106
+ return 0
107
+
108
+ ) 200>/var/lock/subsys/lxc
109
+
110
+ return $?
111
+ }
112
+
113
+ copy_configuration()
114
+ {
115
+ path=$1
116
+ rootfs=$2
117
+ name=$3
118
+
119
+ cat <<EOF >> $path/config
120
+ lxc.utsname = $name
121
+
122
+ lxc.tty = 4
123
+ lxc.pts = 1024
124
+ lxc.rootfs = $rootfs
125
+ lxc.mount = $path/fstab
126
+
127
+ lxc.cgroup.devices.deny = a
128
+ # /dev/null and zero
129
+ lxc.cgroup.devices.allow = c 1:3 rwm
130
+ lxc.cgroup.devices.allow = c 1:5 rwm
131
+ # consoles
132
+ lxc.cgroup.devices.allow = c 5:1 rwm
133
+ lxc.cgroup.devices.allow = c 5:0 rwm
134
+ # lxc.cgroup.devices.allow = c 4:0 rwm
135
+ # lxc.cgroup.devices.allow = c 4:1 rwm
136
+ # /dev/{,u}random
137
+ lxc.cgroup.devices.allow = c 1:9 rwm
138
+ lxc.cgroup.devices.allow = c 1:8 rwm
139
+ lxc.cgroup.devices.allow = c 136:* rwm
140
+ lxc.cgroup.devices.allow = c 5:2 rwm
141
+ # rtc
142
+ lxc.cgroup.devices.allow = c 254:0 rwm
143
+ EOF
144
+
145
+ cat <<EOF > $path/fstab
146
+ proc $rootfs/proc proc nodev,noexec,nosuid 0 0
147
+ devpts $rootfs/dev/pts devpts defaults 0 0
148
+ sysfs $rootfs/sys sysfs defaults 0 0
149
+ EOF
150
+
151
+ if [ $? -ne 0 ]; then
152
+ echo "Failed to add configuration"
153
+ return 1
154
+ fi
155
+
156
+ return 0
157
+ }
158
+
159
+ clean()
160
+ {
161
+ cache="/var/cache/lxc/ubuntu"
162
+
163
+ if [ ! -e $cache ]; then
164
+ exit 0
165
+ fi
166
+
167
+ # lock, so we won't purge while someone is creating a repository
168
+ (
169
+ flock -n -x 200
170
+ if [ $? != 0 ]; then
171
+ echo "Cache repository is busy."
172
+ exit 1
173
+ fi
174
+
175
+ echo -n "Purging the download cache..."
176
+ rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
177
+ exit 0
178
+
179
+ ) 200>/var/lock/subsys/lxc
180
+ }
181
+
182
+ usage()
183
+ {
184
+ cat <<EOF
185
+ $1 -h|--help -p|--path=<path> --clean
186
+ EOF
187
+ return 0
188
+ }
189
+
190
+ options=$(getopt -o hp:n:c -l help,path:,name:,clean -- "$@")
191
+ if [ $? -ne 0 ]; then
192
+ usage $(basename $0)
193
+ exit 1
194
+ fi
195
+ eval set -- "$options"
196
+
197
+ while true
198
+ do
199
+ case "$1" in
200
+ -h|--help) usage $0 && exit 0;;
201
+ -p|--path) path=$2; shift 2;;
202
+ -n|--name) name=$2; shift 2;;
203
+ -c|--clean) clean=$2; shift 2;;
204
+ --) shift 1; break ;;
205
+ *) break ;;
206
+ esac
207
+ done
208
+
209
+ if [ ! -z "$clean" -a -z "$path" ]; then
210
+ clean || exit 1
211
+ exit 0
212
+ fi
213
+
214
+ type debootstrap
215
+ if [ $? -ne 0 ]; then
216
+ echo "'debootstrap' command is missing"
217
+ exit 1
218
+ fi
219
+
220
+ if [ -z "$path" ]; then
221
+ echo "'path' parameter is required"
222
+ exit 1
223
+ fi
224
+
225
+ if [ "$(id -u)" != "0" ]; then
226
+ echo "This script should be run as 'root'"
227
+ exit 1
228
+ fi
229
+
230
+ rootfs=$path/rootfs
231
+
232
+ install_ubuntu $rootfs
233
+ if [ $? -ne 0 ]; then
234
+ echo "failed to install ubuntu"
235
+ exit 1
236
+ fi
237
+
238
+ configure_ubuntu $rootfs $name
239
+ if [ $? -ne 0 ]; then
240
+ echo "failed to configure ubuntu for a container"
241
+ exit 1
242
+ fi
243
+
244
+ copy_configuration $path $rootfs $name
245
+ if [ $? -ne 0 ]; then
246
+ echo "failed write configuration file"
247
+ exit 1
248
+ fi
249
+
250
+ if [ ! -z $clean ]; then
251
+ clean || exit 1
252
+ exit 0
253
+ fi
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toft
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Huang Liang
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-26 00:00:00 Z
18
+ date: 2011-10-01 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
@@ -109,12 +109,20 @@ files:
109
109
  - lib/toft/node.rb
110
110
  - lib/toft/node_controller.rb
111
111
  - lib/toft/version.rb
112
- - scripts/bash/install-chef-ubuntu.sh
113
- - scripts/bash/install-rvm.sh
112
+ - scripts/centos/bin/lxc-prepare-host
114
113
  - scripts/cookbooks/lxc/attributes/default.rb
115
114
  - scripts/cookbooks/lxc/files/default/lxc-create-ubuntu-image
116
115
  - scripts/cookbooks/lxc/recipes/default.rb
117
116
  - scripts/cookbooks/lxc/templates/default/lxc-lucid-chef
117
+ - scripts/cookbooks/lxc/templates/default/lxc-natty-chef
118
+ - scripts/ubuntu/bin/install-chef-ubuntu.sh
119
+ - scripts/ubuntu/bin/install-rvm.sh
120
+ - scripts/ubuntu/bin/lxc-create-centos-image
121
+ - scripts/ubuntu/bin/lxc-create-ubuntu-image
122
+ - scripts/ubuntu/bin/lxc-prepare-host
123
+ - scripts/ubuntu/lxc-templates/lxc-centos-6
124
+ - scripts/ubuntu/lxc-templates/lxc-lucid
125
+ - scripts/ubuntu/lxc-templates/lxc-natty
118
126
  - spec/spec_helper.rb
119
127
  - spec/tuft/chef_attributes_spec.rb
120
128
  homepage: https://github.com/exceedhl/toft
@@ -146,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
154
  requirements: []
147
155
 
148
156
  rubyforge_project: toft
149
- rubygems_version: 1.8.8
157
+ rubygems_version: 1.8.6
150
158
  signing_key:
151
159
  specification_version: 3
152
160
  summary: toft aims to help test infrastructure code such as chef