Files
linuxkit/alpine/packages/mobyconfig/mobyconfig
David Scott 129f7836fd mobyconfig: on Hyper-V connect to the db over AF_HYPERV
We detect Hyper-V by the presence of /sys/bus/vmbus and then run the
/sbin/9pmount-vsock command to establish a socket connection and then
pass the fd to /bin/mount

This patch also hard-codes the database directory

  com.docker.driver.amd64-linux

since we can't use the kernel commandline on Hyper-V hosts. It would
probably be better to expose a generic directory name ( / ?) on all
platforms and configure the datbase to store each VM's configuration
in a different directory.

Signed-off-by: David Scott <dave.scott@docker.com>
2016-05-21 21:51:11 +01:00

105 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
if [ $# -ne 2 ]
then
printf "usage: $0 [get|exists|watch|path|dir|find] key\n"
exit 0
fi
if [ $1 == "set" ]
then
printf "Configuration is immutable\n" 1>&2
exit 1
fi
if [ ! -d /Database ]
then
mkdir -p /Database
if [ -d /sys/bus/vmbus ]; then
# Running on a Hyper-V hypervisor
/sbin/9pmount-vsock listen db /Database
else
mount -t 9p -o trans=virtio,dfltuid=1001,dfltgid=50,version=9p2000 db /Database
fi
if [ $? -ne 0 ]
then
rm -rf /Database
printf "Could not mount configuration database\n" 1>&2
exit 1
fi
fi
DATABASE="com.docker.driver.amd64-linux"
BASE="/Database/branch/master/ro/${DATABASE}"
KEY=$(echo $2 | sed 's@^/@@')
if [ $1 == "exists" ]
then
[ -d ${BASE}/${KEY} ] && exit 0
[ -f ${BASE}/${KEY} ] || exit 1
VALUE="$(cat ${BASE}/${KEY} | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
[ -z "${VALUE}" ] && exit 1
exit 0
fi
if [ $1 == "dir" ]
then
[ -d ${BASE}/${KEY} ] && exit 0 || exit 1
fi
if [ $1 == "get" ]
then
if [ -f ${BASE}/${KEY} ]
then
cat ${BASE}/${KEY}
exit 0
else
printf "No such key: ${KEY}\n" 1>&2
exit 1
fi
fi
if [ $1 == "path" ]
then
if [ -e ${BASE}/${KEY} ]
then
printf ${BASE}/${KEY}
exit 0
else
printf "No such key: ${KEY}\n" 1>&2
exit 1
fi
fi
if [ $1 == "find" ]
then
if [ -e ${BASE}/${KEY} ]
then
find ${BASE}/${KEY} -type f | sed "s@^${BASE}@@g"
exit 0
else
printf "No such key: ${KEY}\n" 1>&2
exit 1
fi
fi
# might be nicer if watch returned a file descriptor not a path
# /Database/branch/master/watch/com.docker.driver.amd64-linux.node/etc.node/docker.node/daemon.json.node/tree.live
if [ $1 == "watch" ]
then
WATCHBASE="/Database/branch/master/watch/${DATABASE}.node"
WATCH="${WATCHBASE}/$(echo ${KEY} | sed 's@/@.node/@g').node/tree.live"
if [ -f ${WATCH} ]
then
printf ${WATCH}
exit 0
else
printf "No such watch: ${WATCH}\n" 2>&1
exit 1
fi
fi
printf "usage: $0 [get|exists|watch|path|dir|find] key\n"
exit 1