Restructure container manager startup script

Mount /cache and /data properly and stop bridge correctly.
This commit is contained in:
Simon Fels 2016-12-08 17:08:18 +01:00
commit cbb4beaac2
2 changed files with 50 additions and 31 deletions

View file

@ -21,41 +21,59 @@ if [ ! -e $SYSTEM_IMG ]; then
exit 1
fi
# Extract ramdisk content instead of trying to bind mount the
# cpio image file to allow modifications.
rm -Rf $RAMDISK_PATH
mkdir -p $RAMDISK_PATH
cd $RAMDISK_PATH
cat $INITRD | gzip -d | cpio -i
start() {
# Extract ramdisk content instead of trying to bind mount the
# cpio image file to allow modifications.
rm -Rf $RAMDISK_PATH
mkdir -p $RAMDISK_PATH
cd $RAMDISK_PATH
cat $INITRD | gzip -d | cpio -i
# FIXME those things should be fixed in the build process
chmod +x $RAMDISK_PATH/anbox-init.sh
# FIXME those things should be fixed in the build process
chmod +x $RAMDISK_PATH/anbox-init.sh
# Setup the read-only rootfs
mkdir -p $ROOTFS_PATH
mount -o bind,ro $RAMDISK_PATH $ROOTFS_PATH
mount -o loop,ro $SYSTEM_IMG $ROOTFS_PATH/system
# Setup the read-only rootfs
mkdir -p $ROOTFS_PATH
mount -o bind,ro $RAMDISK_PATH $ROOTFS_PATH
mount -o loop,ro $SYSTEM_IMG $ROOTFS_PATH/system
# but certain top-level directories need to be in a writable space
for dir in cache data; do
mkdir -p $DATA_PATH/android-$dir
mount -o bind $DATA_PATH/android-$dir $ROOTFS_PATH/$dir
done
# but certain top-level directories need to be in a writable space
for dir in cache data; do
mkdir -p $DATA_PATH/android-$dir
mount -o bind $DATA_PATH/android-$dir $ROOTFS_PATH/$dir
done
# Make sure our setup path for the container rootfs
# is present as lxc is statically configured for
# this path.
mkdir -p $SNAP_COMMON/lxc
# Make sure our setup path for the container rootfs
# is present as lxc is statically configured for
# this path.
mkdir -p $SNAP_COMMON/lxc
# We start the bridge here as long as a oneshot service unit is not
# possible. See snapcraft.yaml for further details.
$SNAP/bin/anbox-bridge.sh start
# We start the bridge here as long as a oneshot service unit is not
# possible. See snapcraft.yaml for further details.
$SNAP/bin/anbox-bridge.sh start
$SNAP/usr/sbin/aa-exec -p unconfined -- $SNAP/bin/anbox-wrapper.sh container-manager
pid=$!
waitpid $pid
exec $SNAP/usr/sbin/aa-exec -p unconfined -- $SNAP/bin/anbox-wrapper.sh container-manager
}
$SNAP/bin/anbox-bridge.sh stop
stop() {
for dir in cache data; do
umount $ROOTFS_PATH/$dir
done
umount $ROOTFS_PATH/system
umount $ROOTFS_PATH
umount $ROOTFS_PATH/system
umount $ROOTFS_PATH/data
$SNAP/bin/anbox-bridge.sh stop
}
case "$1" in
start)
start
;;
stop)
stop
;;
*)
echo "ERROR: Unknown command '$1'"
exit 1
;;
esac

View file

@ -12,7 +12,8 @@ apps:
anbox:
command: bin/anbox-wrapper.sh
container-manager:
command: bin/container-manager.sh
command: bin/container-manager.sh start
stop-command: bin/container-manager.sh stop
daemon: simple
# FIXME: a oneshot unit with start/stop commands needs also RemainAfterExit=yes
# but this isn't supported by snapd yet. See LP #1647169 for details.