-#!/bin/bash
+#!/usr/bin/env bash
usage () {
echo "Usage: launcher COMMAND CONFIG [--skip-prereqs] [--docker-args STRING]"
echo " run: Run the given command with the config in the context of the last bootstrapped image"
echo " rebuild: Rebuild a container (destroy old, bootstrap, start new)"
echo " cleanup: Remove all containers that have stopped for > 24 hours"
+ echo " start-cmd: Generate docker command used to start container"
echo
echo "Options:"
echo " --skip-prereqs Don't check launcher prerequisites"
command=$1
config=$2
+
+# user_args_argv is assigned once when the argument vector is parsed.
+user_args_argv=""
+# user_args is mutable: its value may change when templates are parsed.
+# Superset of user_args_argv.
user_args=""
+
user_run_image=""
if [[ $command == "run" ]]; then
SKIP_MAC_ADDRESS="1"
;;
--docker-args)
- user_args="$2"
+ user_args_argv="$2"
+ user_args="$user_args_argv"
shift
;;
--run-image)
config_file=containers/"$config".yml
cidbootstrap=cids/"$config"_bootstrap.cid
local_discourse=local_discourse
-image=discourse/base:2.0.20181031
-docker_path=`which docker.io || which docker`
+image="discourse/base:2.0.20190901-2315"
+docker_path=`which docker.io 2> /dev/null || which docker`
git_path=`which git`
if [ "${SUPERVISED}" = "true" ]; then
fi
# 2. running an approved storage driver?
- if ! $docker_path info 2> /dev/null | egrep -q '^Storage Driver: (aufs|btrfs|zfs|overlay|overlay2)$'; then
+ if ! $docker_path info 2> /dev/null | egrep -q 'Storage Driver: (aufs|zfs|overlay2)$'; then
echo "Your Docker installation is not using a supported storage driver. If we were to proceed you may have a broken install."
- echo "aufs is the recommended storage driver, although zfs/btrfs/overlay and overlay2 may work as well."
+ echo "aufs is the recommended storage driver, although zfs and overlay2 may work as well."
echo "Other storage drivers are known to be problematic."
echo "You can tell what filesystem you are using by running \"docker info\" and looking at the 'Storage Driver' line."
echo
echo "You have less than 5GB of free space on the disk where $safe_folder is located. You will need more space to continue"
df -h $safe_folder
echo
- read -p "Would you like to attempt to recover space by cleaning docker images and containers in the system?(y/N)" -n 1 -r
- echo
- if [[ $REPLY =~ ^[Yy]$ ]]
- then
- $docker_path system prune -af
- echo "If the cleanup was successful, you may try again now"
+ if tty >/dev/null; then
+ read -p "Would you like to attempt to recover space by cleaning docker images and containers in the system?(y/N)" -n 1 -r
+ echo
+ if [[ $REPLY =~ ^[Yy]$ ]]
+ then
+ $docker_path system prune -af
+ echo "If the cleanup was successful, you may try again now"
+ fi
fi
exit 1
fi
p e
end
end
- puts ports.map {|p| "-p\n#{p}"}.join("\n")
+ puts ports.map { |p| p.to_s.include?(':') ? "-p\n#{p}" : "--expose\n#{p}" }.join("\n")
RUBY
tmp_input_file=$(mktemp)
)
else
echo "$config was not started !"
+ echo "./discourse-doctor may help diagnose the problem."
exit 1
fi
}
"require 'yaml'; puts YAML.load(STDIN.readlines.join)['docker_args']"`
if [[ -n "$docker_args" ]]; then
- user_args="$user_args $docker_args"
+ user_args="$user_args_argv $docker_args"
fi
}
run_start() {
- existing=`$docker_path ps | awk '{ print $1, $(NF) }' | grep " $config$" | awk '{ print $1 }'`
- echo $existing
- if [ ! -z $existing ]
+ if [ -z "$START_CMD_ONLY" ]
then
- echo "Nothing to do, your container has already started!"
- exit 0
- fi
+ existing=`$docker_path ps | awk '{ print $1, $(NF) }' | grep " $config$" | awk '{ print $1 }'`
+ echo $existing
+ if [ ! -z $existing ]
+ then
+ echo "Nothing to do, your container has already started!"
+ exit 0
+ fi
- existing=`$docker_path ps -a | awk '{ print $1, $(NF) }' | grep " $config$" | awk '{ print $1 }'`
- if [ ! -z $existing ]
- then
- echo "starting up existing container"
- (
- set -x
- $docker_path start $config
- )
- exit 0
+ existing=`$docker_path ps -a | awk '{ print $1, $(NF) }' | grep " $config$" | awk '{ print $1 }'`
+ if [ ! -z $existing ]
+ then
+ echo "starting up existing container"
+ (
+ set -x
+ $docker_path start $config
+ )
+ exit 0
+ fi
fi
host_run
mac_address="--mac-address $($docker_path run $user_args -i --rm -a stdout -a stderr $image /bin/sh -c "echo $hostname | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/'")"
fi
+ if [ ! -z "$START_CMD_ONLY" ] ; then
+ docker_path="true"
+ fi
+
set -x
+
$docker_path run --shm-size=512m $links $attach_on_run $restart_policy "${env[@]}" "${labels[@]}" -h "$hostname" \
-e DOCKER_HOST_IP="$docker_ip" --name $config -t "${ports[@]}" $volumes $mac_address $user_args \
$run_image $boot_command
$docker_path rm `cat $cidbootstrap`
rm $cidbootstrap
- echo "** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one"
+ echo "** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one."
+ echo "./discourse-doctor may help diagnose the problem."
exit 1
fi
exit 0
;;
+ start-cmd)
+ START_CMD_ONLY="1"
+ run_start
+ exit 0;
+ ;;
+
start)
run_start
exit 0
git remote update
- LOCAL=$(git rev-parse @)
+ LOCAL=$(git rev-parse HEAD)
REMOTE=$(git rev-parse @{u})
- BASE=$(git merge-base @ @{u})
+ BASE=$(git merge-base HEAD @{u})
if [ $LOCAL = $REMOTE ]; then
echo "Launcher is up-to-date"