Revision 53a5929f
b/snf-image-host/Makefile.am | ||
---|---|---|
22 | 22 |
-e 's|@osname[@]|$(osname)|g' \ |
23 | 23 |
-e 's|@defaultdir[@]|$(defaultdir)|g' \ |
24 | 24 |
-e 's|@HELPER_DIR[@]|$(HELPER_DIR)|g' \ |
25 |
-e 's|@HELPER_CACHE_DIR[@]|$(HELPER_CACHE_DIR)|g' \ |
|
25 | 26 |
-e 's|@HELPER_IMG[@]|$(HELPER_IMG)|g' \ |
26 | 27 |
-e 's|@HELPER_KERNEL[@]|$(HELPER_KERNEL)|g' \ |
27 | 28 |
-e 's|@HELPER_INITRD[@]|$(HELPER_INITRD)|g' \ |
b/snf-image-host/common.sh.in | ||
---|---|---|
292 | 292 |
|
293 | 293 |
do_debootstrap() { |
294 | 294 |
local target="$1" |
295 |
local cache="$2" |
|
296 |
local pkgs="$3" |
|
295 | 297 |
|
296 | 298 |
echo "Debootstraping to create a new root filesystem:" |
297 | 299 |
|
... | ... | |
308 | 310 |
"$HELPER_MIRROR" 2>&1 | sed -e 's/^/DEBOOTSTRAP: /g' |
309 | 311 |
|
310 | 312 |
# Save the package list |
311 |
chroot "$target" dpkg-query -W -f "\${Package}\n" > "$HELPER_CACHE_PKGS"
|
|
313 |
chroot "$target" dpkg-query -W -f "\${Package}\n" > "$pkgs"
|
|
312 | 314 |
|
313 | 315 |
rm "$target/usr/sbin/policy-rc.d" |
314 | 316 |
|
... | ... | |
316 | 318 |
find "$target/var/cache/apt/archives" -type f -name '*.deb' -print0 | \ |
317 | 319 |
xargs -r0 rm -f |
318 | 320 |
|
319 |
local tmp_cache=$(mktemp "$CACHE_FILE.XXXXXX")
|
|
321 |
local tmp_cache=$(mktemp "$cache.XXXXXX")
|
|
320 | 322 |
tar cf "$tmp_cache" --one-file-system -C "$target" . || \ |
321 | 323 |
{ rm "$tmp_cache"; false; } |
322 | 324 |
# Overwrite the default cache file. Not the user specified if present. |
323 |
mv -f "$tmp_cache" "$HELPER_CACHE_FILE"
|
|
325 |
mv -f "$tmp_cache" "$cache"
|
|
324 | 326 |
} |
325 | 327 |
|
326 | 328 |
do_multistrap() { |
327 | 329 |
local target="$1" |
330 |
local cache="$2" |
|
331 |
local pkgs="$3" |
|
328 | 332 |
|
329 | 333 |
# Create a policy-rc.d file to deny init script execution |
330 | 334 |
mkdir -p "$target/usr/sbin" |
... | ... | |
338 | 342 |
-f "$MULTISTRAP_CONFIG" 2>&1 | sed -u -e 's/^/MULTISTRAP: /g' |
339 | 343 |
|
340 | 344 |
# Save the package list |
341 |
chroot "$target" dpkg-query -W -f "\${Package}\n" > "$HELPER_CACHE_PKGS"
|
|
345 |
chroot "$target" dpkg-query -W -f "\${Package}\n" > "$pkgs"
|
|
342 | 346 |
|
343 | 347 |
rm "$target/usr/sbin/policy-rc.d" |
344 | 348 |
|
345 |
local tmp_cache=$(mktemp "$CACHE_FILE.XXXXXX")
|
|
349 |
local tmp_cache=$(mktemp "$cache.XXXXXX")
|
|
346 | 350 |
tar cf "$tmp_cache" --one-file-system -C "$target" . || \ |
347 | 351 |
{ rm "$tmp_cache"; false; } |
348 | 352 |
# Overwrite the default cache file. Not the user specified if present. |
349 |
mv -f "$tmp_cache" "$HELPER_CACHE_FILE"
|
|
353 |
mv -f "$tmp_cache" "$cache"
|
|
350 | 354 |
} |
351 | 355 |
|
352 | 356 |
report_and_cleanup(){ |
... | ... | |
401 | 405 |
: ${IMAGE_DIR:="@localstatedir@/lib/snf-image"} |
402 | 406 |
: ${IMAGE_DEBUG:="no"} |
403 | 407 |
: ${HELPER_DIR:="@HELPER_DIR@"} |
408 |
: ${HELPER_CACHE_DIR:="@HELPER_CACHE_DIR@"} |
|
404 | 409 |
: ${HELPER_IMG:="@HELPER_IMG@"} |
405 | 410 |
: ${HELPER_KERNEL:="@HELPER_KERNEL@"} |
406 | 411 |
: ${HELPER_INITRD:="@HELPER_INITRD@"} |
... | ... | |
408 | 413 |
: ${HELPER_SOFT_TIMEOUT:=20} |
409 | 414 |
: ${HELPER_HARD_TIMEOUT:=5} |
410 | 415 |
: ${HELPER_USER:="nobody"} |
411 |
: ${HELPER_CACHE_FILE:="@HELPER_DIR@/cache.tar"} |
|
412 |
: ${HELPER_CACHE_PKGS:="@HELPER_DIR@/packages"} |
|
413 | 416 |
: ${HELPER_EXTRA_PKGS:="linux-image-amd64,e2fsprogs,ntfs-3g,ntfsprogs,xmlstarlet,python,parted,reglookup,chntpw,util-linux"} |
414 | 417 |
: ${HELPER_MIRROR:=""} |
415 | 418 |
: ${PITHOS_DB:="sqlite:////@localstatedir@/lib/pithos/backend.db"} |
b/snf-image-host/configure.ac | ||
---|---|---|
65 | 65 |
[helper_dir="$localstatedir/lib/snf-image/helper"]) |
66 | 66 |
AC_SUBST(HELPER_DIR, $helper_dir) |
67 | 67 |
|
68 |
# --with-helper-cache-dir |
|
69 |
AC_ARG_WITH([helper-cache-dir], |
|
70 |
[AS_HELP_STRING([--with-helper-cache-dir=DIR], |
|
71 |
[top-level directory to host the helper VM cache files |
|
72 |
[LOCALSTATEDIR/cache/snf-image/helper]] |
|
73 |
)], |
|
74 |
[helper_cache_dir="$withval"], |
|
75 |
[helper_cache_dir="$localstatedir/cache/snf-image/helper"]) |
|
76 |
AC_SUBST(HELPER_CACHE_DIR, $helper_cache_dir) |
|
77 |
|
|
68 | 78 |
# --with-helper-img |
69 | 79 |
AC_ARG_WITH([helper-img], |
70 | 80 |
[AS_HELP_STRING([--with-helper-img=IMG_PATH], |
b/snf-image-host/defaults | ||
---|---|---|
15 | 15 |
# HELPER_DIR: Directory hosting the helper files |
16 | 16 |
# HELPER_DIR="/var/lib/snf-image/helper/" |
17 | 17 |
|
18 |
# HELPER_CACHE_DIR: Directory hosting the helper cache files |
|
19 |
# HELPER_CACHE_DIR="/var/cache/snf-image/helper/" |
|
20 |
|
|
18 | 21 |
# HELPER_IMG: Path to the helper VM image |
19 | 22 |
# HELPER_IMG="${HELPER_DIR}/image" |
20 | 23 |
|
... | ... | |
43 | 46 |
# HELPER_USER imeddiately before starting execution of the helper VM. |
44 | 47 |
# HELPER_USER="nobody" |
45 | 48 |
|
46 |
# HELPER_CACHE_FILE: Cache file update-helper script uses to avoid running |
|
47 |
# `debootstrap' all the time. |
|
48 |
# HELPER_CACHE_FILE="${HELPER_DIR}/cache.tar" |
|
49 |
|
|
50 |
# HELPER_CACHE_PKGS: Debian Packages the cache file contains. |
|
51 |
# HELPER_CACHE_PKGS="${HELPER_DIR}/packages" |
|
52 |
|
|
53 | 49 |
# MULTISTRAP_CONFIG: Configuration file to be used with multistrap to create |
54 | 50 |
# the rootfs of the helper image. |
55 | 51 |
# MULTISTRAP_CONFIG="/etc/snf-image/multistrap.conf" |
b/snf-image-host/snf-image-update-helper.in | ||
---|---|---|
35 | 35 |
ganeti's \`snf-image' guest OS type. |
36 | 36 |
|
37 | 37 |
OPTIONS: |
38 |
-c CACHE_FILE |
|
39 |
Use this cache file, instead of the default |
|
40 |
[default: $HELPER_CACHE_FILE] |
|
41 |
|
|
42 | 38 |
-d DIRECTORY |
43 | 39 |
Use this directory to host the created files, instead of the default |
44 | 40 |
[default: $HELPER_DIR] |
... | ... | |
49 | 45 |
Install this deb package in the helper image, instead of the default |
50 | 46 |
[default: $HELPER_PKG] |
51 | 47 |
|
48 |
-r Don't use any existing cache |
|
49 |
|
|
52 | 50 |
-y Assume Yes to all queries and do not prompt |
53 | 51 |
|
54 | 52 |
EOF |
... | ... | |
56 | 54 |
exit "$rc" |
57 | 55 |
} |
58 | 56 |
|
59 |
while getopts "c:d:hp:y" opt; do
|
|
57 |
while getopts "d:hp:ry" opt; do
|
|
60 | 58 |
case $opt in |
61 |
c) CACHE_FILE="$OPTARG" |
|
62 |
OVERWRITTEN_CACHE_FILE="yes" |
|
63 |
;; |
|
64 | 59 |
d) HELPER_DIR="$OPTARG" |
65 | 60 |
;; |
66 | 61 |
h) usage 0 |
67 | 62 |
;; |
68 | 63 |
p) HELPER_PKG="$OPTARG" |
69 | 64 |
;; |
65 |
r) NO_CACHE="yes" |
|
66 |
;; |
|
70 | 67 |
y) NO_PROMPT="yes" |
71 | 68 |
;; |
72 | 69 |
?) log_error "Use \`-h' for help"; exit 1 |
... | ... | |
74 | 71 |
esac |
75 | 72 |
done |
76 | 73 |
|
77 |
if [ x"$OVERWRITTEN_CACHE_FILE" != "xyes" ] ; then |
|
78 |
CACHE_FILE="$HELPER_CACHE_FILE" |
|
79 |
fi |
|
80 |
|
|
81 | 74 |
echo |
82 | 75 |
echo "This is the update helper image script for snf-image." |
83 | 76 |
echo "If you don't know what to do, use \`-h'." |
... | ... | |
157 | 150 |
mount "$root_dev" "$target" |
158 | 151 |
add_cleanup umount "$root_dev" |
159 | 152 |
|
160 |
echo -n "Checking for cached root filesystem file \`$CACHE_FILE'..." |
|
161 |
if [ -f "$CACHE_FILE" ]; then |
|
153 |
echo -n "Checking for cached root filesystem in \`$HELPER_CACHE_DIR'..." |
|
154 |
if [ "$NO_CACHE" == "yes" ]; then |
|
155 |
echo "don't use cache (option -r applied)" |
|
156 |
do_multistrap "$target" "$HELPER_CACHE_DIR/root.tar" "$HELPER_CACHE_DIR/packages" |
|
157 |
elif [ -f "$HELPER_CACHE_DIR/root.tar" ]; then |
|
162 | 158 |
echo "found" |
163 | 159 |
|
164 |
|
|
165 | 160 |
missing_pkgs="no" |
166 |
if [ "$CACHE_FILE" == "$HELPER_CACHE_FILE" ]; then |
|
167 |
echo -n "Checking if needed packages are present..." |
|
168 |
if [ ! -f "$HELPER_CACHE_PKGS" ]; then |
|
169 |
missing_pkgs="yes" |
|
170 |
echo "packages file: \`$HELPER_CACHE_PKGS' does not exist" |
|
171 |
else |
|
172 |
extra_pkgs=$(grep ^packages= "$MULTISTRAP_CONFIG" | cut -d= -f2 | tr '\n' ' ') |
|
173 |
for pkg in $extra_pkgs; do |
|
174 |
if ! grep "^$pkg\$" "$HELPER_CACHE_PKGS" > /dev/null; then |
|
175 |
missing_pkgs="yes" |
|
176 |
echo "$pkg is missing." |
|
177 |
break |
|
178 |
fi |
|
179 |
done |
|
180 |
if [ "$missing_pkgs" == "no" ]; then |
|
181 |
echo "done" |
|
161 |
echo -n "Checking if needed packages are present..." |
|
162 |
if [ ! -f "$HELPER_CACHE_DIR/packages" ]; then |
|
163 |
missing_pkgs="yes" |
|
164 |
echo "packages file: \`$HELPER_CACHE_DIR/packages' does not exist" |
|
165 |
else |
|
166 |
extra_pkgs=$(grep ^packages= "$MULTISTRAP_CONFIG" | cut -d= -f2 | tr '\n' ' ') |
|
167 |
for pkg in $extra_pkgs; do |
|
168 |
if ! grep "^$pkg\$" "$HELPER_CACHE_DIR/packages" > /dev/null; then |
|
169 |
missing_pkgs="yes" |
|
170 |
echo "$pkg is missing." |
|
171 |
break |
|
182 | 172 |
fi |
183 |
fi
|
|
184 |
if [ "$missing_pkgs" == "yes" ]; then
|
|
185 |
do_multistrap "$target"
|
|
173 |
done
|
|
174 |
if [ "$missing_pkgs" == "no" ]; then
|
|
175 |
echo "done"
|
|
186 | 176 |
fi |
187 | 177 |
fi |
188 |
|
|
178 |
if [ "$missing_pkgs" == "yes" ]; then |
|
179 |
do_multistrap "$target" "$HELPER_CACHE_DIR/root.tar" "$HELPER_CACHE_DIR/packages" |
|
180 |
fi |
|
189 | 181 |
|
190 | 182 |
test "$missing_pkgs" == "no" && while [[ 1 ]]; do |
191 | 183 |
echo -n "Use the cached file [Y/n]? " |
... | ... | |
199 | 191 |
if [ -z "$answer" -o "$(tr [A-Z] [a-z] <<< "$answer")" = "y" ]; then |
200 | 192 |
break; |
201 | 193 |
elif [ "$(tr [A-Z] [a-z] <<< "$answer" )" = "n" ]; then |
202 |
do_multistrap "$target" |
|
194 |
do_multistrap "$target" "$HELPER_CACHE_DIR/root.tar" "$HELPER_CACHE_DIR/packages"
|
|
203 | 195 |
break; |
204 | 196 |
fi |
205 | 197 |
done |
206 | 198 |
|
207 | 199 |
else |
208 | 200 |
echo "not found" |
209 |
do_multistrap "$target" |
|
201 |
do_multistrap "$target" "$HELPER_CACHE_DIR/root.tar" "$HELPER_CACHE_DIR/packages"
|
|
210 | 202 |
fi |
211 | 203 |
|
212 |
tar xf "$HELPER_CACHE_FILE" -C "$target"
|
|
204 |
tar xf "$HELPER_CACHE_DIR/root.tar" -C "$target"
|
|
213 | 205 |
|
214 | 206 |
echo -n "Configuring the helper image..." |
215 | 207 |
echo snf-image-helper > "$target/etc/hostname" |
Also available in: Unified diff