+function start_container {
+ local args="-d -i -t"
+ if [[ "$1" != '' ]]; then
+ local port="$1"
+ args="$args -p $port"
+ fi
+ if [[ "$2" != '' ]]; then
+ local name="$2"
+ args="$args -name $name"
+ fi
+ if [[ "$3" != '' ]]; then
+ local volume="$3"
+ args="$args -v $volume"
+ fi
+ if [[ "$4" != '' ]]; then
+ local link="$4"
+ args="$args -link $link"
+ fi
+ local image=$5
+
+ if $ENABLE_SSH
+ then
+ args="$args -e ENABLE_SSH=$ENABLE_SSH"
+ fi
+
+ `docker ps |grep -P "$name[^/]" -q`
+ if [[ "$?" == "0" ]]; then
+ echo "You have a running container with name $name -- skipping."
+ return
+ fi
+
+ # Remove any existing container by this name.
+ docker rm "$name" 2>/dev/null
+
+ echo "Starting container:"
+ echo " docker run $args $image"
+ container=`docker run $args $image`
+ if [[ "$?" != "0" ]]; then
+ echo "Unable to start container"
+ exit 1
+ fi
+ if $ENABLE_SSH
+ then
+ ip=$(ip_address $container )
+ echo
+ echo "You can ssh into the container with:"
+ echo
+ echo " ssh root@$ip"
+ echo
+ fi
+}
+
+declare -a keep_volumes
+
+# Initialize the global `keep_volumes' array. If any keep volumes
+# already appear to exist (mounted volumes with a top-level "keep"
+# directory), use them; create temporary volumes if necessary.
+#
+function make_keep_volumes () {
+ # Mount a keep volume if we don't already have one
+ for mountpoint in $(cut -d ' ' -f 2 /proc/mounts); do
+ if [[ -d "$mountpoint/keep" && "$mountpoint" != "/" ]]; then
+ keep_volumes+=($mountpoint)
+ fi
+ done
+
+ # Create any keep volumes that do not yet exist.
+ while [ ${#keep_volumes[*]} -lt 2 ]
+ do
+ new_keep=$(mktemp -d)
+ echo >&2 "mounting 512M tmpfs keep volume in $new_keep"
+ sudo mount -t tmpfs -o size=512M tmpfs $new_keep
+ mkdir $new_keep/keep
+ keep_volumes+=($new_keep)
+ done
+}
+
+function do_start {
+ local start_doc=false
+ local start_sso=false
+ local start_api=false
+ local start_workbench=false
+ local start_keep=false
+
+ # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
+ local TEMP=`getopt -o d::s::a::w::kh \
+ --long doc::,sso::,api::,workbench::,keep,help,ssh \
+ -n "$0" -- "$@"`
+
+ if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
+
+ # Note the quotes around `$TEMP': they are essential!
+ eval set -- "$TEMP"