~serge-hallyn/ubuntu/saucy/lxc/lxc-dnsmasq

« back to all changes in this revision

Viewing changes to templates/lxc-debian.in

  • Committer: Stéphane Graber
  • Date: 2013-02-18 15:20:18 UTC
  • mto: This revision was merged to the branch mainline in revision 190.
  • Revision ID: stgraber@ubuntu.com-20130218152018-ls2gi9hkqs2kuhj8
Tags: upstream-0.9.0~alpha3
Import upstream version 0.9.0~alpha3

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
# This library is distributed in the hope that it will be useful,
15
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
17
# Lesser General Public License for more details.
18
18
 
19
19
# You should have received a copy of the GNU Lesser General Public
31
31
    # squeeze only has /dev/tty and /dev/tty0 by default,
32
32
    # therefore creating missing device nodes for tty1-4.
33
33
    for tty in $(seq 1 4); do
34
 
        if [ ! -e $rootfs/dev/tty$tty ]; then
35
 
            mknod $rootfs/dev/tty$tty c 4 $tty
36
 
        fi
 
34
        if [ ! -e $rootfs/dev/tty$tty ]; then
 
35
            mknod $rootfs/dev/tty$tty c 4 $tty
 
36
        fi
37
37
    done
38
38
 
39
39
    # configure the inittab
54
54
c2:12345:respawn:/sbin/getty 38400 tty2 linux
55
55
c3:12345:respawn:/sbin/getty 38400 tty3 linux
56
56
c4:12345:respawn:/sbin/getty 38400 tty4 linux
 
57
p6::ctrlaltdel:/sbin/init 6
 
58
p0::powerfail:/sbin/init 0
57
59
EOF
58
60
 
59
61
    # disable selinux in debian
76
78
 
77
79
    # reconfigure some services
78
80
    if [ -z "$LANG" ]; then
79
 
        chroot $rootfs locale-gen en_US.UTF-8 UTF-8
80
 
        chroot $rootfs update-locale LANG=en_US.UTF-8
 
81
        chroot $rootfs locale-gen en_US.UTF-8 UTF-8
 
82
        chroot $rootfs update-locale LANG=en_US.UTF-8
81
83
    else
82
 
        chroot $rootfs locale-gen $LANG $(echo $LANG | cut -d. -f2)
83
 
        chroot $rootfs update-locale LANG=$LANG
 
84
        chroot $rootfs locale-gen $LANG $(echo $LANG | cut -d. -f2)
 
85
        chroot $rootfs update-locale LANG=$LANG
84
86
    fi
85
87
 
86
88
    # remove pointless services in a container
95
97
    return 0
96
98
}
97
99
 
 
100
cleanup()
 
101
{
 
102
    rm -rf $cache/partial-$SUITE-$arch
 
103
    rm -rf $cache/rootfs-$SUITE-$arch
 
104
}
 
105
 
98
106
download_debian()
99
107
{
100
108
    packages=\
102
110
locales,\
103
111
libui-dialog-perl,\
104
112
dialog,\
105
 
dhcp3-client,\
 
113
isc-dhcp-client,\
106
114
netbase,\
107
115
net-tools,\
108
116
iproute,\
111
119
    cache=$1
112
120
    arch=$2
113
121
 
 
122
    trap cleanup EXIT SIGHUP SIGINT SIGTERM
114
123
    # check the mini debian was not already downloaded
115
124
    mkdir -p "$cache/partial-$SUITE-$arch"
116
125
    if [ $? -ne 0 ]; then
117
 
        echo "Failed to create '$cache/partial-$SUITE-$arch' directory"
118
 
        return 1
 
126
        echo "Failed to create '$cache/partial-$SUITE-$arch' directory"
 
127
        return 1
119
128
    fi
120
129
 
121
130
    # download a mini debian into a cache
122
131
    echo "Downloading debian minimal ..."
123
132
    debootstrap --verbose --variant=minbase --arch=$arch \
124
 
        --include=$packages \
125
 
        "$SUITE" "$cache/partial-$SUITE-$arch" $MIRROR
 
133
        --include=$packages \
 
134
        "$SUITE" "$cache/partial-$SUITE-$arch" $MIRROR
126
135
    if [ $? -ne 0 ]; then
127
 
        echo "Failed to download the rootfs, aborting."
128
 
        return 1
 
136
        echo "Failed to download the rootfs, aborting."
 
137
        return 1
129
138
    fi
130
139
 
131
140
    mv "$1/partial-$SUITE-$arch" "$1/rootfs-$SUITE-$arch"
132
141
    echo "Download complete."
 
142
    trap EXIT
 
143
    trap SIGINT
 
144
    trap SIGTERM
 
145
    trap SIGHUP
133
146
 
134
147
    return 0
135
148
}
143
156
    # make a local copy of the minidebian
144
157
    echo -n "Copying rootfs to $rootfs..."
145
158
    mkdir -p $rootfs
146
 
    rsync -a "$cache/rootfs-$SUITE-$arch"/ $rootfs/ || return 1
 
159
    rsync -Ha "$cache/rootfs-$SUITE-$arch"/ $rootfs/ || return 1
147
160
    return 0
148
161
}
149
162
 
153
166
    rootfs=$1
154
167
    mkdir -p @LOCALSTATEDIR@/lock/subsys/
155
168
    (
156
 
        flock -n -x 200
157
 
        if [ $? -ne 0 ]; then
158
 
            echo "Cache repository is busy."
159
 
            return 1
160
 
        fi
161
 
 
162
 
        arch=$(dpkg --print-architecture)
163
 
 
164
 
        echo "Checking cache download in $cache/rootfs-$SUITE-$arch ... "
165
 
        if [ ! -e "$cache/rootfs-$SUITE-$arch" ]; then
166
 
            download_debian $cache $arch
167
 
            if [ $? -ne 0 ]; then
168
 
                echo "Failed to download 'debian base'"
169
 
                return 1
170
 
            fi
171
 
        fi
172
 
 
173
 
        copy_debian $cache $arch $rootfs
174
 
        if [ $? -ne 0 ]; then
175
 
            echo "Failed to copy rootfs"
176
 
            return 1
177
 
        fi
178
 
 
179
 
        return 0
180
 
 
181
 
        ) 200>@LOCALSTATEDIR@/lock/subsys/lxc
 
169
        flock -x 200
 
170
        if [ $? -ne 0 ]; then
 
171
            echo "Cache repository is busy."
 
172
            return 1
 
173
        fi
 
174
 
 
175
        arch=$(dpkg --print-architecture)
 
176
 
 
177
        echo "Checking cache download in $cache/rootfs-$SUITE-$arch ... "
 
178
        if [ ! -e "$cache/rootfs-$SUITE-$arch" ]; then
 
179
            download_debian $cache $arch
 
180
            if [ $? -ne 0 ]; then
 
181
                echo "Failed to download 'debian base'"
 
182
                return 1
 
183
            fi
 
184
        fi
 
185
 
 
186
        copy_debian $cache $arch $rootfs
 
187
        if [ $? -ne 0 ]; then
 
188
            echo "Failed to copy rootfs"
 
189
            return 1
 
190
        fi
 
191
 
 
192
        return 0
 
193
 
 
194
        ) 200>@LOCALSTATEDIR@/lock/subsys/lxc-debian
182
195
 
183
196
    return $?
184
197
}
189
202
    rootfs=$2
190
203
    hostname=$3
191
204
 
 
205
    grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
192
206
    cat <<EOF >> $path/config
193
207
lxc.tty = 4
194
208
lxc.pts = 1024
195
 
lxc.rootfs = $rootfs
196
209
lxc.utsname = $hostname
 
210
 
 
211
# When using LXC with apparmor, uncomment the next line to run unconfined:
 
212
#lxc.aa_profile = unconfined
 
213
 
197
214
lxc.cgroup.devices.deny = a
198
215
# /dev/null and zero
199
216
lxc.cgroup.devices.allow = c 1:3 rwm
212
229
lxc.cgroup.devices.allow = c 254:0 rwm
213
230
 
214
231
# mounts point
215
 
lxc.mount.entry=proc $rootfs/proc proc nodev,noexec,nosuid 0 0
216
 
lxc.mount.entry=sysfs $rootfs/sys sysfs defaults  0 0
 
232
lxc.mount.entry = proc proc proc nodev,noexec,nosuid 0 0
 
233
lxc.mount.entry = sysfs sys sysfs defaults  0 0
217
234
EOF
218
235
 
219
236
    if [ $? -ne 0 ]; then
220
 
        echo "Failed to add configuration"
221
 
        return 1
 
237
        echo "Failed to add configuration"
 
238
        return 1
222
239
    fi
223
240
 
224
241
    return 0
229
246
    cache="@LOCALSTATEDIR@/cache/lxc/debian"
230
247
 
231
248
    if [ ! -e $cache ]; then
232
 
        exit 0
 
249
        exit 0
233
250
    fi
234
251
 
235
252
    # lock, so we won't purge while someone is creating a repository
236
253
    (
237
 
        flock -n -x 200
238
 
        if [ $? != 0 ]; then
239
 
            echo "Cache repository is busy."
240
 
            exit 1
241
 
        fi
242
 
 
243
 
        echo -n "Purging the download cache..."
244
 
        rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
245
 
        exit 0
246
 
 
247
 
    ) 200>@LOCALSTATEDIR@/lock/subsys/lxc
 
254
        flock -x 200
 
255
        if [ $? != 0 ]; then
 
256
            echo "Cache repository is busy."
 
257
            exit 1
 
258
        fi
 
259
 
 
260
        echo -n "Purging the download cache..."
 
261
        rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
 
262
        exit 0
 
263
 
 
264
    ) 200>@LOCALSTATEDIR@/lock/subsys/lxc-debian
248
265
}
249
266
 
250
267
usage()
258
275
options=$(getopt -o hp:n:c -l help,path:,name:,clean -- "$@")
259
276
if [ $? -ne 0 ]; then
260
277
        usage $(basename $0)
261
 
        exit 1
 
278
        exit 1
262
279
fi
263
280
eval set -- "$options"
264
281
 
267
284
    case "$1" in
268
285
        -h|--help)      usage $0 && exit 0;;
269
286
        -p|--path)      path=$2; shift 2;;
270
 
        -n|--name)      name=$2; shift 2;;
271
 
        -c|--clean)     clean=$2; shift 2;;
 
287
        -n|--name)      name=$2; shift 2;;
 
288
        -c|--clean)     clean=$2; shift 2;;
272
289
        --)             shift 1; break ;;
273
290
        *)              break ;;
274
291
    esac
295
312
    exit 1
296
313
fi
297
314
 
298
 
rootfs=$path/rootfs
 
315
# detect rootfs
 
316
config="$path/config"
 
317
if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
 
318
    rootfs=`grep 'lxc.rootfs =' $config | awk -F= '{ print $2 }'`
 
319
else
 
320
    rootfs=$path/rootfs
 
321
fi
 
322
 
299
323
 
300
324
install_debian $rootfs
301
325
if [ $? -ne 0 ]; then