libreoffice-online/loolwsd-systemplate-setup
Ashod Nakashian 5c9988f2e3 wsd: faster jail setup via bind-mount
loolmount now works and supports mounting and
unmounting, plus numerous improvements,
refactoring, logging, etc..  When enabled,
binding improves the jail setup time by anywhere
from 2x to orders of magnitude (in docker, f.e.).

A new config entry mount_jail_tree controls
whether mounting is used or the old method of
linking/copying of jail contents. It is set to
true by default and falls back to linking/copying.
A test mount is done when the setting is enabled,
and if mounting fails, it's disabled to avoid noise.

Temporarily disabled for unit-tests until we can
cleanup lingering mounts after Jenkins aborts our
build job. In a future patch we will have mount/jail
cleanup as part of make.

The network/system files in /etc that need frequent
refreshing are now updated in systemplate to make
their most recent version available in the jails.
These files can change during the course of loolwsd
lifetime, and are unlikely to be updated in
systemplate after installation at all. We link to
them in the systemplate/etc directory, and if that
fails, we copy them before forking each kit
instance to have the latest.

This reworks the approach used to bind-mount the
jails and the templates such that the total is
now down to only three mounts: systemplate, lo, tmp.

As now systemplate and lotemplate are shared, they
must be mounted as readonly, this means that user/
must now be moved into tmp/user/ which is writable.

The mount-points must be recursive, because we mount
lo/ within the mount-point of systemplate (which is
the root of the jail). But because we (re)bind
recursively, and because both systemplate and
lotemplate are mounted for each jails, we need to
make them unbindable, so they wouldn't multiply the
mount-points for each jails (an explosive growth!)
Contrarywise, we don't want the mount-points to
be shared, because we don't expect to add/remove
mounts after a jail is created.

The random temp directory is now created and set
correctly, plus many logging and other improvements.

Change-Id: Iae3fda5e876cf47d2cae6669a87b5b826a8748df
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92829
Tested-by: Jenkins
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
2020-07-01 05:42:43 +02:00

97 lines
2.7 KiB
Bash
Executable file

#!/bin/bash
test $# -eq 2 || { echo "Usage: $0 <chroot template directory for system libs to create> <LO installation directory>"; exit 1; }
# No provision for spaces or other weird characters in pathnames. So sue me.
CHROOT=$1
INSTDIR=$2
test -d "$INSTDIR" || { echo "No such directory: $INSTDIR"; exit 1; }
mkdir -p $CHROOT || exit 1
CHROOT=`cd $CHROOT && /bin/pwd`
INSTDIR=`cd $INSTDIR && /bin/pwd`
cd / || exit 1
(
# Produce a list of file names, one per line, that will be copied
# into the template tree of system files for the chroot jails.
# First essential files and shared objects
find etc/hosts etc/nsswitch.conf etc/resolv.conf \
etc/passwd etc/group etc/host.conf \
etc/ld.so.* \
lib/ld-* lib64/ld-* \
lib/libnss_* lib64/libnss_* lib/*/libnss_* \
lib/libresolv* lib64/libresolv* lib/*/libresolv* \
var/cache/fontconfig \
etc/fonts \
etc/timezone \
etc/localtime \
usr/lib/locale/en_US.utf8 \
usr/lib/locale/C.UTF-8 \
usr/lib/locale/locale_archive \
usr/lib/*/nss/*.so \
usr/lib/*/libsqlite* \
usr/share/zoneinfo/* \
usr/share/liblangtag \
usr/share/hyphen \
-type f 2>/dev/null
find etc/fonts \
etc/timezone \
etc/localtime \
etc/resolv.conf \
lib/ld-* lib64/ld-* \
lib/libnss_* lib64/libnss_* lib/*/libnss_* \
lib/libresolv* lib64/libresolv* lib/*/libresolv* \
usr/lib/*/libsqlite* \
-type l 2>/dev/null
# Go through the LO shared objects and check what system libraries
# they link to.
find $INSTDIR -name 'xpdfimport' |
while read file; do
ldd $file 2>/dev/null
done |
grep -v dynamic | cut -d " " -f 3 | grep -E '^(/lib|/usr)' | sort -u | sed -e 's,^/,,'
) |
# Can't use -l because then symlinks won't be handled well enough.
# This will now copy the file a symlink points to, but whatever.
cpio -p -d -L $CHROOT
mkdir -p $CHROOT/lo
mkdir -p $CHROOT/dev
mkdir -p $CHROOT/tmp/dev
# /usr/share/fonts needs to be taken care of separately because the
# directory time stamps must be preserved for fontconfig to trust
# its cache.
cd $CHROOT || exit 1
mkdir -p usr/share || exit 1
cp -r -p -L /usr/share/fonts usr/share
if [ -h usr/share/fonts/ghostscript ]; then
mkdir usr/share/ghostscript || exit 1
cp -r -p -L /usr/share/ghostscript/fonts usr/share/ghostscript
fi
# Remove obsolete & unused bitmap fonts
find usr/share -name '*.pcf' | xargs rm -f
find usr/share -name '*.pcf.gz' | xargs rm -f
# Debugging only hackery to avoid confusion.
if test "z$ENABLE_DEBUG" != "z" -a "z$HOME" != "z"; then
echo "Copying development users's fonts into systemplate"
mkdir -p $CHROOT/$HOME
test -d $HOME/.fonts && cp -r -p -L $HOME/.fonts $CHROOT/$HOME
fi
exit 0