aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/create_container
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/create_container')
-rwxr-xr-xcontrib/create_container55
1 files changed, 43 insertions, 12 deletions
diff --git a/contrib/create_container b/contrib/create_container
index ca22f32..64fd28c 100755
--- a/contrib/create_container
+++ b/contrib/create_container
@@ -20,23 +20,45 @@ CURDIR=$(cd $(dirname $0) && pwd -P)
PREFIX=agl-worker
DEFIMAGE=$(make -s -C $CURDIR/.. show-image)
OCCUPIED_ID=$(docker ps -a -f name=${PREFIX} --format "{{.Names}}" | grep -oE "[0-9]" | sort -n | sed ':a;N;$!ba;s/\n/ /g')
+BOOTSRV=""
+ID=""
+IMAGE=""
function usage() {
- echo "Usage: $(basename $0) <instance ID> [image name]" >&2
+ echo "Usage: $(basename $0) <instance ID> [image name] [--enable-boot-srv]" >&2
echo "Instance ID must be 0 or a positive integer (1,2,...)" >&2
echo "Image name is optional: 'make show-image' is used by default to get image" >&2
+ echo "--enable-boot-srv: Enable binding tftp/nbd port." >&2
echo "Default image: $DEFIMAGE" >&2
exit 1
}
-case $1 in
- -h|--help|"")
- usage
- ;;
-esac
+while [ $# -ne 0 ]; do
+ case $1 in
+ -h|--help|"")
+ usage
+ ;;
+ --enable-boot-srv)
+ BOOTSRV="TRUE";
+ shift
+ ;;
+ *)
+ if [ -z "${ID}" ] ; then
+ ID=$1
+ shift
+ elif [ -z "${IMAGE}" ] ; then
+ IMAGE=$1
+ shift
+ else
+ usage
+ fi
+ ;;
+ esac
+done
-ID=$1
-IMAGE=${2:-$DEFIMAGE}
+if [ -z "${IMAGE}" ] ; then
+ IMAGE=${DEFIMAGE}
+fi
USER=$(id -un)
echo "Using instance ID #$ID (user $(id -un))"
@@ -60,15 +82,19 @@ SHAREDDIR=$HOME/ssd/share
SSH_PORT=$((2222 + ID))
WWW_PORT=$((8000 + ID))
-BOOT_PORT=$((69 + ID))
-NBD_PORT=$((10809 + ID))
+BOOT_PORT=69
+NBD_PORT=10809
mkdir -p $MIRRORDIR $XDTDIR $SHAREDDIR
+
+if [ -n "${BOOTSRV}" ] ; then
+ BOOTSRV_CONFIG="--publish=${BOOT_PORT}:69/udp --publish=${NBD_PORT}:10809";
+fi
+
docker run \
--publish=${SSH_PORT}:22 \
--publish=${WWW_PORT}:8000 \
- --publish=${BOOT_PORT}:69/udp \
- --publish=${NBD_PORT}:10809 \
+ ${BOOTSRV_CONFIG} \
--detach=true \
--hostname=$NAME --name=$NAME \
--privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro \
@@ -77,6 +103,11 @@ docker run \
-v $XDTDIR:/xdt \
-it $IMAGE
+if [ $? -ne 0 ]; then
+ echo "Failed to run docker"
+ exit 1
+fi
+
echo "Copying your identity to container $NAME"
#wait ssh service
echo -n wait ssh service .